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-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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 * Create a new Adblock Plus filter to content blocker list converter | 355 * Create a new Adblock Plus filter to content blocker list converter |
356 * | 356 * |
357 * @constructor | 357 * @constructor |
358 */ | 358 */ |
359 exports.ContentBlockerList = function () | 359 exports.ContentBlockerList = function () |
360 { | 360 { |
361 this.requestFilters = []; | 361 this.requestFilters = []; |
362 this.requestExceptions = []; | 362 this.requestExceptions = []; |
363 this.elemhideFilters = []; | 363 this.elemhideFilters = []; |
364 this.elemhideExceptions = []; | 364 this.elemhideExceptions = []; |
| 365 this.generichideExceptions = []; |
365 this.elemhideSelectorExceptions = new Map(); | 366 this.elemhideSelectorExceptions = new Map(); |
366 }; | 367 }; |
367 | 368 |
368 /** | 369 /** |
369 * Add Adblock Plus filter to be converted | 370 * Add Adblock Plus filter to be converted |
370 * | 371 * |
371 * @param {Filter} filter Filter to convert | 372 * @param {Filter} filter Filter to convert |
372 */ | 373 */ |
373 ContentBlockerList.prototype.addFilter = function(filter) | 374 ContentBlockerList.prototype.addFilter = function(filter) |
374 { | 375 { |
375 if (filter.sitekeys) | 376 if (filter.sitekeys) |
376 return; | 377 return; |
377 if (filter instanceof filterClasses.RegExpFilter && | 378 if (filter instanceof filterClasses.RegExpFilter && |
378 filter.regexpSource == null) | 379 filter.regexpSource == null) |
379 return; | 380 return; |
380 | 381 |
381 if (filter instanceof filterClasses.BlockingFilter) | 382 if (filter instanceof filterClasses.BlockingFilter) |
382 this.requestFilters.push(filter); | 383 this.requestFilters.push(filter); |
383 | 384 |
384 if (filter instanceof filterClasses.WhitelistFilter) | 385 if (filter instanceof filterClasses.WhitelistFilter) |
385 { | 386 { |
386 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) | 387 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) |
387 this.requestExceptions.push(filter); | 388 this.requestExceptions.push(filter); |
388 | 389 |
389 if (filter.contentType & typeMap.ELEMHIDE) | 390 if (filter.contentType & typeMap.ELEMHIDE) |
390 this.elemhideExceptions.push(filter); | 391 this.elemhideExceptions.push(filter); |
| 392 else if (filter.contentType & typeMap.GENERICHIDE) |
| 393 this.generichideExceptions.push(filter); |
391 } | 394 } |
392 | 395 |
393 if (filter instanceof filterClasses.ElemHideFilter) | 396 if (filter instanceof filterClasses.ElemHideFilter) |
394 this.elemhideFilters.push(filter); | 397 this.elemhideFilters.push(filter); |
395 | 398 |
396 if (filter instanceof filterClasses.ElemHideException) | 399 if (filter instanceof filterClasses.ElemHideException) |
397 { | 400 { |
398 let domains = this.elemhideSelectorExceptions[filter.selector]; | 401 let domains = this.elemhideSelectorExceptions[filter.selector]; |
399 if (!domains) | 402 if (!domains) |
400 domains = this.elemhideSelectorExceptions[filter.selector] = []; | 403 domains = this.elemhideSelectorExceptions[filter.selector] = []; |
401 | 404 |
402 parseDomains(filter.domains, domains, []); | 405 parseDomains(filter.domains, domains, []); |
403 } | 406 } |
404 }; | 407 }; |
405 | 408 |
406 /** | 409 /** |
407 * Generate content blocker list for all filters that were added | 410 * Generate content blocker list for all filters that were added |
408 * | 411 * |
409 * @returns {Filter} filter Filter to convert | 412 * @returns {Filter} filter Filter to convert |
410 */ | 413 */ |
411 ContentBlockerList.prototype.generateRules = function(filter) | 414 ContentBlockerList.prototype.generateRules = function(filter) |
412 { | 415 { |
413 let rules = []; | 416 let rules = []; |
414 | 417 |
415 let groupedElemhideFilters = new Map(); | 418 let groupedElemhideFilters = new Map(); |
| 419 |
| 420 // Make sure the generic element hiding filters are first in the map so they |
| 421 // get generated first. |
| 422 groupedElemhideFilters.set("^https?://", []); |
| 423 |
416 for (let filter of this.elemhideFilters) | 424 for (let filter of this.elemhideFilters) |
417 { | 425 { |
418 let result = convertElemHideFilter(filter, this.elemhideSelectorExceptions); | 426 let result = convertElemHideFilter(filter, this.elemhideSelectorExceptions); |
419 if (!result) | 427 if (!result) |
420 continue; | 428 continue; |
421 | 429 |
422 if (result.matchDomains.length == 0) | 430 if (result.matchDomains.length == 0) |
423 result.matchDomains = ["^https?://"]; | 431 result.matchDomains = ["^https?://"]; |
424 | 432 |
425 for (let matchDomain of result.matchDomains) | 433 for (let matchDomain of result.matchDomains) |
(...skipping 14 matching lines...) Expand all Loading... |
440 // this by converting to the attribute format [id="elementID"] | 448 // this by converting to the attribute format [id="elementID"] |
441 selector = convertIDSelectorsToAttributeSelectors(selector); | 449 selector = convertIDSelectorsToAttributeSelectors(selector); |
442 | 450 |
443 rules.push({ | 451 rules.push({ |
444 trigger: {"url-filter": matchDomain, | 452 trigger: {"url-filter": matchDomain, |
445 "url-filter-is-case-sensitive": true}, | 453 "url-filter-is-case-sensitive": true}, |
446 action: {type: "css-display-none", | 454 action: {type: "css-display-none", |
447 selector: selector} | 455 selector: selector} |
448 }); | 456 }); |
449 } | 457 } |
| 458 |
| 459 if (matchDomain == "^https?://") |
| 460 { |
| 461 // Right after the generic element hiding filters, add the exceptions |
| 462 // that should apply only to those filters. |
| 463 for (let filter of this.generichideExceptions) |
| 464 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); |
| 465 } |
450 }); | 466 }); |
451 | 467 |
452 for (let filter of this.elemhideExceptions) | 468 for (let filter of this.elemhideExceptions) |
453 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); | 469 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); |
454 for (let filter of this.requestFilters) | 470 for (let filter of this.requestFilters) |
455 convertFilterAddRules(rules, filter, "block", true); | 471 convertFilterAddRules(rules, filter, "block", true); |
456 for (let filter of this.requestExceptions) | 472 for (let filter of this.requestExceptions) |
457 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); | 473 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); |
458 | 474 |
459 return rules.filter(rule => !hasNonASCI(rule)); | 475 return rules.filter(rule => !hasNonASCI(rule)); |
460 }; | 476 }; |
OLD | NEW |