Index: chrome/content/elemHideEmulation.js |
=================================================================== |
--- a/chrome/content/elemHideEmulation.js |
+++ b/chrome/content/elemHideEmulation.js |
@@ -312,16 +312,17 @@ |
function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, |
hideElemsFunc) |
{ |
this.window = window; |
this.getFiltersFunc = getFiltersFunc; |
this.addSelectorsFunc = addSelectorsFunc; |
this.hideElemsFunc = hideElemsFunc; |
+ this.observer = new MutationObserver(this.observe.bind(this)); |
Wladimir Palant
2017/07/21 21:37:28
new window.MutationObserver?
hub
2017/07/22 01:31:24
https://developer.mozilla.org/en-US/docs/Web/API/M
hub
2017/07/23 15:36:34
My bad. will actually do that.
|
} |
ElemHideEmulation.prototype = { |
isSameOrigin(stylesheet) |
{ |
try |
{ |
return new URL(stylesheet.href).origin == this.window.location.origin; |
@@ -482,53 +483,77 @@ |
} |
this.addSelectorsFunc(selectors, selectorFilters); |
this.hideElemsFunc(elements, elementFilters); |
}, |
_stylesheetQueue: null, |
+ queueFiltering() |
+ { |
+ if (!this._stylesheetQueue && |
+ Date.now() - this._lastInvocation < MIN_INVOCATION_INTERVAL) |
+ { |
+ this._stylesheetQueue = []; |
+ this.window.setTimeout(() => |
+ { |
+ let stylesheets = this._stylesheetQueue; |
+ this._stylesheetQueue = null; |
+ this.addSelectors(stylesheets); |
+ }, MIN_INVOCATION_INTERVAL - (Date.now() - this._lastInvocation)); |
+ } |
+ }, |
+ |
onLoad(event) |
{ |
let stylesheet = event.target.sheet; |
if (stylesheet) |
{ |
- if (!this._stylesheetQueue && |
- Date.now() - this._lastInvocation < MIN_INVOCATION_INTERVAL) |
- { |
- this._stylesheetQueue = []; |
- this.window.setTimeout(() => |
- { |
- let stylesheets = this._stylesheetQueue; |
- this._stylesheetQueue = null; |
- this.addSelectors(stylesheets); |
- }, MIN_INVOCATION_INTERVAL - (Date.now() - this._lastInvocation)); |
- } |
+ this.queueFiltering(); |
if (this._stylesheetQueue) |
this._stylesheetQueue.push(stylesheet); |
else |
this.addSelectors([stylesheet]); |
} |
}, |
+ observe(mutations) |
+ { |
+ for (let mutation of mutations) |
+ { |
+ if (mutation.type == "childList") |
+ { |
+ this.queueFiltering(); |
Wladimir Palant
2017/07/21 21:37:28
a) Reapplying the rules on the entire document is
hub
2017/07/22 01:31:24
Acknowledged.
|
+ break; |
+ } |
+ } |
+ }, |
+ |
apply() |
{ |
this.getFiltersFunc(patterns => |
{ |
this.patterns = []; |
for (let pattern of patterns) |
{ |
let selectors = this.parseSelector(pattern.selector); |
if (selectors != null && selectors.length > 0) |
this.patterns.push({selectors, text: pattern.text}); |
} |
if (this.patterns.length > 0) |
{ |
let {document} = this.window; |
this.addSelectors(); |
+ this.observer.observe( |
+ document, |
+ { |
+ childList: true, |
+ subtree: true |
+ } |
+ ); |
document.addEventListener("load", this.onLoad.bind(this), true); |
} |
}); |
} |
}; |