mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-15 07:22:28 +02:00
select optimal hideElements
depending on whether shadow DOM is supported
This commit is contained in:
parent
02874dfd05
commit
ab24f725ce
@ -443,28 +443,30 @@ var uBlockCollapser = (function() {
|
||||
//console.debug('µBlock> generic cosmetic filters: injecting %d CSS rules:', selectors.length, text);
|
||||
};
|
||||
|
||||
var hideElements = function(selectors) {
|
||||
var hideElements = (function() {
|
||||
if ( document.body === null ) {
|
||||
return function() {};
|
||||
}
|
||||
if ( document.body.shadowRoot === undefined ) {
|
||||
return function(selectors) {
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/207
|
||||
// Do not call querySelectorAll() using invalid CSS selectors
|
||||
if ( selectors.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
if ( document.body === null ) {
|
||||
return;
|
||||
}
|
||||
if ( selectors.length === 0 ) { return; }
|
||||
var elems = document.querySelectorAll(selectors);
|
||||
var i = elems.length;
|
||||
if ( i === 0 ) {
|
||||
return;
|
||||
}
|
||||
if ( i === 0 ) { return; }
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/158
|
||||
// Using CSSStyleDeclaration.setProperty is more reliable
|
||||
if ( document.body.shadowRoot === undefined ) {
|
||||
while ( i-- ) {
|
||||
elems[i].style.setProperty('display', 'none', 'important');
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
return function(selectors) {
|
||||
if ( selectors.length === 0 ) { return; }
|
||||
var elems = document.querySelectorAll(selectors);
|
||||
var i = elems.length;
|
||||
if ( i === 0 ) { return; }
|
||||
// https://github.com/gorhill/uBlock/issues/435
|
||||
// Using shadow content so that we do not have to modify style
|
||||
// attribute.
|
||||
@ -492,6 +494,7 @@ var uBlockCollapser = (function() {
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
// Extract and return the staged nodes which (may) match the selectors.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user