Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 yield null; | 144 yield null; |
145 else | 145 else |
146 yield* evaluate(chain, index + 1, selector, element, styles); | 146 yield* evaluate(chain, index + 1, selector, element, styles); |
147 } | 147 } |
148 // Just in case the getSelectors() generator above had to run some heavy | 148 // Just in case the getSelectors() generator above had to run some heavy |
149 // document.querySelectorAll() call which didn't produce any results, make | 149 // document.querySelectorAll() call which didn't produce any results, make |
150 // sure there is at least one point where execution can pause. | 150 // sure there is at least one point where execution can pause. |
151 yield null; | 151 yield null; |
152 } | 152 } |
153 | 153 |
154 function extractSubtrees(nodes) | 154 function isDescendantOf(node, subtrees) |
155 { | 155 { |
156 return nodes.filter( | 156 return subtrees.some(subtree => subtree.contains(node)); |
157 (node, index) => !nodes.some( | 157 } |
158 // The index comparison is based on the fact that a node always appears | 158 |
159 // in the list before any of its descendants. | 159 function* extractAddedSubtrees(mutations) |
160 (otherNode, otherIndex) => otherIndex < index && otherNode.contains(node) | 160 { |
161 ) | 161 let knownSubtrees = []; |
162 ); | 162 |
163 for (let mutation of mutations) | |
164 { | |
165 for (let node of mutation.addedNodes) | |
166 { | |
167 if (node instanceof Element && !isDescendantOf(node, knownSubtrees)) | |
168 { | |
169 knownSubtrees.push(node); | |
170 yield node; | |
171 } | |
172 } | |
173 } | |
163 } | 174 } |
164 | 175 |
165 function* traverse(nodes) | 176 function* traverse(nodes) |
166 { | 177 { |
167 for (let node of nodes) | 178 for (let node of nodes) |
168 { | 179 { |
169 yield* traverse(node.children); | 180 yield* traverse(node.children); |
170 yield node; | 181 yield node; |
171 } | 182 } |
172 } | 183 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 niceLoop(traverse(nodes), node => | 680 niceLoop(traverse(nodes), node => |
670 { | 681 { |
671 let shadowRoot = node.shadowRoot; | 682 let shadowRoot = node.shadowRoot; |
672 if (shadowRoot) | 683 if (shadowRoot) |
673 this.addShadowRoot(shadowRoot); | 684 this.addShadowRoot(shadowRoot); |
674 }); | 685 }); |
675 }, | 686 }, |
676 | 687 |
677 observe(mutations) | 688 observe(mutations) |
678 { | 689 { |
679 if (typeof ShadowRoot != "undefined") | 690 if (typeof ShadowRoot != "undefined") |
Manish Jethani
2017/10/20 16:16:42
Of course we only have to run this code on Chrome.
hub
2017/10/20 19:12:50
Maybe we should set a different mutation observer
Manish Jethani
2017/10/22 20:01:35
But both the observers would listen for the same D
hub
2017/10/23 13:30:34
not saying to observe twice. but when we set up th
Manish Jethani
2017/10/23 23:04:28
OK, I see what you mean. I think we're going to en
| |
680 { | 691 { |
681 let allAddedElements = []; | |
682 for (let mutation of mutations) | |
683 { | |
684 for (let node of mutation.addedNodes) | |
685 { | |
686 if (node instanceof Element) | |
687 allAddedElements.push(node); | |
688 } | |
689 } | |
690 | |
691 // Find any preattached shadows. | 692 // Find any preattached shadows. |
692 this.findShadowRoots(extractSubtrees(allAddedElements)); | 693 this.findShadowRoots(extractAddedSubtrees(mutations)); |
693 } | 694 } |
694 | 695 |
695 this.queueFiltering(); | 696 this.queueFiltering(); |
696 }, | 697 }, |
697 | 698 |
698 apply(patterns, parsed) | 699 apply(patterns, parsed) |
699 { | 700 { |
700 if (parsed) | 701 if (parsed) |
701 { | 702 { |
702 this.patterns = patterns; | 703 this.patterns = patterns; |
(...skipping 19 matching lines...) Expand all Loading... | |
722 attributes: true, | 723 attributes: true, |
723 characterData: true, | 724 characterData: true, |
724 subtree: true | 725 subtree: true |
725 } | 726 } |
726 ); | 727 ); |
727 } | 728 } |
728 } | 729 } |
729 }; | 730 }; |
730 | 731 |
731 exports.ElemHideEmulation = ElemHideEmulation; | 732 exports.ElemHideEmulation = ElemHideEmulation; |
LEFT | RIGHT |