diff options
author | hackademix <giorgio@maone.net> | 2018-07-30 16:18:17 +0200 |
---|---|---|
committer | hackademix <giorgio@maone.net> | 2018-07-30 16:18:17 +0200 |
commit | 5e0ab1515ab1c399a6405f579c3b931563e4020d (patch) | |
tree | d163af155124b72fe3dc4c326d998bd6b2e2361a /bg/Storage.js | |
parent | 096cd90010b093e7c211f3318cbe41711ecfdef9 (diff) |
Implement early whitelisting / blacklisting logic.
Diffstat (limited to 'bg/Storage.js')
-rw-r--r-- | bg/Storage.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/bg/Storage.js b/bg/Storage.js index 1386538..ecdc9e4 100644 --- a/bg/Storage.js +++ b/bg/Storage.js @@ -58,14 +58,35 @@ class ListStore { this.items = new Set(); } + static hashItem(hash) { + return hash.startsWith("(") ? hash : `(${hash})`; + } + static urlItem(url) { + let queryPos = url.indexOf("?"); + return queryPos === -1 ? url : url.substring(0, queryPos); + } + static siteItem(url) { + if (url.endsWith("/*")) return url; + try { + return `${new URL(url).origin}/*`; + } catch (e) { + return `${url}/*`; + } + } + async save() { return await this.storage.save(this.key, this.items); } async load() { - return await this.storage.load(this.key); + try { + this.items = await this.storage.load(this.key); + } catch (e) { + console.error(e); + } + return this.items; } - + async store(item) { let size = this.items.size; return (size !== this.items.add(item).size) && await this.save(); @@ -74,6 +95,10 @@ class ListStore { async remove(item) { return this.items.delete(item) && await this.save(); } + + contains(item) { + return this.items.has(item); + } } module.exports = { ListStore, Storage }; |