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

Unified Diff: lib/abp2blocklist.js

Issue 29441592: Issue 4329 - Add $genericblock support (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Add $genericblock domains after filter-specific exception domains Created May 20, 2017, 7:28 p.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
@@ -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)
@@ -251,16 +252,19 @@
if (parsed.canSafelyMatchAsLowercase || filter.matchCase)
trigger["url-filter-is-case-sensitive"] = true;
let included = [];
let excluded = [];
parseDomains(filter.domains, included, excluded);
+ if (exceptionDomains)
+ excluded = excluded.concat(exceptionDomains);
Sebastian Noack 2017/05/21 20:44:35 I wonder whether it would be better to avoid conca
Manish Jethani 2017/05/21 21:03:57 JSHydra does not support the spread operator. It's
+
if (withResourceTypes)
{
trigger["resource-type"] = getResourceTypes(filter);
if (trigger["resource-type"].length == 0)
return;
}
@@ -357,16 +361,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 +388,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 +454,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));
};
« 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