aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-09-15 09:51:22 -0400
committergorhill <rhill@raymondhill.net>2015-09-15 09:51:22 -0400
commitab24f725ce9df85b88274c89104c85f6c072af99 (patch)
tree98732532e6c23efc141fe294fc4499512b21f709 /src
parent02874dfd05407b48ee0ef22d5ec793e927617a5a (diff)
downloaduBlock-ab24f725ce9df85b88274c89104c85f6c072af99.zip
uBlock-ab24f725ce9df85b88274c89104c85f6c072af99.tar.gz
uBlock-ab24f725ce9df85b88274c89104c85f6c072af99.tar.bz2
select optimal `hideElements` depending on whether shadow DOM is supported
Diffstat (limited to 'src')
-rw-r--r--src/js/contentscript-end.js87
1 files changed, 45 insertions, 42 deletions
diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js
index b4cd920..776862f 100644
--- a/src/js/contentscript-end.js
+++ b/src/js/contentscript-end.js
@@ -443,55 +443,58 @@ var uBlockCollapser = (function() {
//console.debug('µBlock> generic cosmetic filters: injecting %d CSS rules:', selectors.length, text);
};
- var hideElements = function(selectors) {
- // https://github.com/chrisaljoudi/uBlock/issues/207
- // Do not call querySelectorAll() using invalid CSS selectors
- if ( selectors.length === 0 ) {
- return;
- }
+ var hideElements = (function() {
if ( document.body === null ) {
- return;
- }
- var elems = document.querySelectorAll(selectors);
- var i = elems.length;
- if ( i === 0 ) {
- return;
+ return function() {};
}
- // https://github.com/chrisaljoudi/uBlock/issues/158
- // Using CSSStyleDeclaration.setProperty is more reliable
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; }
+ var elems = document.querySelectorAll(selectors);
+ var i = elems.length;
+ if ( i === 0 ) { return; }
+ // https://github.com/chrisaljoudi/uBlock/issues/158
+ // Using CSSStyleDeclaration.setProperty is more reliable
+ while ( i-- ) {
+ elems[i].style.setProperty('display', 'none', 'important');
+ }
+ };
+ }
+ 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.
+ var sessionId = vAPI.sessionId;
+ var elem, shadow;
while ( i-- ) {
- elems[i].style.setProperty('display', 'none', 'important');
- }
- return;
- }
- // https://github.com/gorhill/uBlock/issues/435
- // Using shadow content so that we do not have to modify style
- // attribute.
- var sessionId = vAPI.sessionId;
- var elem, shadow;
- while ( i-- ) {
- elem = elems[i];
- shadow = elem.shadowRoot;
- // https://www.chromestatus.com/features/4668884095336448
- // "Multiple shadow roots is being deprecated."
- if ( shadow !== null ) {
- if ( shadow.className !== sessionId ) {
+ elem = elems[i];
+ shadow = elem.shadowRoot;
+ // https://www.chromestatus.com/features/4668884095336448
+ // "Multiple shadow roots is being deprecated."
+ if ( shadow !== null ) {
+ if ( shadow.className !== sessionId ) {
+ elem.style.setProperty('display', 'none', 'important');
+ }
+ continue;
+ }
+ // https://github.com/gorhill/uBlock/pull/555
+ // Not all nodes can be shadowed:
+ // https://github.com/w3c/webcomponents/issues/102
+ try {
+ shadow = elem.createShadowRoot();
+ shadow.className = sessionId;
+ } catch (ex) {
elem.style.setProperty('display', 'none', 'important');
}
- continue;
- }
- // https://github.com/gorhill/uBlock/pull/555
- // Not all nodes can be shadowed:
- // https://github.com/w3c/webcomponents/issues/102
- try {
- shadow = elem.createShadowRoot();
- shadow.className = sessionId;
- } catch (ex) {
- elem.style.setProperty('display', 'none', 'important');
}
- }
- };
+ };
+ })();
// Extract and return the staged nodes which (may) match the selectors.