diff options
author | hackademix <giorgio@maone.net> | 2018-09-13 00:23:24 +0200 |
---|---|---|
committer | hackademix <giorgio@maone.net> | 2018-09-13 15:47:27 +0200 |
commit | a2c93c2663d4f61b3c88d39f27fa492aca999455 (patch) | |
tree | 33a1f01c1f92e9e507aa7c67995bf4a97d77cfe2 /bg/ListManager.js | |
parent | 1eac93ab65df6963b464a780b92ff06651ba96d6 (diff) |
Support for batch async list operations.
Diffstat (limited to 'bg/ListManager.js')
-rw-r--r-- | bg/ListManager.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/bg/ListManager.js b/bg/ListManager.js index 34d9531..7284aca 100644 --- a/bg/ListManager.js +++ b/bg/ListManager.js @@ -30,20 +30,21 @@ class ListManager { this.lists = {whitelist, blacklist}; this.builtInHashes = new Set(builtInHashes); } - async whitelist(key) { - await this.lists.blacklist.remove(key); - await this.lists.whitelist.store(key); + + static async move(fromList, toList, ...keys) { + await Promise.all([fromList.remove(...keys), toList.store(...keys)]); } - async blacklist(key) { - await this.lists.whitelist.remove(key); - await this.lists.blacklist.store(key); + + async whitelist(...keys) { + ListManager.move(this.lists.blacklist, this.lists.whitelist, ...keys); } - async forget(key) { - for (let list of Object.values(this.lists)) { - await list.remove(key); - } + async blacklist(...keys) { + ListManager.move(this.lists.whitelist, this.lists.blacklist, ...keys); } - /* key is a string representing either a URL or an optional path + async forget(...keys) { + await Promise.all(Object.values(this.lists).map(l => l.remove(...keys))); + } + /* key is a string representing either a URL or an optional path with a trailing (hash). Returns "blacklisted", "whitelisted" or defValue */ @@ -53,16 +54,16 @@ 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) || blacklist.contains(site)) ? "blacklisted" - : whitelist.contains(url) || whitelist.contains(site) - ? "whitelisted" : defValue; + : whitelist.contains(url) || whitelist.contains(site) + ? "whitelisted" : defValue; } - + let [hashItem, srcHash] = match; // (hash), hash - + return blacklist.contains(hashItem) ? "blacklisted" - : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem) + : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem) ? "whitelisted" : defValue; } |