From 30036443b7b993d75992d3277d50c24fed3fc815 Mon Sep 17 00:00:00 2001 From: Said Achmiz Date: Mon, 4 Feb 2019 02:03:37 -0500 Subject: [PATCH] Fixed element selection bug --- src/contentScript.js | 22 ++++++++-------------- src/functions.js | 10 +++++++--- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/contentScript.js b/src/contentScript.js index 639f4f0..d0f9ce9 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -59,14 +59,7 @@ function checkForShouldKillSticky(result) { function startConstantVigilance() { var observer = new MutationObserver((mutationsList, observer) => { for (var mutation of mutationsList) { - if (getComputedStyle(mutation.target).position == 'fixed' || - getComputedStyle(mutation.target).position == 'sticky') { - mutation.target.remove(); - console.log("Killing a sticky!"); - - // Compensate for fullscreen paywalls. - restoreScrollability(); - } + killSticky(mutation.target); } }); @@ -87,13 +80,14 @@ function initialize() { let shouldKillSticky = checkForShouldKillSticky(result); updateIcon(shouldKillSticky); if (shouldKillSticky) { - startConstantVigilance(); - if (document.readyState == "loading") { - document.addEventListener("DOMContentLoaded", () => { - killSticky(); - }); - } else { + function beginKillingStickies() { killSticky(); + startConstantVigilance(); + } + if (document.readyState == "loading") { + document.addEventListener("DOMContentLoaded", beginKillingStickies); + } else { + beginKillingStickies(); } } }); diff --git a/src/functions.js b/src/functions.js index a63a92f..4c605ce 100644 --- a/src/functions.js +++ b/src/functions.js @@ -46,14 +46,18 @@ function updateIcon(shouldKillSticky, tabID) { all elements whose 'position' CSS property has a computed value of either 'sticky' or 'fixed', and removes those elements. */ -function killSticky() { - console.log("Killing all stickies!"); - document.querySelectorAll('body *').forEach(element => { +function killSticky(root) { + var message = root ? "Killing all stickies!" : "Killing more stickies!"; + console.log(message); + + root = root || document.querySelector("body"); + root.querySelectorAll('*').forEach(element => { if (getComputedStyle(element).position === 'fixed' || getComputedStyle(element).position === 'sticky') { element.remove(); } }); + // Compensate for full-screen paywalls. restoreScrollability(); }