summaryrefslogtreecommitdiff
path: root/common/storage_raw.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage_raw.js')
-rw-r--r--common/storage_raw.js33
1 files changed, 13 insertions, 20 deletions
diff --git a/common/storage_raw.js b/common/storage_raw.js
index c79fe84..4009f13 100644
--- a/common/storage_raw.js
+++ b/common/storage_raw.js
@@ -41,23 +41,20 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT TYPE_PREFIX
- * IMPORT browser
- * IMPORT is_chrome
- * IMPORTS_END
- */
+#FROM common/browser.js IMPORT browser
+#FROM common/stored_types.js IMPORT TYPE_PREFIX
async function get(key)
{
- /* Fix for fact that Chrome does not use promises here */
- const promise = is_chrome ?
- new Promise(resolve => chrome.storage.local.get(key, resolve)) :
- browser.storage.local.get(key);
+#IF CHROMIUM
+ const promise = new Promise(cb => browser.storage.local.get(key, cb));
+#ELIF MOZILLA
+ const promise = browser.storage.local.get(key);
+#ENDIF
return (await promise)[key];
}
+#EXPORT get
async function set(key_or_object, value)
{
@@ -65,25 +62,21 @@ async function set(key_or_object, value)
key_or_object : {[key_or_object]: value};
return browser.storage.local.set(arg);
}
+#EXPORT set
async function set_var(name, value)
{
return set(TYPE_PREFIX.VAR + name, value);
}
+#EXPORT set_var
async function get_var(name)
{
return get(TYPE_PREFIX.VAR + name);
}
+#EXPORT get_var
const on_changed = browser.storage.onChanged || browser.storage.local.onChanged;
-const listen = cb => on_changed.addListener(cb);
-const no_listen = cb => on_changed.removeListener(cb);
-
-const raw_storage = {get, set, get_var, set_var, listen, no_listen};
-/*
- * EXPORTS_START
- * EXPORT raw_storage
- * EXPORTS_END
- */
+#EXPORT cb => on_changed.addListener(cb) AS listen
+#EXPORT cb => on_changed.removeListener(cb) AS no_listen