| Index: lib/abp2blocklist.js |
| =================================================================== |
| --- a/lib/abp2blocklist.js |
| +++ b/lib/abp2blocklist.js |
| @@ -59,16 +59,30 @@ |
| return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
| } |
| function matchDomain(domain) |
| { |
| return "^https?://([^/:]*\\.)?" + escapeRegExp(domain).toLowerCase() + "[/:]"; |
| } |
| +function findSubdomainsInList(domain, list) |
| +{ |
| + let subdomains = []; |
| + let suffixLength = domain.length + 1; |
| + |
| + for (let name of list) |
| + { |
| + if (name.length > suffixLength && name.slice(-suffixLength) == "." + domain) |
| + subdomains.push(name.slice(0, -suffixLength)); |
| + } |
| + |
| + return subdomains; |
| +} |
| + |
| function convertElemHideFilter(filter, elemhideSelectorExceptions) |
| { |
| let included = []; |
| let excluded = []; |
| let rules = []; |
| parseDomains(filter.domains, included, excluded); |
| @@ -263,19 +277,44 @@ |
| if (trigger["resource-type"].length == 0) |
| return; |
| } |
| if (filter.thirdParty != null) |
| trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; |
| if (included.length > 0) |
| - trigger["if-domain"] = included.map(name => "*" + name); |
| + { |
| + trigger["if-domain"] = []; |
| + |
| + for (let name of included) |
| + { |
| + // If this is a blocking filter or an element hiding filter, add the |
| + // subdomain wildcard only if no subdomains have been excluded. |
| + let notSubdomains = null; |
| + if ((filter instanceof filterClasses.BlockingFilter || |
| + filter instanceof filterClasses.ElemHideFilter) && |
| + (notSubdomains = findSubdomainsInList(name, excluded)).length > 0) |
| + { |
| + trigger["if-domain"].push(name); |
| + |
| + // Add the "www" prefix but only if it hasn't been excluded. |
| + if (!notSubdomains.includes("www")) |
| + trigger["if-domain"].push("www." + name); |
| + } |
| + else |
| + { |
| + trigger["if-domain"].push("*" + name); |
| + } |
| + } |
| + } |
| else if (excluded.length > 0) |
| + { |
| trigger["unless-domain"] = excluded.map(name => "*" + name); |
| + } |
| rules.push({trigger: trigger, action: {type: action}}); |
| } |
| function hasNonASCI(obj) |
| { |
| if (typeof obj == "string") |
| { |