瀏覽代碼

Fixed element selection bug

master
Said Achmiz 6 年之前
父節點
當前提交
30036443b7
共有 2 個檔案被更改,包括 14 行新增16 行删除
  1. 7
    13
      src/contentScript.js
  2. 7
    3
      src/functions.js

+ 7
- 13
src/contentScript.js 查看文件

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' ||
getComputedStyle(mutation.target).position == 'sticky') {
mutation.target.remove();
console.log("Killing a sticky!");

// Compensate for fullscreen paywalls.
restoreScrollability();
}
killSticky(mutation.target);
} }
}); });


let shouldKillSticky = checkForShouldKillSticky(result); let shouldKillSticky = checkForShouldKillSticky(result);
updateIcon(shouldKillSticky); updateIcon(shouldKillSticky);
if (shouldKillSticky) { if (shouldKillSticky) {
startConstantVigilance();
function beginKillingStickies() {
killSticky();
startConstantVigilance();
}
if (document.readyState == "loading") { if (document.readyState == "loading") {
document.addEventListener("DOMContentLoaded", () => {
killSticky();
});
document.addEventListener("DOMContentLoaded", beginKillingStickies);
} else { } else {
killSticky();
beginKillingStickies();
} }
} }
}); });

+ 7
- 3
src/functions.js 查看文件

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() {
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' || 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();
} }

Loading…
取消
儲存