1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

Improve zapper's detection of scroll-locked documents

This commit is contained in:
Raymond Hill 2020-11-18 14:11:36 -05:00
parent ee2fd45f00
commit 38cecddcd1
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -921,12 +921,12 @@ const zapElementAtPoint = function(mx, my, options) {
return;
}
let elem = targetElements.length !== 0 && targetElements[0] || null;
if ( elem === null && mx !== undefined ) {
elem = elementFromPoint(mx, my);
let elemToRemove = targetElements.length !== 0 && targetElements[0] || null;
if ( elemToRemove === null && mx !== undefined ) {
elemToRemove = elementFromPoint(mx, my);
}
if ( elem instanceof Element === false ) { return; }
if ( elemToRemove instanceof Element === false ) { return; }
const getStyleValue = function(elem, prop) {
const style = window.getComputedStyle(elem);
@ -934,23 +934,30 @@ const zapElementAtPoint = function(mx, my, options) {
};
// Heuristic to detect scroll-locking: remove such lock when detected.
if (
parseInt(getStyleValue(elem, 'zIndex'), 10) >= 1000 ||
getStyleValue(elem, 'position') === 'fixed'
) {
let maybeScrollLocked = false;
let elem = elemToRemove;
do {
maybeScrollLocked =
parseInt(getStyleValue(elem, 'zIndex'), 10) >= 1000 ||
getStyleValue(elem, 'position') === 'fixed';
elem = elem.parentElement;
} while ( elem !== null && maybeScrollLocked === false );
if ( maybeScrollLocked ) {
const doc = document;
if ( getStyleValue(doc.body, 'overflowY') === 'hidden' ) {
doc.body.style.setProperty('overflow', 'auto', 'important');
}
if ( getStyleValue(doc.body, 'position') === 'fixed' ) {
doc.body.style.setProperty('position', 'static', 'important');
doc.body.style.setProperty('position', 'initial', 'important');
}
if ( getStyleValue(doc.documentElement, 'position') === 'fixed' ) {
doc.documentElement.style.setProperty('position', 'initial', 'important');
}
if ( getStyleValue(doc.documentElement, 'overflowY') === 'hidden' ) {
doc.documentElement.style.setProperty('overflow', 'auto', 'important');
}
}
elem.remove();
elemToRemove.remove();
highlightElementAtPoint(mx, my);
};