diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-08-04 22:01:01 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-08-04 22:01:01 +0200 |
commit | 5957fbeeb47bb2c519d34ae4d2eada2433dd1e09 (patch) | |
tree | f4e3892cc36937e486075ace69c2d3b7dd26f842 /background | |
parent | 2fa41a54acfa5e25b5ccad5b3c91210cc42ce00d (diff) | |
download | browser-extension-5957fbeeb47bb2c519d34ae4d2eada2433dd1e09.tar.gz browser-extension-5957fbeeb47bb2c519d34ae4d2eada2433dd1e09.zip |
make settings_query.js use storage object passed as an argument
Diffstat (limited to 'background')
-rw-r--r-- | background/page_actions_server.js | 6 | ||||
-rw-r--r-- | background/page_info_server.js | 6 | ||||
-rw-r--r-- | background/policy_injector.js | 6 | ||||
-rw-r--r-- | background/settings_query.js | 65 |
4 files changed, 6 insertions, 77 deletions
diff --git a/background/page_actions_server.js b/background/page_actions_server.js index a7a44c1..58a0073 100644 --- a/background/page_actions_server.js +++ b/background/page_actions_server.js @@ -13,18 +13,17 @@ * IMPORT browser * IMPORT listen_for_connection * IMPORT sha256 - * IMPORT get_query_best + * IMPORT query_best * IMPORT make_ajax_request * IMPORTS_END */ var storage; -var query_best; var handler; function send_actions(url, port) { - const [pattern, settings] = query_best(url); + const [pattern, settings] = query_best(storage, url); const repos = storage.get_all(TYPE_PREFIX.REPO); port.postMessage(["settings", [pattern, settings, repos]]); @@ -126,7 +125,6 @@ function new_connection(port) async function start_page_actions_server() { storage = await get_storage(); - query_best = await get_query_best(); listen_for_connection(CONNECTION_TYPE.PAGE_ACTIONS, new_connection); } diff --git a/background/page_info_server.js b/background/page_info_server.js index 6f02750..e915011 100644 --- a/background/page_info_server.js +++ b/background/page_info_server.js @@ -10,7 +10,7 @@ * IMPORTS_START * IMPORT listen_for_connection * IMPORT get_storage - * IMPORT get_query_all + * IMPORT query_all * IMPORT TYPE_PREFIX * IMPORT CONNECTION_TYPE * IMPORT url_matches @@ -18,7 +18,6 @@ */ var storage; -var query_all; function handle_change(connection_data, change) { @@ -37,7 +36,7 @@ async function handle_subscription(connection_data, message) } connection_data.subscribed.add(url); - connection_data.port.postMessage(["new_url", query_all(url)]); + connection_data.port.postMessage(["new_url", query_all(storage, url)]); } function new_connection(port) @@ -62,7 +61,6 @@ function new_connection(port) async function start_page_info_server() { storage = await get_storage(); - query_all = await get_query_all(); listen_for_connection(CONNECTION_TYPE.PAGE_INFO, new_connection); } diff --git a/background/policy_injector.js b/background/policy_injector.js index 01da094..b3d85e8 100644 --- a/background/policy_injector.js +++ b/background/policy_injector.js @@ -19,13 +19,12 @@ * IMPORT url_item * IMPORT url_extract_target * IMPORT sign_policy - * IMPORT get_query_best + * IMPORT query_best * IMPORT csp_rule * IMPORTS_END */ var storage; -var query_best; const csp_header_names = { "content-security-policy" : true, @@ -53,7 +52,7 @@ function url_inject(details) if (targets.policy) targets.target = ""; - let [pattern, settings] = query_best(targets.base_url); + let [pattern, settings] = query_best(storage, targets.base_url); /* Defaults */ if (!pattern) settings = {}; @@ -106,7 +105,6 @@ function headers_inject(details) async function start_policy_injector() { storage = await get_storage(); - query_best = await get_query_best(); let extra_opts = ["blocking", "responseHeaders"]; if (is_chrome) diff --git a/background/settings_query.js b/background/settings_query.js deleted file mode 100644 index d0d9511..0000000 --- a/background/settings_query.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Hachette querying page settings with regard to wildcard records - * - * Copyright (C) 2021 Wojtek Kosior - * Redistribution terms are gathered in the `copyright' file. - */ - -/* - * IMPORTS_START - * IMPORT make_once - * IMPORT get_storage - * IMPORT TYPE_PREFIX - * IMPORT for_each_possible_pattern - * IMPORTS_END - */ - -var storage; - -async function init(fun) -{ - storage = await get_storage(); - - return fun; -} - -function check_pattern(pattern, multiple, matched) -{ - const settings = storage.get(TYPE_PREFIX.PAGE, pattern); - - if (settings === undefined) - return; - - matched.push([pattern, settings]); - - if (!multiple) - return false; -} - -function query(url, multiple) -{ - const matched = []; - for_each_possible_pattern(url, p => check_pattern(p, multiple, matched)); - - return multiple ? matched : (matched[0] || [undefined, undefined]); -} - -function query_best(url) -{ - return query(url, false); -} - -function query_all(url) -{ - return query(url, true); -} - -const get_query_best = make_once(() => init(query_best)); -const get_query_all = make_once(() => init(query_all)); - -/* - * EXPORTS_START - * EXPORT get_query_best - * EXPORT get_query_all - * EXPORTS_END - */ |