Last active
June 27, 2023 23:31
-
-
Save NZDev0/3c0986163492fd50603d1415ad80d367 to your computer and use it in GitHub Desktop.
Adds a clear notifcations button to the forums drop down menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GOG Menu Dot | |
// @namespace https://gist.github.com/NZDev0/ | |
// @author Dev0 NZ | |
// @description Clear Notifications button on the community drop down menu | |
// @updateURL https://gist.github.com/NZDev0/3c0986163492fd50603d1415ad80d367/raw/ | |
// @downloadURL https://gist.github.com/NZDev0/3c0986163492fd50603d1415ad80d367/raw/ | |
// @match https://www.gog.com/* | |
// @run-at document-start | |
// @version 1.2 | |
// ==/UserScript== | |
/* | |
* Thanks for the angular hook in code | |
* https://gist.github.com/adaliabooks/bf3cbdbb56db6c107dd8 | |
* | |
*/ | |
document.addEventListener ("DOMContentLoaded", DOM_ContentReady); | |
function DOM_ContentReady () { | |
contentEval(function() { | |
if(window.gog) { | |
gog.config( | |
['$compileProvider', function( $compileProvider ) { | |
$compileProvider.debugInfoEnabled(true); | |
}] | |
); | |
var clear_btn = document.createElement('a'); | |
var menu_btn = document.createElement("div"); | |
clear_btn.setAttribute("href", "#"); | |
clear_btn.setAttribute("class", "menu-submenu-link"); | |
clear_btn.onclick = () => { | |
angular.element(document.body).injector().get('menuNotificationsRepository').deleteAllNotifications(); | |
}; | |
clear_btn.innerHTML = "Clear Notifications"; | |
menu_btn.setAttribute("class", "menu-submenu-item menu-submenu-item--hover"); | |
menu_btn.appendChild(clear_btn); | |
// Add notifications button | |
document.querySelector('.js-menu-community').childNodes[2].prepend(menu_btn); | |
} | |
}); | |
} | |
function contentEval(source) { | |
// Check for function input. | |
if ('function' == typeof source) { | |
// Execute this function with no arguments, by adding parentheses. | |
// One set around the function, required for valid syntax, and a | |
// second empty set calls the surrounded function. | |
source = '(' + source + ')();' | |
} | |
// Create a script node holding this source code. | |
var script = document.createElement('script'); | |
script.setAttribute("type", "application/javascript"); | |
script.textContent = source; | |
// Insert the script node into the page, so it will run, and immediately | |
// remove it to clean up. | |
document.body.appendChild(script); | |
document.body.removeChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment