From ee2cd8a08ef8e8beb18e2325a393c28e48632b4a Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 27 Aug 2023 21:43:10 +1000 Subject: [PATCH] Add Hide sticky elements --- Hide sticky elements.user.js | 54 ++++++++++++++++++++++++++++++++++++ README.md | 5 ++++ 2 files changed, 59 insertions(+) create mode 100644 Hide sticky elements.user.js diff --git a/Hide sticky elements.user.js b/Hide sticky elements.user.js new file mode 100644 index 0000000..db48952 --- /dev/null +++ b/Hide sticky elements.user.js @@ -0,0 +1,54 @@ +// ==UserScript== +// @name Hide sticky elements +// @namespace blankie-scripts +// @match http*://*/* +// @grant GM_registerMenuCommand +// @grant GM_unregisterMenuCommand +// @version 1.0.0 +// @author blankie +// @description Adds a button to the monkey menu to hide sticky elements +// @inject-into content +// ==/UserScript== + +"use strict"; + +let stickyElements = []; +let hideStickyElements = true; +let menuId; + +function hideAllStickyElements() { + for (let element of document.body.querySelectorAll("*")) { + let style = getComputedStyle(element); + if (style.position !== "sticky" && style.position !== "fixed") { + continue; + } + + let originalDisplayValue = element.style.getPropertyValue("display"); + let originalDisplayPriority = element.style.getPropertyPriority("display"); + element.style.setProperty("display", "none", "important"); + stickyElements.push([element, originalDisplayValue, originalDisplayPriority]); + } +} + +function unhideAllStickyElements() { + for (let [element, originalDisplayValue, originalDisplayPriority] of stickyElements) { + element.style.setProperty("display", originalDisplayValue, originalDisplayPriority); + } + stickyElements = []; +} + + + +function registerMenu() { + if (menuId) { + GM_unregisterMenuCommand(menuId); + } + + let caption = hideStickyElements ? "Hide sticky elements" : "Unhide sticky elements"; + menuId = GM_registerMenuCommand(caption, function() { + (hideStickyElements ? hideAllStickyElements : unhideAllStickyElements)(); + hideStickyElements = !hideStickyElements; + registerMenu(); + }); +} +registerMenu(); \ No newline at end of file diff --git a/README.md b/README.md index e9e829c..76e86d1 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ A userscript that adds small but useful features for Compass. Features include: A userscript that adds a "Show elements popup" option to the Monkey Menu which lists all elements with an ID +## Hide sticky elements + +A userscript that adds a button to the monkey menu to hide and unhide sticky +elements + ## Image Loader Placeholder Remover Removes image loading placeholders from images loaded via Javascript, such as