Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/abp2blocklist.js

Issue 29439639: Issue 4329 - Add $generichide support (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created May 17, 2017, 3:33 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/abp2blocklist.js
===================================================================
--- a/lib/abp2blocklist.js
+++ b/lib/abp2blocklist.js
@@ -357,16 +357,17 @@
* @constructor
*/
exports.ContentBlockerList = function ()
{
this.requestFilters = [];
this.requestExceptions = [];
this.elemhideFilters = [];
this.elemhideExceptions = [];
+ this.generichideExceptions = [];
this.elemhideSelectorExceptions = new Map();
};
/**
* Add Adblock Plus filter to be converted
*
* @param {Filter} filter Filter to convert
*/
@@ -383,16 +384,18 @@
if (filter instanceof filterClasses.WhitelistFilter)
{
if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes))
this.requestExceptions.push(filter);
if (filter.contentType & typeMap.ELEMHIDE)
this.elemhideExceptions.push(filter);
+ else if (filter.contentType & typeMap.GENERICHIDE)
+ this.generichideExceptions.push(filter);
}
if (filter instanceof filterClasses.ElemHideFilter)
this.elemhideFilters.push(filter);
if (filter instanceof filterClasses.ElemHideException)
{
let domains = this.elemhideSelectorExceptions[filter.selector];
@@ -408,16 +411,21 @@
*
* @returns {Filter} filter Filter to convert
*/
ContentBlockerList.prototype.generateRules = function(filter)
{
let rules = [];
let groupedElemhideFilters = new Map();
+
+ // Make sure the generic element hiding filters are first in the map so they
+ // get generated first.
+ groupedElemhideFilters.set("^https?://", []);
Sebastian Noack 2017/05/17 06:37:10 I'm not sure if it is a good idea, to split up gen
+
for (let filter of this.elemhideFilters)
{
let result = convertElemHideFilter(filter, this.elemhideSelectorExceptions);
if (!result)
continue;
if (result.matchDomains.length == 0)
result.matchDomains = ["^https?://"];
@@ -442,16 +450,24 @@
rules.push({
trigger: {"url-filter": matchDomain,
"url-filter-is-case-sensitive": true},
action: {type: "css-display-none",
selector: selector}
});
}
+
+ if (matchDomain == "^https?://")
+ {
+ // Right after the generic element hiding filters, add the exceptions
+ // that should apply only to those filters.
+ for (let filter of this.generichideExceptions)
+ convertFilterAddRules(rules, filter, "ignore-previous-rules", false);
+ }
});
for (let filter of this.elemhideExceptions)
convertFilterAddRules(rules, filter, "ignore-previous-rules", false);
for (let filter of this.requestFilters)
convertFilterAddRules(rules, filter, "block", true);
for (let filter of this.requestExceptions)
convertFilterAddRules(rules, filter, "ignore-previous-rules", true);
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld