|
|
|
|
|
|
|
|
zero exclusion matters match the URL of the current page) |
|
|
zero exclusion matters match the URL of the current page) |
|
|
*/ |
|
|
*/ |
|
|
function checkForShouldKillSticky(result) { |
|
|
function checkForShouldKillSticky(result) { |
|
|
|
|
|
console.log("checkForShouldKillSticky"); |
|
|
var shouldKillSticky = false; |
|
|
var shouldKillSticky = false; |
|
|
|
|
|
|
|
|
/* If whitelist mode is active, then the matching patterns list is treated |
|
|
/* If whitelist mode is active, then the matching patterns list is treated |
|
|
|
|
|
|
|
|
‘sticky’ or ‘fixed’, and removes those elements. |
|
|
‘sticky’ or ‘fixed’, and removes those elements. |
|
|
*/ |
|
|
*/ |
|
|
function killSticky(root) { |
|
|
function killSticky(root) { |
|
|
|
|
|
console.log("killSticky"); |
|
|
root = root || document.querySelector("body"); |
|
|
root = root || document.querySelector("body"); |
|
|
if (killStickyIfNeeded(root) == false) { |
|
|
if (killStickyIfNeeded(root) == false) { |
|
|
root.querySelectorAll('*').forEach(element => { |
|
|
root.querySelectorAll('*').forEach(element => { |
|
|
|
|
|
|
|
|
// Compensate for full-screen paywalls. |
|
|
// Compensate for full-screen paywalls. |
|
|
restoreScrollability(); |
|
|
restoreScrollability(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function killStickyIfNeeded(element) { |
|
|
function killStickyIfNeeded(element) { |
|
|
let position = getComputedStyle(element).position; |
|
|
|
|
|
|
|
|
console.log("killStickyIfNeeded"); |
|
|
|
|
|
var position = getComputedStyle(element).position; |
|
|
if (position === 'fixed' || position === 'sticky') { |
|
|
if (position === 'fixed' || position === 'sticky') { |
|
|
// uBlock exception. |
|
|
// uBlock exception. |
|
|
if (element.tagName == "IFRAME" && |
|
|
if (element.tagName == "IFRAME" && |
|
|
|
|
|
|
|
|
element.remove(); |
|
|
element.remove(); |
|
|
|
|
|
|
|
|
// Increment the stickies killed count, and update icon badge. |
|
|
// Increment the stickies killed count, and update icon badge. |
|
|
AKS.stickiesKilled++; |
|
|
|
|
|
chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled }); |
|
|
|
|
|
|
|
|
incrementKilledStickiesCount(); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
var didKillSticky = false; |
|
|
|
|
|
|
|
|
|
|
|
// The ::before pseudo-element might be sticky on its own. |
|
|
|
|
|
position = getComputedStyle(element, "::before").position; |
|
|
|
|
|
if (position === 'fixed' || position === 'sticky') { |
|
|
|
|
|
// Kill the sticky. |
|
|
|
|
|
console.log("Killing sticky!"); |
|
|
|
|
|
killStickyPseudoElement(element, true); |
|
|
|
|
|
|
|
|
|
|
|
// Increment the stickies killed count, and update icon badge. |
|
|
|
|
|
incrementKilledStickiesCount(); |
|
|
|
|
|
|
|
|
|
|
|
didKillSticky = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// The ::after pseudo-element, too, might be sticky on its own. |
|
|
|
|
|
position = getComputedStyle(element, "::after").position; |
|
|
|
|
|
if (position === 'fixed' || position === 'sticky') { |
|
|
|
|
|
// Kill the sticky. |
|
|
|
|
|
console.log("Killing sticky!"); |
|
|
|
|
|
killStickyPseudoElement(element, false); |
|
|
|
|
|
|
|
|
|
|
|
// Increment the stickies killed count, and update icon badge. |
|
|
|
|
|
incrementKilledStickiesCount(); |
|
|
|
|
|
|
|
|
|
|
|
didKillSticky = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function killStickyPseudoElement(element, before) { |
|
|
|
|
|
console.log("killStickyPseudoElement"); |
|
|
|
|
|
if (!AKS.pseudoElementKillingStyleBlock) { |
|
|
|
|
|
document.querySelector("head").insertAdjacentHTML("beforeend", "<style id='always-kill-sticky'></style>"); |
|
|
|
|
|
AKS.pseudoElementKillingStyleBlock = document.querySelector("style#always-kill-sticky"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var id = element.id; |
|
|
|
|
|
if (id == "") |
|
|
|
|
|
element.id = "always-kill-sticky-killed-element-" + (++AKS.stickyElementIDs); |
|
|
|
|
|
|
|
|
|
|
|
let selector = `${element.tagName}#${element.id}::${(before ? 'before' : 'after')}`; |
|
|
|
|
|
AKS.pseudoElementKillingStyleBlock.innerHTML = AKS.pseudoElementKillingStyleBlock.innerHTML + `${selector} { content: none; }\n`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function incrementKilledStickiesCount() { |
|
|
|
|
|
console.log("incrementKilledStickiesCount"); |
|
|
|
|
|
AKS.stickiesKilled++; |
|
|
|
|
|
chrome.runtime.sendMessage({ newBadgeText: "" + AKS.stickiesKilled }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
|
|
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
|
|
/* Full-screen paywalls not only bring up sticky elements, they also make |
|
|
/* Full-screen paywalls not only bring up sticky elements, they also make |
|
|
the page un-scrollable. This ensures that the page remains scrollable. |
|
|
the page un-scrollable. This ensures that the page remains scrollable. |
|
|
*/ |
|
|
*/ |
|
|
function restoreScrollability() { |
|
|
function restoreScrollability() { |
|
|
|
|
|
console.log("restoreScrollability"); |
|
|
document.querySelectorAll("html, body").forEach(container => { |
|
|
document.querySelectorAll("html, body").forEach(container => { |
|
|
container.style.setProperty("overflow-y", "auto", "important"); |
|
|
container.style.setProperty("overflow-y", "auto", "important"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
necessary, killing any newly-formed stickies. |
|
|
necessary, killing any newly-formed stickies. |
|
|
*/ |
|
|
*/ |
|
|
function startConstantVigilance() { |
|
|
function startConstantVigilance() { |
|
|
|
|
|
console.log("startConstantVigilance"); |
|
|
var observer = new MutationObserver((mutationsList, observer) => { |
|
|
var observer = new MutationObserver((mutationsList, observer) => { |
|
|
window.requestIdleCallback(() => { |
|
|
window.requestIdleCallback(() => { |
|
|
for (var mutation of mutationsList) { |
|
|
for (var mutation of mutationsList) { |
|
|
|
|
|
|
|
|
/* Immediately kill all stickies, then commence constant vigilance. |
|
|
/* Immediately kill all stickies, then commence constant vigilance. |
|
|
*/ |
|
|
*/ |
|
|
function beginKillingStickies() { |
|
|
function beginKillingStickies() { |
|
|
|
|
|
console.log("beginKillingStickies"); |
|
|
if (!window.AKS) window.AKS = { stickiesKilled: 0 }; |
|
|
if (!window.AKS) window.AKS = { stickiesKilled: 0 }; |
|
|
|
|
|
|
|
|
window.requestIdleCallback(() => { |
|
|
window.requestIdleCallback(() => { |
|
|
|
|
|
|
|
|
/******************/ |
|
|
/******************/ |
|
|
|
|
|
|
|
|
function initialize() { |
|
|
function initialize() { |
|
|
|
|
|
console.log("initialize"); |
|
|
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { |
|
|
chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { |
|
|
let shouldKillSticky = checkForShouldKillSticky(result); |
|
|
let shouldKillSticky = checkForShouldKillSticky(result); |
|
|
updateIcon(shouldKillSticky); |
|
|
updateIcon(shouldKillSticky); |