aboutsummaryrefslogtreecommitdiff
path: root/bg
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2019-03-26 22:45:37 +0100
committerhackademix <giorgio@maone.net>2019-03-26 22:45:37 +0100
commit9884643742b54b88f94111d62f5e89a12a60e604 (patch)
treef367f5b7aa7ae3b950c26a946b54b737e6014a5c /bg
parent55469c349c3c47c882ee21348ba67780c8291003 (diff)
Subdomain wildcard support.
Diffstat (limited to 'bg')
-rw-r--r--bg/ListManager.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/bg/ListManager.js b/bg/ListManager.js
index 2f5f74e..745e599 100644
--- a/bg/ListManager.js
+++ b/bg/ListManager.js
@@ -36,13 +36,13 @@ class ListManager {
}
async whitelist(...keys) {
- ListManager.move(this.lists.blacklist, this.lists.whitelist, ...keys);
+ await ListManager.move(this.lists.blacklist, this.lists.whitelist, ...keys);
}
async blacklist(...keys) {
- ListManager.move(this.lists.whitelist, this.lists.blacklist, ...keys);
+ await ListManager.move(this.lists.whitelist, this.lists.blacklist, ...keys);
}
async forget(...keys) {
- await Promise.all(Object.values(this.lists).map(l => l.remove(...keys)));
+ await Promise.all(Object.values(this.lists).map(async l => await l.remove(...keys)));
}
/* key is a string representing either a URL or an optional path
with a trailing (hash).
@@ -62,10 +62,11 @@ class ListManager {
if (!match) {
let url = ListStore.urlItem(key);
let site = ListStore.siteItem(key);
- return (blacklist.contains(url) || blacklist.contains(site))
+ return (blacklist.contains(url) || ListManager.siteMatch(site, blacklist)
? "blacklisted"
- : whitelist.contains(url) || whitelist.contains(site)
- ? "whitelisted" : defValue;
+ : whitelist.contains(url) || ListManager.siteMatch(site, whitelist)
+ ? "whitelisted" : defValue
+ );
}
let [hashItem, srcHash] = match; // (hash), hash
@@ -74,6 +75,28 @@ class ListManager {
? "whitelisted"
: defValue;
}
+
+ /*
+ Matches by whole site ("http://some.domain.com/*") supporting also
+ wildcarded subdomains ("https://*.domain.com/*").
+ */
+ static siteMatch(url, list) {
+ let site = ListStore.siteItem(url);
+ if (list.contains(site)) {
+ return site;
+ }
+ site = site.replace(/^([\w-]+:\/\/)?(\w)/, "$1*.$2");
+ for (;;) {
+ if (list.contains(site)) {
+ return site;
+ }
+ let oldKey = site;
+ site = site.replace(/(?:\*\.)*\w+(?=\.)/, "*");
+ if (site === oldKey) {
+ return null;
+ }
+ }
+ }
}
module.exports = { ListManager };