mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Improve zapper's detection of scroll-locked documents
This commit is contained in:
parent
ee2fd45f00
commit
38cecddcd1
1 changed files with 18 additions and 11 deletions
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue