| return shouldKillSticky; | return shouldKillSticky; | ||||
| } | } | ||||
| /* Some websites add sticky elements after loading, or make existing elements | |||||
| sticky (either on a timer, or based on user actions). CONSTANT VIGILANCE | |||||
| counteracts this behavior, by watching the DOM for mutations, and, if | |||||
| necessary, killing any newly-formed stickies. | |||||
| */ | |||||
| function startConstantVigilance() { | |||||
| var observer = new MutationObserver((mutationsList, observer) => { | |||||
| for (var mutation of mutationsList) { | |||||
| killSticky(mutation.target); | |||||
| } | |||||
| }); | |||||
| console.log("Commencing vigilance for stickies!"); | |||||
| observer.observe(document.querySelector("html"), { | |||||
| attributes: true, | |||||
| childList: true, | |||||
| subtree: true | |||||
| }); | |||||
| } | |||||
| /******************/ | /******************/ | ||||
| /* INITIALIZATION */ | /* INITIALIZATION */ | ||||
| /******************/ | /******************/ | ||||
| let shouldKillSticky = checkForShouldKillSticky(result); | let shouldKillSticky = checkForShouldKillSticky(result); | ||||
| updateIcon(shouldKillSticky); | updateIcon(shouldKillSticky); | ||||
| if (shouldKillSticky) { | if (shouldKillSticky) { | ||||
| function beginKillingStickies() { | |||||
| killSticky(); | |||||
| startConstantVigilance(); | |||||
| } | |||||
| if (document.readyState == "loading") { | if (document.readyState == "loading") { | ||||
| document.addEventListener("DOMContentLoaded", beginKillingStickies); | document.addEventListener("DOMContentLoaded", beginKillingStickies); | ||||
| } else { | } else { |
| 'sticky' or 'fixed', and removes those elements. | 'sticky' or 'fixed', and removes those elements. | ||||
| */ | */ | ||||
| function killSticky(root) { | function killSticky(root) { | ||||
| var message = root ? "Killing all stickies!" : "Killing more stickies!"; | |||||
| console.log(message); | |||||
| root = root || document.querySelector("body"); | root = root || document.querySelector("body"); | ||||
| root.querySelectorAll('*').forEach(element => { | root.querySelectorAll('*').forEach(element => { | ||||
| if (getComputedStyle(element).position === 'fixed' || | if (getComputedStyle(element).position === 'fixed' || | ||||
| getComputedStyle(element).position === 'sticky') { | getComputedStyle(element).position === 'sticky') { | ||||
| console.log("Killing sticky!"); | |||||
| element.remove(); | element.remove(); | ||||
| } | } | ||||
| }); | }); | ||||
| container.style.setProperty("overflow-y", "auto", "important"); | container.style.setProperty("overflow-y", "auto", "important"); | ||||
| }); | }); | ||||
| } | } | ||||
| /* Some websites add sticky elements after loading, or make existing elements | |||||
| sticky (either on a timer, or based on user actions). CONSTANT VIGILANCE | |||||
| counteracts this behavior, by watching the DOM for mutations, and, if | |||||
| necessary, killing any newly-formed stickies. | |||||
| */ | |||||
| function startConstantVigilance() { | |||||
| var observer = new MutationObserver((mutationsList, observer) => { | |||||
| for (var mutation of mutationsList) { | |||||
| killSticky(mutation.target); | |||||
| } | |||||
| }); | |||||
| console.log("Commencing vigilance for stickies!"); | |||||
| observer.observe(document.querySelector("html"), { | |||||
| attributes: true, | |||||
| childList: true, | |||||
| subtree: true | |||||
| }); | |||||
| } | |||||
| /* Immediately kill all stickies, then commence constant vigilance. | |||||
| */ | |||||
| function beginKillingStickies() { | |||||
| killSticky(); | |||||
| startConstantVigilance(); | |||||
| } | |||||
| Otherwise, show the reload button. */ | Otherwise, show the reload button. */ | ||||
| let shouldKillSticky = AKS.pageMatched && !AKS.pageExcluded; | let shouldKillSticky = AKS.pageMatched && !AKS.pageExcluded; | ||||
| if (AKS.pageMatched && !AKS.pageExcluded) { | if (AKS.pageMatched && !AKS.pageExcluded) { | ||||
| chrome.tabs.executeScript(null, { code: 'killSticky()' }); | |||||
| chrome.tabs.executeScript(null, { code: 'beginKillingStickies()' }); | |||||
| reloadButton.classList.toggle("active", false); | reloadButton.classList.toggle("active", false); | ||||
| } else { | } else { | ||||
| reloadButton.classList.toggle("active", true); | reloadButton.classList.toggle("active", true); |