| 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 { | 597 { |
| 598 return patterns.some(pattern => pattern.dependsOnCharacterData); | 598 return patterns.some(pattern => pattern.dependsOnCharacterData); |
| 599 } | 599 } |
| 600 | 600 |
| 601 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) | 601 function ElemHideEmulation(addSelectorsFunc, hideElemsFunc) |
| 602 { | 602 { |
| 603 this.document = document; | 603 this.document = document; |
| 604 this.addSelectorsFunc = addSelectorsFunc; | 604 this.addSelectorsFunc = addSelectorsFunc; |
| 605 this.hideElemsFunc = hideElemsFunc; | 605 this.hideElemsFunc = hideElemsFunc; |
| 606 this.observer = new MutationObserver(this.observe.bind(this)); | 606 this.observer = new MutationObserver(this.observe.bind(this)); |
| 607 this.useInlineStyles = true; | |
| 608 } | 607 } |
| 609 | 608 |
| 610 ElemHideEmulation.prototype = { | 609 ElemHideEmulation.prototype = { |
| 611 isSameOrigin(stylesheet) | 610 isSameOrigin(stylesheet) |
| 612 { | 611 { |
| 613 try | 612 try |
| 614 { | 613 { |
| 615 return new URL(stylesheet.href).origin == this.document.location.origin; | 614 return new URL(stylesheet.href).origin == this.document.location.origin; |
| 616 } | 615 } |
| 617 catch (e) | 616 catch (e) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 | 786 |
| 788 let evaluationTargets = targets; | 787 let evaluationTargets = targets; |
| 789 | 788 |
| 790 // If the pattern appears to contain any sibling combinators, we can't | 789 // If the pattern appears to contain any sibling combinators, we can't |
| 791 // easily optimize based on the mutation targets. Since this is a | 790 // easily optimize based on the mutation targets. Since this is a |
| 792 // special case, skip the optimization. By setting it to null here we | 791 // special case, skip the optimization. By setting it to null here we |
| 793 // make sure we process the entire DOM. | 792 // make sure we process the entire DOM. |
| 794 if (pattern.maybeContainsSiblingCombinators) | 793 if (pattern.maybeContainsSiblingCombinators) |
| 795 evaluationTargets = null; | 794 evaluationTargets = null; |
| 796 | 795 |
| 797 // Ignore mutation targets when using style sheets, because we may have | |
| 798 // to update all the CSS selectors. | |
| 799 if (!this.useInlineStyles) | |
| 800 evaluationTargets = null; | |
| 801 | |
| 802 generator = evaluate(pattern.selectors, 0, "", | 796 generator = evaluate(pattern.selectors, 0, "", |
| 803 this.document, cssStyles, evaluationTargets); | 797 this.document, cssStyles, evaluationTargets); |
| 804 } | 798 } |
| 805 for (let selector of generator) | 799 for (let selector of generator) |
| 806 { | 800 { |
| 807 if (selector != null) | 801 if (selector != null) |
| 808 { | 802 { |
| 809 if (!this.useInlineStyles) | 803 for (let element of this.document.querySelectorAll(selector)) |
| 810 { | 804 { |
| 811 selectors.push(selector); | 805 elements.push(element); |
| 812 selectorFilters.push(pattern.text); | 806 elementFilters.push(pattern.text); |
| 813 } | |
| 814 else | |
| 815 { | |
| 816 for (let element of this.document.querySelectorAll(selector)) | |
| 817 { | |
| 818 elements.push(element); | |
| 819 elementFilters.push(pattern.text); | |
| 820 } | |
| 821 } | 807 } |
| 822 } | 808 } |
| 823 if (performance.now() - cycleStart > MAX_SYNCHRONOUS_PROCESSING_TIME) | 809 if (performance.now() - cycleStart > MAX_SYNCHRONOUS_PROCESSING_TIME) |
| 824 { | 810 { |
| 825 setTimeout(processPatterns, 0); | 811 setTimeout(processPatterns, 0); |
| 826 return; | 812 return; |
| 827 } | 813 } |
| 828 } | 814 } |
| 829 pattern = null; | 815 pattern = null; |
| 830 return processPatterns(); | 816 return processPatterns(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 characterData: shouldObserveCharacterData(this.patterns), | 965 characterData: shouldObserveCharacterData(this.patterns), |
| 980 subtree: true | 966 subtree: true |
| 981 } | 967 } |
| 982 ); | 968 ); |
| 983 this.document.addEventListener("load", this.onLoad.bind(this), true); | 969 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 984 } | 970 } |
| 985 } | 971 } |
| 986 }; | 972 }; |
| 987 | 973 |
| 988 exports.ElemHideEmulation = ElemHideEmulation; | 974 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |