From a56cb18a8943be357b0ccb15f515f2315866f408 Mon Sep 17 00:00:00 2001 From: achmizs <1874748+achmizs@users.noreply.github.com> Date: Mon, 16 Dec 2019 04:21:50 -0500 Subject: [PATCH] Fixed bug with observed changes to specified element; version to 1.2.8 --- src/contentScript.js | 47 ++++++++++++++++++------------ src/platform/chrome/manifest.json | 2 +- src/platform/firefox/manifest.json | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/contentScript.js b/src/contentScript.js index 604386c..dd887fa 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -54,32 +54,41 @@ function checkForShouldKillSticky(result) { /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* This is the code that actually does the sticky killing! It simply selects - all elements whose 'position' CSS property has a computed value of either - 'sticky' or 'fixed', and removes those elements. + all elements whose ‘position’ CSS property has a computed value of either + ‘sticky’ or ‘fixed’, and removes those elements. */ function killSticky(root) { root = root || document.querySelector("body"); - root.querySelectorAll('*').forEach(element => { - let position = getComputedStyle(element).position; - if (position === 'fixed' || position === 'sticky') { - // uBlock exception. - if (element.tagName == "IFRAME" && - element.parentElement.tagName == "HTML") - return; - - // Kill the sticky. - console.log("Killing sticky!"); - element.remove(); - - // Increment the stickies killed count, and update icon badge. - AKS.stickiesKilled++; - chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled }); - } - }); + if (killStickyIfNeeded(root) == false) { + root.querySelectorAll('*').forEach(element => { + killStickyIfNeeded(element) + }); + } // Compensate for full-screen paywalls. restoreScrollability(); } +function killStickyIfNeeded(element) { + let position = getComputedStyle(element).position; + if (position === 'fixed' || position === 'sticky') { + // uBlock exception. + if (element.tagName == "IFRAME" && + element.parentElement.tagName == "HTML") + return; + + // Kill the sticky. + console.log("Killing sticky!"); + element.remove(); + + // Increment the stickies killed count, and update icon badge. + AKS.stickiesKilled++; + chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled }); + + return true; + } else { + return false; + } +} /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Full-screen paywalls not only bring up sticky elements, they also make diff --git a/src/platform/chrome/manifest.json b/src/platform/chrome/manifest.json index 0e4f139..f05bc16 100644 --- a/src/platform/chrome/manifest.json +++ b/src/platform/chrome/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "AlwaysKillSticky", - "version": "1.2.7", + "version": "1.2.8", "description": "Get rid of sticky elements on websites - permanently!", "author": "Said Achmiz", "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", diff --git a/src/platform/firefox/manifest.json b/src/platform/firefox/manifest.json index 19c2ec9..2cc800f 100644 --- a/src/platform/firefox/manifest.json +++ b/src/platform/firefox/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "AlwaysKillSticky", - "version": "1.2.7", + "version": "1.2.8", "description": "Get rid of sticky elements on websites - permanently!", "author": "Said Achmiz", "browser_specific_settings": {