From 698461c04d7d2f1e67f1edf97c1dc1248a39f053 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 23 Jun 2017 01:51:14 +0530 Subject: Initial commit. --- youtube-noscript-shim.user.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 youtube-noscript-shim.user.js 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"]); +}); -- cgit v1.2.3