summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--youtube-noscript-shim.user.js43
1 files changed, 29 insertions, 14 deletions
diff --git a/youtube-noscript-shim.user.js b/youtube-noscript-shim.user.js
index beee814..92b189f 100644
--- a/youtube-noscript-shim.user.js
+++ b/youtube-noscript-shim.user.js
@@ -22,16 +22,31 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-function toggleClasses (selector, classes) {
- classes.forEach(function (cls) {
- document.querySelector(selector).classList.toggle(cls);
+/**
+ * Add/remove classes on one or more elements
+ * @param {string} selector - CSS selector for the elements
+ * @param {...string} classes - Classes to add/remove
+ */
+function toggleClasses (selector, ...classes) {
+ document.querySelectorAll(selector).forEach(function (element) {
+ classes.forEach(function (cls) {
+ element.classList.toggle(cls);
+ });
});
}
-function toggleBooleanAttributes (selector, attributes) {
- element = document.querySelector(selector);
- attributes.forEach(function (attribute) {
- element.setAttribute(attribute, element.getAttribute(attribute) == "true" ? "false" : "true");
+/**
+ * Toggle boolean attributes on one or more elements
+ * @param {string} selector - CSS selector for the elements
+ * @param {...string} classes - Boolean attributes to toggle
+ */
+function toggleBooleanAttributes (selector, ...attributes) {
+ document.querySelectorAll(selector).forEach(function (element) {
+ attributes.forEach(function (attribute) {
+ element.setAttribute(attribute, element.getAttribute(attribute) == "true" ? "false" : "true");
+ });
+ });
+}
});
}
@@ -42,13 +57,13 @@ Array.from(document.querySelectorAll("img[data-thumb]")).forEach(function (img)
// Search filters
document.querySelector(".filter-button").addEventListener("click", function () {
- toggleClasses(".filter-button", ["yt-uix-button-toggled"]);
- toggleClasses(".search-header", ["yt-uix-expander-collapsed"]);
- toggleBooleanAttributes(".filter-button", ["aria-pressed"]);
+ toggleClasses(".filter-button", "yt-uix-button-toggled");
+ toggleClasses(".search-header", "yt-uix-expander-collapsed");
+ toggleBooleanAttributes(".filter-button", "aria-pressed");
});
-// Guide
-document.querySelector("#appbar-guide-button").addEventListener("click", function () {
- toggleClasses("html", ["show-guide"]);
- toggleBooleanAttributes("#appbar-guide-button", ["aria-expanded"]);
+// Menu
+document.querySelector("#appbar-guide-button").addEvenetListener("click", function () {
+ toggleClasses("html", "show-guide");
+ toggleBooleanAttributes("#appbar-guide-button", "aria-expanded");
});