Fixed element selection bug

This commit is contained in:
Said Achmiz 2019-02-04 02:03:37 -05:00
parent e62ec717c8
commit 30036443b7
2 changed files with 15 additions and 17 deletions

View File

@ -59,14 +59,7 @@ function checkForShouldKillSticky(result) {
function startConstantVigilance() { function startConstantVigilance() {
var observer = new MutationObserver((mutationsList, observer) => { var observer = new MutationObserver((mutationsList, observer) => {
for (var mutation of mutationsList) { for (var mutation of mutationsList) {
if (getComputedStyle(mutation.target).position == 'fixed' || killSticky(mutation.target);
getComputedStyle(mutation.target).position == 'sticky') {
mutation.target.remove();
console.log("Killing a sticky!");
// Compensate for fullscreen paywalls.
restoreScrollability();
}
} }
}); });
@ -87,13 +80,14 @@ function initialize() {
let shouldKillSticky = checkForShouldKillSticky(result); let shouldKillSticky = checkForShouldKillSticky(result);
updateIcon(shouldKillSticky); updateIcon(shouldKillSticky);
if (shouldKillSticky) { if (shouldKillSticky) {
function beginKillingStickies() {
killSticky();
startConstantVigilance(); startConstantVigilance();
}
if (document.readyState == "loading") { if (document.readyState == "loading") {
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", beginKillingStickies);
killSticky();
});
} else { } else {
killSticky(); beginKillingStickies();
} }
} }
}); });

View File

@ -46,14 +46,18 @@ function updateIcon(shouldKillSticky, tabID) {
all elements whose 'position' CSS property has a computed value of either all elements whose 'position' CSS property has a computed value of either
'sticky' or 'fixed', and removes those elements. 'sticky' or 'fixed', and removes those elements.
*/ */
function killSticky() { function killSticky(root) {
console.log("Killing all stickies!"); var message = root ? "Killing all stickies!" : "Killing more stickies!";
document.querySelectorAll('body *').forEach(element => { console.log(message);
root = root || document.querySelector("body");
root.querySelectorAll('*').forEach(element => {
if (getComputedStyle(element).position === 'fixed' || if (getComputedStyle(element).position === 'fixed' ||
getComputedStyle(element).position === 'sticky') { getComputedStyle(element).position === 'sticky') {
element.remove(); element.remove();
} }
}); });
// Compensate for full-screen paywalls. // Compensate for full-screen paywalls.
restoreScrollability(); restoreScrollability();
} }