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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 { | 475 { |
476 // Sitekeys are case-sensitive so we shouldn't convert them to | 476 // Sitekeys are case-sensitive so we shouldn't convert them to |
477 // upper-case to avoid false positives here. Instead we need to | 477 // upper-case to avoid false positives here. Instead we need to |
478 // change the way filter options are parsed. | 478 // change the way filter options are parsed. |
479 if (this.sitekeys && | 479 if (this.sitekeys && |
480 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) | 480 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) |
481 { | 481 { |
482 return false; | 482 return false; |
483 } | 483 } |
484 | 484 |
| 485 let {domains} = this; |
| 486 |
485 // If no domains are set the rule matches everywhere | 487 // If no domains are set the rule matches everywhere |
486 if (!this.domains) | 488 if (!domains) |
487 return true; | 489 return true; |
488 | 490 |
489 // If the document has no host name, match only if the filter | 491 // If the document has no host name, match only if the filter |
490 // isn't restricted to specific domains | 492 // isn't restricted to specific domains |
491 if (!docDomain) | 493 if (!docDomain) |
492 return this.domains.get(""); | 494 return domains.get(""); |
493 | 495 |
494 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); | 496 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); |
495 | 497 |
496 while (true) | 498 while (true) |
497 { | 499 { |
498 let isDomainIncluded = this.domains.get(docDomain); | 500 let isDomainIncluded = domains.get(docDomain); |
499 if (typeof isDomainIncluded != "undefined") | 501 if (typeof isDomainIncluded != "undefined") |
500 return isDomainIncluded; | 502 return isDomainIncluded; |
501 | 503 |
502 let nextDot = docDomain.indexOf("."); | 504 let nextDot = docDomain.indexOf("."); |
503 if (nextDot < 0) | 505 if (nextDot < 0) |
504 break; | 506 break; |
505 docDomain = docDomain.substr(nextDot + 1); | 507 docDomain = docDomain.substr(nextDot + 1); |
506 } | 508 } |
507 return this.domains.get(""); | 509 return domains.get(""); |
508 }, | 510 }, |
509 | 511 |
510 /** | 512 /** |
511 * Checks whether this filter is active only on a domain and its subdomains. | 513 * Checks whether this filter is active only on a domain and its subdomains. |
512 * @param {string} docDomain | 514 * @param {string} docDomain |
513 * @return {boolean} | 515 * @return {boolean} |
514 */ | 516 */ |
515 isActiveOnlyOnDomain(docDomain) | 517 isActiveOnlyOnDomain(docDomain) |
516 { | 518 { |
517 if (!docDomain || !this.domains || this.domains.get("")) | 519 let {domains} = this; |
| 520 |
| 521 if (!docDomain || !domains || domains.get("")) |
518 return false; | 522 return false; |
519 | 523 |
520 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); | 524 docDomain = docDomain.replace(/\.+$/, "").toLowerCase(); |
521 | 525 |
522 for (let [domain, isIncluded] of this.domains) | 526 for (let [domain, isIncluded] of domains) |
523 { | 527 { |
524 if (isIncluded && domain != docDomain) | 528 if (isIncluded && domain != docDomain) |
525 { | 529 { |
526 if (domain.length <= docDomain.length) | 530 if (domain.length <= docDomain.length) |
527 return false; | 531 return false; |
528 | 532 |
529 if (!domain.endsWith("." + docDomain)) | 533 if (!domain.endsWith("." + docDomain)) |
530 return false; | 534 return false; |
531 } | 535 } |
532 } | 536 } |
533 | 537 |
534 return true; | 538 return true; |
535 }, | 539 }, |
536 | 540 |
537 /** | 541 /** |
538 * Checks whether this filter is generic or specific | 542 * Checks whether this filter is generic or specific |
539 * @return {boolean} | 543 * @return {boolean} |
540 */ | 544 */ |
541 isGeneric() | 545 isGeneric() |
542 { | 546 { |
543 return !(this.sitekeys && this.sitekeys.length) && | 547 let {sitekeys, domains} = this; |
544 (!this.domains || this.domains.get("")); | 548 |
| 549 return !(sitekeys && sitekeys.length) && (!domains || domains.get("")); |
545 }, | 550 }, |
546 | 551 |
547 /** | 552 /** |
548 * See Filter.serialize() | 553 * See Filter.serialize() |
549 * @inheritdoc | 554 * @inheritdoc |
550 */ | 555 */ |
551 serialize(buffer) | 556 serialize(buffer) |
552 { | 557 { |
553 if (this._disabled || this._hitCount || this._lastHit) | 558 if (this._disabled || this._hitCount || this._lastHit) |
554 { | 559 { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 | 1172 |
1168 /** | 1173 /** |
1169 * Script that should be executed | 1174 * Script that should be executed |
1170 * @type {string} | 1175 * @type {string} |
1171 */ | 1176 */ |
1172 get script() | 1177 get script() |
1173 { | 1178 { |
1174 return this.body; | 1179 return this.body; |
1175 } | 1180 } |
1176 }); | 1181 }); |
OLD | NEW |