diff options
author | Yuchen Pei <hi@ypei.me> | 2022-07-29 12:26:39 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-07-29 12:26:39 +1000 |
commit | 8806d891c0c6aeccacb3e4bc97a99fd9ec560f44 (patch) | |
tree | 540de0be744d04606a8c7cce3b5af0eb13cec28f | |
parent | a6d433a604cecbfc75859855e375057f1de332c0 (diff) |
clean up bg/ListManager.js
-rw-r--r-- | bg/ListManager.js | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/bg/ListManager.js b/bg/ListManager.js index 3020197..8106a25 100644 --- a/bg/ListManager.js +++ b/bg/ListManager.js @@ -23,7 +23,7 @@ A class to manage whitelist/blacklist operations */ -let { ListStore } = require('../common/Storage'); +const { ListStore } = require('../common/Storage'); class ListManager { constructor(whitelist, blacklist, builtInHashes) { @@ -49,8 +49,8 @@ class ListManager { Returns "blacklisted", "whitelisted" or defValue */ getStatus(key, defValue = 'unknown') { - let { blacklist, whitelist } = this.lists; - let inline = ListStore.inlineItem(key); + const { blacklist, whitelist } = this.lists; + const inline = ListStore.inlineItem(key); if (inline) { return blacklist.contains(inline) ? 'blacklisted' @@ -58,10 +58,10 @@ class ListManager { : defValue; } - let match = key.match(/\(([^)]+)\)(?=[^()]*$)/); + const match = key.match(/\(([^)]+)\)(?=[^()]*$)/); if (!match) { - let url = ListStore.urlItem(key); - let site = ListStore.siteItem(key); + const url = ListStore.urlItem(key); + const site = ListStore.siteItem(key); return (blacklist.contains(url) || ListManager.siteMatch(site, blacklist) ? 'blacklisted' : whitelist.contains(url) || ListManager.siteMatch(site, whitelist) @@ -69,7 +69,7 @@ class ListManager { ); } - let [hashItem, srcHash] = match; // (hash), hash + const [hashItem, srcHash] = match; // (hash), hash return blacklist.contains(hashItem) ? 'blacklisted' : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem) ? 'whitelisted' @@ -81,20 +81,14 @@ class ListManager { 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; - } + const site = ListStore.siteItem(url); + if (list.contains(site)) return site; + // TODO: get rid of let + for (let replaced = site.replace(/^([\w-]+:\/\/)?(\w)/, '$1*.$2'); ;) { + if (list.contains(replaced)) return replaced; + const oldKey = replaced; + replaced = replaced.replace(/(?:\*\.)*\w+(?=\.)/, '*'); + if (oldKey === replaced) return null; } } } |