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/settings_query.js | |
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/settings_query.js')
-rw-r--r-- | background/settings_query.js | 65 |
1 files changed, 0 insertions, 65 deletions
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 - */ |