aboutsummaryrefslogtreecommitdiff
path: root/bg/ListManager.js
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-04-07 12:17:38 +1000
committerYuchen Pei <hi@ypei.me>2022-04-07 12:17:38 +1000
commitae25ad78906179e1448ff7d97957810e2be40206 (patch)
treeca56b583f36ccd317900e6b51c4fcd86f161bc56 /bg/ListManager.js
parent52398eafaf99ebbba7ff5a28b832830be394bf1d (diff)
nop whitespace formatting change.
- ran eglot-format using typescript-language-server on all js files in the repo except those under /hash_script/ - verify only whitespace changed: git diff --word-diff-regex=. 62d6a71 62d6a71~1
Diffstat (limited to 'bg/ListManager.js')
-rw-r--r--bg/ListManager.js52
1 files changed, 26 insertions, 26 deletions
diff --git a/bg/ListManager.js b/bg/ListManager.js
index 745e599..f712356 100644
--- a/bg/ListManager.js
+++ b/bg/ListManager.js
@@ -23,11 +23,11 @@
A class to manage whitelist/blacklist operations
*/
-let {ListStore} = require("../common/Storage");
+let { ListStore } = require("../common/Storage");
class ListManager {
constructor(whitelist, blacklist, builtInHashes) {
- this.lists = {whitelist, blacklist};
+ this.lists = { whitelist, blacklist };
this.builtInHashes = new Set(builtInHashes);
}
@@ -49,13 +49,13 @@ class ListManager {
Returns "blacklisted", "whitelisted" or defValue
*/
getStatus(key, defValue = "unknown") {
- let {blacklist, whitelist} = this.lists;
+ let { blacklist, whitelist } = this.lists;
let inline = ListStore.inlineItem(key);
if (inline) {
return blacklist.contains(inline)
? "blacklisted"
: whitelist.contains(inline) ? "whitelisted"
- : defValue;
+ : defValue;
}
let match = key.match(/\(([^)]+)\)(?=[^()]*$)/);
@@ -65,38 +65,38 @@ class ListManager {
return (blacklist.contains(url) || ListManager.siteMatch(site, blacklist)
? "blacklisted"
: whitelist.contains(url) || ListManager.siteMatch(site, whitelist)
- ? "whitelisted" : defValue
+ ? "whitelisted" : defValue
);
}
- let [hashItem, srcHash] = match; // (hash), hash
- return blacklist.contains(hashItem) ? "blacklisted"
- : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem)
+ let [hashItem, srcHash] = match; // (hash), hash
+ return blacklist.contains(hashItem) ? "blacklisted"
+ : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem)
? "whitelisted"
- : defValue;
- }
+ : 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);
+ /*
+ 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;
}
- 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;
- }
+ let oldKey = site;
+ site = site.replace(/(?:\*\.)*\w+(?=\.)/, "*");
+ if (site === oldKey) {
+ return null;
}
}
+ }
}
module.exports = { ListManager };