Defuse fixed position on body element in element zapper

The `fixed` style property on the `body` element will be
defused if an overlay element is removed using the element
zapper.

Related:
- https://www.reddit.com/r/uBlockOrigin/comments/bktxtb/scrolling_doesnt_work/emlscyz
This commit is contained in:
Raymond Hill 2019-05-06 13:32:55 -04:00
parent 26237d6d40
commit e59bdb1485
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -1259,18 +1259,38 @@ const showDialog = function(options) {
/******************************************************************************/
// https://www.reddit.com/r/uBlockOrigin/comments/bktxtb/scrolling_doesnt_work/emn901o
// Override 'fixed' position property on body element if present.
const zap = function() {
if ( targetElements.length === 0 ) { return; }
const getStyleValue = function(elem, prop) {
const style = window.getComputedStyle(elem);
return style ? style[prop] : '';
};
let elem = targetElements[0];
const style = window.getComputedStyle(elem);
// Heuristic to detect scroll-locking: remove such lock when detected.
if ( parseInt(style.zIndex, 10) >= 1000 || style.position === 'fixed' ) {
document.body.style.setProperty('overflow', 'auto', 'important');
document.documentElement.style.setProperty('overflow', 'auto', 'important');
if (
parseInt(getStyleValue(elem, 'zIndex'), 10) >= 1000 ||
getStyleValue(elem, 'position') === 'fixed'
) {
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');
}
if ( getStyleValue(doc.documentElement, 'overflowY') === 'hidden' ) {
doc.documentElement.style.setProperty('overflow', 'auto', 'important');
}
}
elem.parentNode.removeChild(elem);
elem = elementFromPoint();
highlightElements(elem ? [elem] : []);
highlightElements(elem ? [ elem ] : []);
};
/******************************************************************************/