| Index: include.preload.js |
| diff --git a/include.preload.js b/include.preload.js |
| index 86e52c32afceb894f6591a84b0eca3b1842383ce..45ccb31fc17a23ca3395ee798033f65e2df77f4d 100644 |
| --- a/include.preload.js |
| +++ b/include.preload.js |
| @@ -192,64 +192,76 @@ function getContentDocument(element) |
| } |
| } |
| -function ElementHidingTracer(selectors) |
| +function ElementHidingTracer() |
| { |
| - this.selectors = selectors; |
| + this.selectors = []; |
| + this.filters = []; |
| this.changedNodes = []; |
| this.timeout = null; |
| + this.started = false; |
| this.observer = new MutationObserver(this.observe.bind(this)); |
| this.trace = this.trace.bind(this); |
| - |
| - if (document.readyState == "loading") |
| - document.addEventListener("DOMContentLoaded", this.trace); |
| - else |
| - this.trace(); |
| } |
| ElementHidingTracer.prototype = { |
| - checkNodes: function(nodes) |
| + start: function() |
|
Sebastian Noack
2017/02/14 10:58:16
Do we even need the start method (and started flag
Sebastian Noack
2017/02/14 11:27:58
I just noticed that currently we have to call trac
wspee
2017/02/15 14:09:57
If we implement your suggestions wouldn't that mea
Sebastian Noack
2017/02/15 18:49:03
We should defer tracing (i.e. traversing through t
wspee
2017/02/17 10:51:38
Done.
|
| { |
| - var matchedSelectors = []; |
| + if (document.readyState == "loading") |
| + document.addEventListener("DOMContentLoaded", this.trace); |
| + else |
| + this.trace(); |
| + }, |
| - // Find all selectors that match any hidden element inside the given nodes. |
| - for (var i = 0; i < this.selectors.length; i++) |
| - { |
| - var selector = this.selectors[i]; |
| + addFilters: function(selectors, filters) |
|
Sebastian Noack
2017/02/14 10:58:16
I think this method should rather be called addSel
wspee
2017/02/15 14:09:57
Done.
|
| + { |
| + if (this.started) |
| + window.setTimeout(() => { |
| + this.checkNodes([document], selectors, filters); |
| + }, 0); |
| + |
| + if (!filters) |
|
Sebastian Noack
2017/02/14 10:58:16
I'd move this to the top of the function. If we ge
wspee
2017/02/15 14:09:56
Done.
|
| + filters = new Array(selectors.length); |
| + |
| + this.selectors.push(...selectors); |
| + this.filters.push(...filters); |
| + }, |
| + |
| + checkNodes: function(nodes, selectors, filters) |
| + { |
| + let matchedFilters = []; |
| - for (var j = 0; j < nodes.length; j++) |
| + for (let i = 0; i < selectors.length; i++) |
| + { |
| + nodes: for (let node of nodes) |
| { |
| - var elements = nodes[j].querySelectorAll(selector); |
| - var matched = false; |
| + let elements = node.querySelectorAll(selectors[i]); |
| - for (var k = 0; k < elements.length; k++) |
| + for (let element of elements) |
| { |
| // Only consider selectors that actually have an effect on the |
| // computed styles, and aren't overridden by rules with higher |
| // priority, or haven't been circumvented in a different way. |
| - if (getComputedStyle(elements[k]).display == "none") |
| + if (getComputedStyle(element).display == "none") |
| { |
| - matchedSelectors.push(selector); |
|
Sebastian Noack
2017/02/14 11:27:58
Renaming this variable to matchedFilters seems ina
wspee
2017/02/15 14:09:57
In case of an ElementHidingEmulationFilter we want
Sebastian Noack
2017/02/15 18:49:03
We never send the actual filter, as we remove the
wspee
2017/02/17 10:51:38
No, that's the change I made, for ElemHideEmulatio
Sebastian Noack
2017/02/17 13:55:30
And what do you do in the line below? ;)
matche
Sebastian Noack
2017/02/18 11:41:18
This comment hasn't been resolved yet.
wspee
2017/02/18 13:00:14
Done, you were right after all ;).
|
| - matched = true; |
| - break; |
| + let filter = filters[i] || selectors[i]; |
| + matchedFilters.push(filter.replace(/^.*?##/, "")); |
| + break nodes; |
| } |
| } |
| - |
| - if (matched) |
| - break; |
| } |
| } |
| - if (matchedSelectors.length > 0) |
| + if (matchedFilters.length > 0) |
| ext.backgroundPage.sendMessage({ |
| type: "devtools.traceElemHide", |
| - selectors: matchedSelectors |
| + selectors: matchedFilters |
| }); |
| }, |
| onTimeout: function() |
| { |
| - this.checkNodes(this.changedNodes); |
| + this.checkNodes(this.changedNodes, this.selectors, this.filters); |
| this.changedNodes = []; |
| this.timeout = null; |
| }, |
| @@ -312,7 +324,8 @@ ElementHidingTracer.prototype = { |
| trace: function() |
| { |
| - this.checkNodes([document]); |
| + this.started = true; |
| + this.checkNodes([document], this.selectors, this.filters); |
| this.observer.observe( |
| document, |
| @@ -490,11 +503,14 @@ ElemHide.prototype = { |
| return shadow; |
| }, |
| - addSelectors: function(selectors) |
| + addSelectors: function(selectors, filters) |
| { |
| - if (selectors.length == 0) |
| + if (!selectors.length) |
| return; |
| + if (this.tracer) |
| + this.tracer.addFilters(selectors, filters); |
| + |
| if (!this.style) |
| { |
| // Create <style> element lazily, only if we add styles. Add it to |
| @@ -544,38 +560,33 @@ ElemHide.prototype = { |
| apply: function() |
| { |
| var selectors = null; |
| - var elemHideEmulationLoaded = false; |
| var checkLoaded = function() |
| { |
| - if (!selectors || !elemHideEmulationLoaded) |
| - return; |
| - |
| if (this.tracer) |
| this.tracer.disconnect(); |
| this.tracer = null; |
| + if (selectors.trace) |
| + this.tracer = new ElementHidingTracer(); |
| + |
| if (this.style && this.style.parentElement) |
| this.style.parentElement.removeChild(this.style); |
| this.style = null; |
| - this.addSelectors(selectors.selectors); |
| + if (selectors.selectors) |
| + this.addSelectors(selectors.selectors); |
| + |
| this.elemHideEmulation.apply(); |
| - if (selectors.trace) |
| - this.tracer = new ElementHidingTracer(selectors.selectors); |
| + if (this.tracer) |
| + this.tracer.start(); |
| }.bind(this); |
| - ext.backgroundPage.sendMessage({type: "get-selectors"}, function(response) |
| + ext.backgroundPage.sendMessage({type: "get-selectors"}, response => |
| { |
| selectors = response; |
| - checkLoaded(); |
| - }); |
| - |
| - this.elemHideEmulation.load(function() |
| - { |
| - elemHideEmulationLoaded = true; |
| - checkLoaded(); |
| + this.elemHideEmulation.load(checkLoaded); |
|
Sebastian Noack
2017/02/14 10:58:16
Why did you move this inside this callback? That w
wspee
2017/02/15 14:09:56
Hmm ... because this way checkLoaded is only calle
Sebastian Noack
2017/02/15 18:49:03
Well, the whole point of having checkLoaded(), as
wspee
2017/02/17 10:51:38
Like so?
Sebastian Noack
2017/02/17 13:55:30
Almost. ;)
|
| }); |
| } |
| }; |