Index: lib/abp2blocklist.js |
=================================================================== |
--- a/lib/abp2blocklist.js |
+++ b/lib/abp2blocklist.js |
@@ -209,17 +209,18 @@ |
typeMap.OTHER)) |
types.push("raw"); |
if (filter.contentType & typeMap.SUBDOCUMENT) |
types.push("document"); |
return types; |
} |
-function convertFilterAddRules(rules, filter, action, withResourceTypes) |
+function convertFilterAddRules(rules, filter, action, withResourceTypes, |
+ exceptionDomains) |
{ |
let parsed = parseFilterRegexpSource(filter.regexpSource); |
// For the special case of $document whitelisting filters with just a domain |
// we can generate an equivalent blocking rule exception using if-domain. |
if (filter instanceof filterClasses.WhitelistFilter && |
filter.contentType & typeMap.DOCUMENT && |
parsed.justHostname) |
@@ -247,17 +248,17 @@ |
// a lowercase string unless the matchCase option was passed. |
if (parsed.canSafelyMatchAsLowercase && !filter.matchCase) |
trigger["url-filter"] = trigger["url-filter"].toLowerCase(); |
if (parsed.canSafelyMatchAsLowercase || filter.matchCase) |
trigger["url-filter-is-case-sensitive"] = true; |
let included = []; |
- let excluded = []; |
+ let excluded = exceptionDomains || []; |
parseDomains(filter.domains, included, excluded); |
if (withResourceTypes) |
{ |
trigger["resource-type"] = getResourceTypes(filter); |
if (trigger["resource-type"].length == 0) |
@@ -357,16 +358,17 @@ |
* @constructor |
*/ |
exports.ContentBlockerList = function () |
{ |
this.requestFilters = []; |
this.requestExceptions = []; |
this.elemhideFilters = []; |
this.elemhideExceptions = []; |
+ this.genericblockExceptions = []; |
this.elemhideSelectorExceptions = new Map(); |
}; |
/** |
* Add Adblock Plus filter to be converted |
* |
* @param {Filter} filter Filter to convert |
*/ |
@@ -383,16 +385,19 @@ |
if (filter instanceof filterClasses.WhitelistFilter) |
{ |
if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) |
this.requestExceptions.push(filter); |
if (filter.contentType & typeMap.ELEMHIDE) |
this.elemhideExceptions.push(filter); |
+ |
+ if (filter.contentType & typeMap.GENERICBLOCK) |
+ this.genericblockExceptions.push(filter); |
} |
if (filter instanceof filterClasses.ElemHideFilter) |
this.elemhideFilters.push(filter); |
if (filter instanceof filterClasses.ElemHideException) |
{ |
let domains = this.elemhideSelectorExceptions[filter.selector]; |
@@ -446,15 +451,28 @@ |
action: {type: "css-display-none", |
selector: selector} |
}); |
} |
}); |
for (let filter of this.elemhideExceptions) |
convertFilterAddRules(rules, filter, "ignore-previous-rules", false); |
+ |
+ let requestFilterExceptionDomains = []; |
+ for (let filter of this.genericblockExceptions) |
+ { |
+ let parsed = parseFilterRegexpSource(filter.regexpSource); |
+ if (parsed.hostname) |
+ requestFilterExceptionDomains.push(parsed.hostname); |
+ } |
+ |
for (let filter of this.requestFilters) |
- convertFilterAddRules(rules, filter, "block", true); |
+ { |
+ convertFilterAddRules(rules, filter, "block", true, |
+ requestFilterExceptionDomains); |
+ } |
+ |
for (let filter of this.requestExceptions) |
convertFilterAddRules(rules, filter, "ignore-previous-rules", true); |
return rules.filter(rule => !hasNonASCI(rule)); |
}; |