aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--youtube-noscript-shim.user.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/youtube-noscript-shim.user.js b/youtube-noscript-shim.user.js
new file mode 100644
index 0000000..cac6d45
--- /dev/null
+++ b/youtube-noscript-shim.user.js
@@ -0,0 +1,39 @@
+// ==UserScript==
+// @name youtube-noscript-shim
+// @namespace systemreboot.net
+// @description Use YouTube with NoScript
+// @include https://www.youtube.com/*
+// @version 0.1
+// @grant none
+// ==/UserScript==
+
+function toggleClasses (selector, classes) {
+ classes.forEach(function (cls) {
+ document.querySelector(selector).classList.toggle(cls);
+ });
+}
+
+function toggleBooleanAttributes (selector, attributes) {
+ element = document.querySelector(selector);
+ attributes.forEach(function (attribute) {
+ element.setAttribute(attribute, element.getAttribute(attribute) == "true" ? "false" : "true");
+ });
+}
+
+// Load thumbnails
+Array.from(document.querySelectorAll("img[data-thumb]")).forEach(function (img) {
+ img.setAttribute("src", img.getAttribute("data-thumb"));
+});
+
+// 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"]);
+});
+
+// Guide
+document.querySelector("#appbar-guide-button").addEventListener("click", function () {
+ toggleClasses("html", ["show-guide"]);
+ toggleBooleanAttributes("#appbar-guide-button", ["aria-expanded"]);
+});