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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 if (suffix == null) | 344 if (suffix == null) |
345 return null; | 345 return null; |
346 | 346 |
347 selectors.push(...suffix); | 347 selectors.push(...suffix); |
348 | 348 |
349 return selectors; | 349 return selectors; |
350 }, | 350 }, |
351 | 351 |
352 _lastInvocation: 0, | 352 _lastInvocation: 0, |
353 | 353 |
354 /** | |
355 * Processes the current document and applies all rules to it. | |
356 * @param {CSSStyleSheet[]} [stylesheets] | |
357 * The list of new stylesheets that have been added to the document and | |
358 * made reprocessing necessary. This parameter shouldn't be passed in for | |
359 * the initial processing, all of document's stylesheets will be considered | |
360 * then and all rules, including the ones not dependent on styles. | |
361 */ | |
354 addSelectors(stylesheets) | 362 addSelectors(stylesheets) |
kzar
2017/07/10 14:50:17
Nit: IMO this function could do with a comment to
Wladimir Palant
2017/07/11 08:18:11
Done.
kzar
2017/07/11 11:05:14
Nice, thanks.
| |
355 { | 363 { |
356 this._lastInvocation = Date.now(); | 364 this._lastInvocation = Date.now(); |
357 | 365 |
358 let selectors = []; | 366 let selectors = []; |
359 let selectorFilters = []; | 367 let selectorFilters = []; |
360 | 368 |
361 let elements = []; | 369 let elements = []; |
362 let elementFilters = []; | 370 let elementFilters = []; |
363 | 371 |
364 let cssStyles = []; | 372 let cssStyles = []; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 if (stylesheet) | 436 if (stylesheet) |
429 { | 437 { |
430 if (!this._stylesheetQueue && | 438 if (!this._stylesheetQueue && |
431 Date.now() - this._lastInvocation < MIN_INVOCATION_INTERVAL) | 439 Date.now() - this._lastInvocation < MIN_INVOCATION_INTERVAL) |
432 { | 440 { |
433 this._stylesheetQueue = []; | 441 this._stylesheetQueue = []; |
434 this.window.setTimeout(() => | 442 this.window.setTimeout(() => |
435 { | 443 { |
436 let stylesheets = this._stylesheetQueue; | 444 let stylesheets = this._stylesheetQueue; |
437 this._stylesheetQueue = null; | 445 this._stylesheetQueue = null; |
438 this.addSelectors(stylesheets); | 446 this.addSelectors(stylesheets); |
Felix Dahlke
2017/07/10 14:37:19
Nit: I'm probably rusty, but couldn't the above th
Wladimir Palant
2017/07/10 14:38:52
The trouble here is reentrance - if addSelector()
Felix Dahlke
2017/07/10 14:52:14
Makes sense.
| |
439 }, MIN_INVOCATION_INTERVAL - (Date.now() - this._lastInvocation)); | 447 }, MIN_INVOCATION_INTERVAL - (Date.now() - this._lastInvocation)); |
440 } | 448 } |
441 | 449 |
442 if (this._stylesheetQueue) | 450 if (this._stylesheetQueue) |
443 this._stylesheetQueue.push(stylesheet); | 451 this._stylesheetQueue.push(stylesheet); |
444 else | 452 else |
445 this.addSelectors([stylesheet]); | 453 this.addSelectors([stylesheet]); |
446 } | 454 } |
447 }, | 455 }, |
448 | 456 |
(...skipping 11 matching lines...) Expand all Loading... | |
460 | 468 |
461 if (this.patterns.length > 0) | 469 if (this.patterns.length > 0) |
462 { | 470 { |
463 let {document} = this.window; | 471 let {document} = this.window; |
464 this.addSelectors(); | 472 this.addSelectors(); |
465 document.addEventListener("load", this.onLoad.bind(this), true); | 473 document.addEventListener("load", this.onLoad.bind(this), true); |
466 } | 474 } |
467 }); | 475 }); |
468 } | 476 } |
469 }; | 477 }; |
LEFT | RIGHT |