| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 const {filterToRegExp, splitSelector} = require("common"); | 20 const {filterToRegExp, splitSelector} = require("common"); |
| 21 | 21 |
| 22 let MIN_INVOCATION_INTERVAL = 3000; | |
| 22 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; | 23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; |
| 23 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; | 24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; |
| 24 | 25 |
| 25 /** Return position of node from parent. | 26 /** Return position of node from parent. |
| 26 * @param {Node} node the node to find the position of. | 27 * @param {Node} node the node to find the position of. |
| 27 * @return {number} One-based index like for :nth-child(), or 0 on error. | 28 * @return {number} One-based index like for :nth-child(), or 0 on error. |
| 28 */ | 29 */ |
| 29 function positionInParent(node) | 30 function positionInParent(node) |
| 30 { | 31 { |
| 31 let {children} = node.parentNode; | 32 let {children} = node.parentNode; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 return; | 495 return; |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 pattern = null; | 498 pattern = null; |
| 498 return processPatterns(); | 499 return processPatterns(); |
| 499 }; | 500 }; |
| 500 | 501 |
| 501 processPatterns(); | 502 processPatterns(); |
| 502 }, | 503 }, |
| 503 | 504 |
| 504 _MIN_INVOCATION_INTERVAL: 3000, | 505 // This property is only used in the tests |
| 505 | 506 // to shorten the invocation interval |
| 506 set _invocationInterval(interval) | 507 get MIN_INVOCATION_INTERVAL() |
| 507 { | 508 { |
| 508 this._MIN_INVOCATION_INTERVAL = interval; | 509 return MIN_INVOCATION_INTERVAL; |
| 509 if (this._lastInvocation < 0) | 510 }, |
| 510 this._lastInvocation = -interval; | 511 |
| 512 set MIN_INVOCATION_INTERVAL(interval) | |
| 513 { | |
| 514 MIN_INVOCATION_INTERVAL = interval; | |
| 511 }, | 515 }, |
|
Wladimir Palant
2017/08/25 07:44:58
You can have a setter without a getter but that's
hub
2017/08/25 13:48:12
Done.
| |
| 512 | 516 |
| 513 _filteringInProgress: false, | 517 _filteringInProgress: false, |
| 514 _lastInvocation: -this._MIN_INVOCATION_INTERVAL, | 518 _lastInvocation: -MIN_INVOCATION_INTERVAL, |
|
Wladimir Palant
2017/08/25 07:44:58
This assignment won't work, `this` isn't pointing
hub
2017/08/25 13:48:12
oops.
| |
| 515 _scheduledProcessing: null, | 519 _scheduledProcessing: null, |
| 516 | 520 |
| 517 /** | 521 /** |
| 518 * Re-run filtering either immediately or queued. | 522 * Re-run filtering either immediately or queued. |
| 519 * @param {CSSStyleSheet[]} [stylesheets] | 523 * @param {CSSStyleSheet[]} [stylesheets] |
| 520 * new stylesheets to be processed. This parameter should be omitted | 524 * new stylesheets to be processed. This parameter should be omitted |
| 521 * for DOM modification (full reprocessing required). | 525 * for DOM modification (full reprocessing required). |
| 522 */ | 526 */ |
| 523 queueFiltering(stylesheets) | 527 queueFiltering(stylesheets) |
| 524 { | 528 { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 539 if (!stylesheets) | 543 if (!stylesheets) |
| 540 this._scheduledProcessing.stylesheets = null; | 544 this._scheduledProcessing.stylesheets = null; |
| 541 else if (this._scheduledProcessing.stylesheets) | 545 else if (this._scheduledProcessing.stylesheets) |
| 542 this._scheduledProcessing.stylesheets.push(...stylesheets); | 546 this._scheduledProcessing.stylesheets.push(...stylesheets); |
| 543 } | 547 } |
| 544 else if (this._filteringInProgress) | 548 else if (this._filteringInProgress) |
| 545 { | 549 { |
| 546 this._scheduledProcessing = {stylesheets}; | 550 this._scheduledProcessing = {stylesheets}; |
| 547 } | 551 } |
| 548 else if (this.window.performance.now() - | 552 else if (this.window.performance.now() - |
| 549 this._lastInvocation < this._MIN_INVOCATION_INTERVAL) | 553 this._lastInvocation < MIN_INVOCATION_INTERVAL) |
| 550 { | 554 { |
| 551 this._scheduledProcessing = {stylesheets}; | 555 this._scheduledProcessing = {stylesheets}; |
| 552 this.window.setTimeout(() => | 556 this.window.setTimeout(() => |
| 553 { | 557 { |
| 554 let newStylesheets = this._scheduledProcessing.stylesheets; | 558 let newStylesheets = this._scheduledProcessing.stylesheets; |
| 555 this._filteringInProgress = true; | 559 this._filteringInProgress = true; |
| 556 this._scheduledProcessing = null; | 560 this._scheduledProcessing = null; |
| 557 this._addSelectors(newStylesheets, completion); | 561 this._addSelectors(newStylesheets, completion); |
| 558 }, | 562 }, |
| 559 this._MIN_INVOCATION_INTERVAL - | 563 MIN_INVOCATION_INTERVAL - |
| 560 (this.window.performance.now() - this._lastInvocation)); | 564 (this.window.performance.now() - this._lastInvocation)); |
| 561 } | 565 } |
| 562 else | 566 else |
| 563 { | 567 { |
| 564 this._filteringInProgress = true; | 568 this._filteringInProgress = true; |
| 565 this._addSelectors(stylesheets, completion); | 569 this._addSelectors(stylesheets, completion); |
| 566 } | 570 } |
| 567 }, | 571 }, |
| 568 | 572 |
| 569 onLoad(event) | 573 onLoad(event) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 subtree: true | 607 subtree: true |
| 604 } | 608 } |
| 605 ); | 609 ); |
| 606 document.addEventListener("load", this.onLoad.bind(this), true); | 610 document.addEventListener("load", this.onLoad.bind(this), true); |
| 607 } | 611 } |
| 608 }); | 612 }); |
| 609 } | 613 } |
| 610 }; | 614 }; |
| 611 | 615 |
| 612 exports.ElemHideEmulation = ElemHideEmulation; | 616 exports.ElemHideEmulation = ElemHideEmulation; |
| LEFT | RIGHT |