| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 yield [selector, subtree]; | 295 yield [selector, subtree]; |
| 296 } | 296 } |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 function isSelectorHidingOnlyPattern(pattern) | 299 function isSelectorHidingOnlyPattern(pattern) |
| 300 { | 300 { |
| 301 return pattern.selectors.some(s => s.preferHideWithSelector) && | 301 return pattern.selectors.some(s => s.preferHideWithSelector) && |
| 302 !pattern.selectors.some(s => s.requiresHiding); | 302 !pattern.selectors.some(s => s.requiresHiding); |
| 303 } | 303 } |
| 304 | 304 |
| 305 function shouldObserveAttributes(patterns) | |
| 306 { | |
| 307 // Observe changes to attributes if either there's a plain selector that | |
| 308 // looks like an attribute selector in one of the patterns | |
| 309 // (e.g. "a[href='https://example.com/']") | |
| 310 // or there's a properties selector nested inside a has selector | |
| 311 // (e.g. "div:-abp-has(:-abp-properties(color: blue))") | |
| 312 return patterns.some( | |
| 313 pattern => pattern.selectors.some( | |
| 314 selector => (selector instanceof PlainSelector && | |
| 315 /\[.+\]/.test(selector._selector))|| | |
|
Manish Jethani
2017/10/22 22:58:13
This check for attribute selector syntax can give
| |
| 316 (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.
| |
| 317 selector instanceof PropsSelector) | |
| 318 ) | |
| 319 ); | |
| 320 } | |
| 321 | |
| 322 function shouldObserveCharacterData(patterns) | |
| 323 { | |
| 324 // Observe changes to character data only if there's a contains selector in | |
| 325 // one of the patterns. | |
| 326 return patterns.some( | |
| 327 pattern => pattern.selectors.some( | |
| 328 selector => selector instanceof ContainsSelector | |
| 329 ) | |
| 330 ); | |
| 331 } | |
| 332 | |
| 305 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) | 333 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) |
| 306 { | 334 { |
| 307 this.document = document; | 335 this.document = document; |
| 308 this.addSelectorsFunc = addSelectorsFunc; | 336 this.addSelectorsFunc = addSelectorsFunc; |
| 309 this.hideElemsFunc = hideElemsFunc; | 337 this.hideElemsFunc = hideElemsFunc; |
| 310 this.observer = new MutationObserver(this.observe.bind(this)); | 338 this.observer = new MutationObserver(this.observe.bind(this)); |
| 311 } | 339 } |
| 312 | 340 |
| 313 ElemHideEmulation.prototype = { | 341 ElemHideEmulation.prototype = { |
| 314 isSameOrigin(stylesheet) | 342 isSameOrigin(stylesheet) |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 this.patterns.push({selectors, text: pattern.text}); | 608 this.patterns.push({selectors, text: pattern.text}); |
| 581 } | 609 } |
| 582 | 610 |
| 583 if (this.patterns.length > 0) | 611 if (this.patterns.length > 0) |
| 584 { | 612 { |
| 585 this.queueFiltering(); | 613 this.queueFiltering(); |
| 586 this.observer.observe( | 614 this.observer.observe( |
| 587 this.document, | 615 this.document, |
| 588 { | 616 { |
| 589 childList: true, | 617 childList: true, |
| 590 attributes: true, | 618 attributes: shouldObserveAttributes(this.patterns), |
| 591 characterData: true, | 619 characterData: shouldObserveCharacterData(this.patterns), |
| 592 subtree: true | 620 subtree: true |
| 593 } | 621 } |
| 594 ); | 622 ); |
| 595 this.document.addEventListener("load", this.onLoad.bind(this), true); | 623 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 596 } | 624 } |
| 597 } | 625 } |
| 598 }; | 626 }; |
| 599 | 627 |
| 600 exports.ElemHideEmulation = ElemHideEmulation; | 628 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |