Add Hide sticky elements

This commit is contained in:
blankie 2023-08-27 21:43:10 +10:00
parent d319934631
commit ee2cd8a08e
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 59 additions and 0 deletions

View File

@ -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();

View File

@ -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