| Index: lib/content/elemHideEmulation.js |
| =================================================================== |
| --- a/lib/content/elemHideEmulation.js |
| +++ b/lib/content/elemHideEmulation.js |
| @@ -297,16 +297,44 @@ |
| }; |
| function isSelectorHidingOnlyPattern(pattern) |
| { |
| return pattern.selectors.some(s => s.preferHideWithSelector) && |
| !pattern.selectors.some(s => s.requiresHiding); |
| } |
| +function shouldObserveAttributes(patterns) |
| +{ |
| + // Observe changes to attributes if either there's a plain selector that |
| + // looks like an attribute selector in one of the patterns |
| + // (e.g. "a[href='https://example.com/']") |
| + // or there's a properties selector nested inside a has selector |
| + // (e.g. "div:-abp-has(:-abp-properties(color: blue))") |
| + return patterns.some( |
| + pattern => pattern.selectors.some( |
| + selector => (selector instanceof PlainSelector && |
| + /\[.+\]/.test(selector._selector))|| |
|
Manish Jethani
2017/10/22 22:58:13
This check for attribute selector syntax can give
|
| + (pattern.selectors[0] instanceof HasSelector && |
|
Manish Jethani
2017/10/22 22:58:13
I realize that the second check is essentially pat
Manish Jethani
2017/10/23 00:12:09
Done.
|
| + selector instanceof PropsSelector) |
| + ) |
| + ); |
| +} |
| + |
| +function shouldObserveCharacterData(patterns) |
| +{ |
| + // Observe changes to character data only if there's a contains selector in |
| + // one of the patterns. |
| + return patterns.some( |
| + pattern => pattern.selectors.some( |
| + selector => selector instanceof ContainsSelector |
| + ) |
| + ); |
| +} |
| + |
| function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) |
| { |
| this.document = document; |
| this.addSelectorsFunc = addSelectorsFunc; |
| this.hideElemsFunc = hideElemsFunc; |
| this.observer = new MutationObserver(this.observe.bind(this)); |
| } |
| @@ -582,18 +610,18 @@ |
| if (this.patterns.length > 0) |
| { |
| this.queueFiltering(); |
| this.observer.observe( |
| this.document, |
| { |
| childList: true, |
| - attributes: true, |
| - characterData: true, |
| + attributes: shouldObserveAttributes(this.patterns), |
| + characterData: shouldObserveCharacterData(this.patterns), |
| subtree: true |
| } |
| ); |
| this.document.addEventListener("load", this.onLoad.bind(this), true); |
| } |
| } |
| }; |