diff options
Diffstat (limited to 'youtube-noscript-shim.user.js')
-rw-r--r-- | youtube-noscript-shim.user.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/youtube-noscript-shim.user.js b/youtube-noscript-shim.user.js index 6468e78..74fac73 100644 --- a/youtube-noscript-shim.user.js +++ b/youtube-noscript-shim.user.js @@ -47,6 +47,16 @@ function toggleBooleanAttributes (selector, ...attributes) { }); }); } + +/** + * Attach event listener to one or more elements + * @param {string} selector - CSS selector for the elements + * @param {string} eventType - Event type to listen for + * @param {function} listener - Event listener callback function + */ +function attachEventListener (selector, eventType, listener) { + document.querySelectorAll(selector).forEach(function (element) { + element.addEventListener(eventType, listener) }); } @@ -56,14 +66,14 @@ document.querySelectorAll("img[data-thumb]").forEach(function (img) { }); // Search filters -document.querySelector(".filter-button").addEventListener("click", function () { +attachEventListener(".filter-button", "click", function () { toggleClasses(".filter-button", "yt-uix-button-toggled"); toggleClasses(".search-header", "yt-uix-expander-collapsed"); toggleBooleanAttributes(".filter-button", "aria-pressed"); }); // Menu -document.querySelector("#appbar-guide-button").addEvenetListener("click", function () { +attachEventListener("#appbar-guide-button", "click", function () { toggleClasses("html", "show-guide"); toggleBooleanAttributes("#appbar-guide-button", "aria-expanded"); }); |