summaryrefslogtreecommitdiff
path: root/popup/popup.js
diff options
context:
space:
mode:
authorFrostyBiscuit <[email protected]>2025-02-16 13:04:17 +0100
committerFrostyBiscuit <[email protected]>2025-02-16 13:04:17 +0100
commitd0e4dcc6ef057f4c680838d4f8ac8e099a166225 (patch)
tree103aae098272bee55b337e53e7436864a9cb8770 /popup/popup.js
Initial push with version 0.1.1
Diffstat (limited to 'popup/popup.js')
-rw-r--r--popup/popup.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/popup/popup.js b/popup/popup.js
new file mode 100644
index 0000000..7824efb
--- /dev/null
+++ b/popup/popup.js
@@ -0,0 +1,51 @@
+new class ExtensionPopup {
+ BROWSER_STORAGE_KEY = "transparentZenSettings";
+ browserStorageSettings = {};
+ extensionSettingsForm = document.getElementById("extension-settings");
+
+ constructor() {
+ this.loadSettings().then((settings) => {
+ if (settings) {
+ this.browserStorageSettings = settings;
+ this.restoreSettings();
+ this.bindEvents();
+ }
+ });
+ }
+
+ bindEvents() {
+ this.extensionSettingsForm.querySelectorAll("input").forEach((input) => {
+ input.addEventListener("change", () => {
+ this.saveSettings();
+ })
+ });
+ }
+
+ restoreSettings() {
+ if (this.extensionSettingsForm?.elements) {
+ for (const element of this.extensionSettingsForm.elements) {
+ if (this.browserStorageSettings[element.name]) {
+ element.checked = JSON.parse(this.browserStorageSettings[element.name]);
+ }
+ }
+ }
+ }
+
+ async loadSettings() {
+ const settings = await browser.storage.local.get(this.BROWSER_STORAGE_KEY);
+ console.info("Settings loaded", settings?.[this.BROWSER_STORAGE_KEY]);
+ return settings?.[this.BROWSER_STORAGE_KEY] || {};
+ }
+
+ saveSettings() {
+ if (this.extensionSettingsForm?.elements) {
+ for (const element of this.extensionSettingsForm.elements) {
+ this.browserStorageSettings[element.name] = element.checked;
+ }
+
+ browser.storage.local.set({[this.BROWSER_STORAGE_KEY]: this.browserStorageSettings});
+ browser.runtime.sendMessage({ action: "updateSettings" });
+ console.info("Settings saved", this.browserStorageSettings);
+ }
+ }
+} \ No newline at end of file