@ -17,6 +17,7 @@
zero exclusion matters match the URL of the current page )
* /
function checkForShouldKillSticky ( result ) {
// console.log("checkForShouldKillSticky");
var shouldKillSticky = false ;
/ * I f w h i t e l i s t m o d e i s a c t i v e , t h e n t h e m a t c h i n g p a t t e r n s l i s t i s t r e a t e d
@ -54,38 +55,99 @@ function checkForShouldKillSticky(result) {
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/ * T h i s i s t h e c o d e t h a t a c t u a l l y d o e s t h e s t i c k y k i l l i n g ! I t s i m p l y s e l e c t s
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 ) {
// console.log("killSticky");
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 ) {
// console.log("killStickyIfNeeded");
var 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.
incrementKilledStickiesCount ( ) ;
return true ;
} 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 ;
}
}
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 } ) ;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/ * F u l l - s c r e e n p a y w a l l s n o t o n l y b r i n g u p s t i c k y e l e m e n t s , t h e y a l s o m a k e
the page un - scrollable . This ensures that the page remains scrollable .
* /
function restoreScrollability ( ) {
// console.log("restoreScrollability");
document . querySelectorAll ( "html, body" ) . forEach ( container => {
container . style . setProperty ( "overflow-y" , "auto" , "important" ) ;
} ) ;
@ -98,6 +160,7 @@ function restoreScrollability() {
necessary , killing any newly - formed stickies .
* /
function startConstantVigilance ( ) {
// console.log("startConstantVigilance");
var observer = new MutationObserver ( ( mutationsList , observer ) => {
window . requestIdleCallback ( ( ) => {
for ( var mutation of mutationsList ) {
@ -118,6 +181,7 @@ function startConstantVigilance() {
/ * I m m e d i a t e l y k i l l a l l s t i c k i e s , t h e n c o m m e n c e c o n s t a n t v i g i l a n c e .
* /
function beginKillingStickies ( ) {
// console.log("beginKillingStickies");
if ( ! window . AKS ) window . AKS = { stickiesKilled : 0 } ;
window . requestIdleCallback ( ( ) => {
@ -131,6 +195,7 @@ function beginKillingStickies() {
/******************/
function initialize ( ) {
// console.log("initialize");
chrome . storage . local . get ( [ "matchingPatterns" , "exclusionPatterns" , "mode" ] , ( result ) => {
let shouldKillSticky = checkForShouldKillSticky ( result ) ;
updateIcon ( shouldKillSticky ) ;