summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-08-04 22:01:01 +0200
committerWojtek Kosior <koszko@koszko.org>2021-08-04 22:01:01 +0200
commit5957fbeeb47bb2c519d34ae4d2eada2433dd1e09 (patch)
treef4e3892cc36937e486075ace69c2d3b7dd26f842 /common
parent2fa41a54acfa5e25b5ccad5b3c91210cc42ce00d (diff)
downloadbrowser-extension-5957fbeeb47bb2c519d34ae4d2eada2433dd1e09.tar.gz
browser-extension-5957fbeeb47bb2c519d34ae4d2eada2433dd1e09.zip
make settings_query.js use storage object passed as an argument
Diffstat (limited to 'common')
-rw-r--r--common/settings_query.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/common/settings_query.js b/common/settings_query.js
new file mode 100644
index 0000000..e85ae63
--- /dev/null
+++ b/common/settings_query.js
@@ -0,0 +1,52 @@
+/**
+ * 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 TYPE_PREFIX
+ * IMPORT for_each_possible_pattern
+ * IMPORTS_END
+ */
+
+function check_pattern(storage, 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(storage, url, multiple)
+{
+ const matched = [];
+ const cb = p => check_pattern(storage, p, multiple, matched);
+ for_each_possible_pattern(url, cb);
+
+ return multiple ? matched : (matched[0] || [undefined, undefined]);
+}
+
+function query_best(storage, url)
+{
+ return query(storage, url, false);
+}
+
+function query_all(storage, url)
+{
+ return query(storage, url, true);
+}
+
+/*
+ * EXPORTS_START
+ * EXPORT query_best
+ * EXPORT query_all
+ * EXPORTS_END
+ */