| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 const incompletePrefixRegexp = /[\s>+~]$/; | 243 const incompletePrefixRegexp = /[\s>+~]$/; |
| 244 | 244 |
| 245 function HasSelector(selectors) | 245 function HasSelector(selectors) |
| 246 { | 246 { |
| 247 this._innerSelectors = selectors; | 247 this._innerSelectors = selectors; |
| 248 } | 248 } |
| 249 | 249 |
| 250 HasSelector.prototype = { | 250 HasSelector.prototype = { |
| 251 requiresHiding: true, | |
| 252 dependsOnDOM: true, | 251 dependsOnDOM: true, |
| 253 | 252 |
| 254 get dependsOnStyles() | 253 get dependsOnStyles() |
| 255 { | 254 { |
| 256 return this._innerSelectors.some(selector => selector.dependsOnStyles); | 255 return this._innerSelectors.some(selector => selector.dependsOnStyles); |
| 257 }, | 256 }, |
| 258 | 257 |
| 259 get dependsOnCharacterData() | 258 get dependsOnCharacterData() |
| 260 { | 259 { |
| 261 return this._innerSelectors.some( | 260 return this._innerSelectors.some( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 303 } |
| 305 } | 304 } |
| 306 }; | 305 }; |
| 307 | 306 |
| 308 function ContainsSelector(textContent) | 307 function ContainsSelector(textContent) |
| 309 { | 308 { |
| 310 this._regexp = makeRegExpParameter(textContent); | 309 this._regexp = makeRegExpParameter(textContent); |
| 311 } | 310 } |
| 312 | 311 |
| 313 ContainsSelector.prototype = { | 312 ContainsSelector.prototype = { |
| 314 requiresHiding: true, | |
| 315 dependsOnDOM: true, | 313 dependsOnDOM: true, |
| 316 dependsOnCharacterData: true, | 314 dependsOnCharacterData: true, |
| 317 | 315 |
| 318 *getSelectors(prefix, subtree, styles) | 316 *getSelectors(prefix, subtree, styles) |
| 319 { | 317 { |
| 320 for (let element of this.getElements(prefix, subtree, styles)) | 318 for (let element of this.getElements(prefix, subtree, styles)) |
| 321 yield [makeSelector(element), subtree]; | 319 yield [makeSelector(element), subtree]; |
| 322 }, | 320 }, |
| 323 | 321 |
| 324 *getElements(prefix, subtree, styles) | 322 *getElements(prefix, subtree, styles) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 regexpString = propertyExpression.slice(1, -1) | 360 regexpString = propertyExpression.slice(1, -1) |
| 363 .replace("\\7B ", "{").replace("\\7D ", "}"); | 361 .replace("\\7B ", "{").replace("\\7D ", "}"); |
| 364 } | 362 } |
| 365 else | 363 else |
| 366 regexpString = filterToRegExp(propertyExpression); | 364 regexpString = filterToRegExp(propertyExpression); |
| 367 | 365 |
| 368 this._regexp = new RegExp(regexpString, "i"); | 366 this._regexp = new RegExp(regexpString, "i"); |
| 369 } | 367 } |
| 370 | 368 |
| 371 PropsSelector.prototype = { | 369 PropsSelector.prototype = { |
| 372 preferHideWithSelector: true, | |
| 373 dependsOnStyles: true, | 370 dependsOnStyles: true, |
| 374 | 371 |
| 375 *findPropsSelectors(styles, prefix, regexp) | 372 *findPropsSelectors(styles, prefix, regexp) |
| 376 { | 373 { |
| 377 for (let style of styles) | 374 for (let style of styles) |
| 378 if (regexp.test(style.style)) | 375 if (regexp.test(style.style)) |
| 379 for (let subSelector of style.subSelectors) | 376 for (let subSelector of style.subSelectors) |
| 380 { | 377 { |
| 381 if (subSelector.startsWith("*") && | 378 if (subSelector.startsWith("*") && |
| 382 !incompletePrefixRegexp.test(prefix)) | 379 !incompletePrefixRegexp.test(prefix)) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 397 } | 394 } |
| 398 }; | 395 }; |
| 399 | 396 |
| 400 function Pattern(selectors, text) | 397 function Pattern(selectors, text) |
| 401 { | 398 { |
| 402 this.selectors = selectors; | 399 this.selectors = selectors; |
| 403 this.text = text; | 400 this.text = text; |
| 404 } | 401 } |
| 405 | 402 |
| 406 Pattern.prototype = { | 403 Pattern.prototype = { |
| 407 isSelectorHidingOnlyPattern() | |
| 408 { | |
| 409 return getCachedPropertyValue( | |
| 410 this, "_selectorHidingOnlyPattern", | |
| 411 () => this.selectors.some(selector => selector.preferHideWithSelector) && | |
| 412 !this.selectors.some(selector => selector.requiresHiding) | |
| 413 ); | |
| 414 }, | |
| 415 | |
| 416 get dependsOnStyles() | 404 get dependsOnStyles() |
| 417 { | 405 { |
| 418 return getCachedPropertyValue( | 406 return getCachedPropertyValue( |
| 419 this, "_dependsOnStyles", | 407 this, "_dependsOnStyles", |
| 420 () => this.selectors.some(selector => selector.dependsOnStyles) | 408 () => this.selectors.some(selector => selector.dependsOnStyles) |
| 421 ); | 409 ); |
| 422 }, | 410 }, |
| 423 | 411 |
| 424 get dependsOnDOM() | 412 get dependsOnDOM() |
| 425 { | 413 { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 657 |
| 670 pattern = patterns.shift(); | 658 pattern = patterns.shift(); |
| 671 | 659 |
| 672 generator = evaluate(pattern.selectors, 0, "", | 660 generator = evaluate(pattern.selectors, 0, "", |
| 673 this.document, cssStyles); | 661 this.document, cssStyles); |
| 674 } | 662 } |
| 675 for (let selector of generator) | 663 for (let selector of generator) |
| 676 { | 664 { |
| 677 if (selector != null) | 665 if (selector != null) |
| 678 { | 666 { |
| 679 if (!this.useInlineStyles || | 667 if (!this.useInlineStyles) |
| 680 pattern.isSelectorHidingOnlyPattern()) | |
| 681 { | 668 { |
| 682 selectors.push(selector); | 669 selectors.push(selector); |
| 683 selectorFilters.push(pattern.text); | 670 selectorFilters.push(pattern.text); |
| 684 } | 671 } |
| 685 else | 672 else |
| 686 { | 673 { |
| 687 for (let element of this.document.querySelectorAll(selector)) | 674 for (let element of this.document.querySelectorAll(selector)) |
| 688 { | 675 { |
| 689 elements.push(element); | 676 elements.push(element); |
| 690 elementFilters.push(pattern.text); | 677 elementFilters.push(pattern.text); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 characterData: shouldObserveCharacterData(this.patterns), | 822 characterData: shouldObserveCharacterData(this.patterns), |
| 836 subtree: true | 823 subtree: true |
| 837 } | 824 } |
| 838 ); | 825 ); |
| 839 this.document.addEventListener("load", this.onLoad.bind(this), true); | 826 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 840 } | 827 } |
| 841 } | 828 } |
| 842 }; | 829 }; |
| 843 | 830 |
| 844 exports.ElemHideEmulation = ElemHideEmulation; | 831 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |