aboutsummaryrefslogtreecommitdiff
path: root/html/default_blocking_policy.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-09-02 18:35:49 +0200
committerWojtek Kosior <koszko@koszko.org>2021-09-02 18:35:49 +0200
commit6247f163d3ca89d5570450ac7ac8fd18f73bb74b (patch)
treee3d4817ae475e1f3553d3a50a77792fc5c3c25a0 /html/default_blocking_policy.js
parent4b59dced912fb9b50ff041c67f0f72cbbad56b6c (diff)
downloadbrowser-extension-6247f163d3ca89d5570450ac7ac8fd18f73bb74b.tar.gz
browser-extension-6247f163d3ca89d5570450ac7ac8fd18f73bb74b.zip
enable toggling of global script blocking policy\n\nThis commit also introduces `light_storage' module which is later going to replace the storage code we use right now.\nAlso included is a hack to properly display scrollbars under Mozilla (needs testing on newer Mozilla browsers).
Diffstat (limited to 'html/default_blocking_policy.js')
-rw-r--r--html/default_blocking_policy.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/html/default_blocking_policy.js b/html/default_blocking_policy.js
new file mode 100644
index 0000000..2f49bac
--- /dev/null
+++ b/html/default_blocking_policy.js
@@ -0,0 +1,47 @@
+/**
+ * part of Hachette
+ * Default policy dialog logic.
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+/*
+ * IMPORTS_START
+ * IMPORT by_id
+ * IMPORT light_storage
+ * IMPORT observables
+ * IMPORTS_END
+ */
+
+/*
+ * Used with `default_blocking_policy.html' to allow user to choose whether to
+ * block scripts globally or not.
+ */
+
+const blocking_policy_span = by_id("blocking_policy_span");
+const current_policy_span = by_id("current_policy_span");
+const toggle_policy_but = by_id("toggle_policy_but");
+
+let policy_observable;
+
+const update_policy =
+ allowed => current_policy_span.textContent = allowed ? "allow" : "block";
+const toggle_policy =
+ () => light_storage.set_var("default_allow", !policy_observable.value);
+
+async function init_default_policy_dialog()
+{
+ policy_observable = await light_storage.observe_var("default_allow");
+ update_policy(policy_observable.value);
+ observables.subscribe(policy_observable, update_policy);
+
+ toggle_policy_but.addEventListener("click", toggle_policy);
+ blocking_policy_span.classList.remove("hide");
+}
+
+/*
+ * EXPORTS_START
+ * EXPORT init_default_policy_dialog
+ * EXPORTS_END
+ */