« get me outta code hell

interactive-bgm - Browser extension that adds background music based on the site you're browsing
about summary refs log tree commit diff
path: root/extension/popup/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'extension/popup/main.js')
-rw-r--r--extension/popup/main.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/extension/popup/main.js b/extension/popup/main.js
index ad1475a..6175e36 100644
--- a/extension/popup/main.js
+++ b/extension/popup/main.js
@@ -143,12 +143,26 @@ function loadTrackList(opts) {
 }
 
 Promise.all([
-    browser.tabs.query({active: true, currentWindow: true})
-        .then(([tab]) => {
-            const url = new URL(tab.url);
-            document.getElementById('hostname').appendChild(document.createTextNode(url.hostname));
-            return url.hostname;
-        }),
+    (async function() {
+        const [[tab], {disableEverywhere: disableEverywhereStatus}] = await Promise.all([
+            browser.tabs.query({active: true, currentWindow: true}),
+            browser.storage.sync.get('disableEverywhere')
+        ]);
+
+        const {hostname} = new URL(tab.url);
+        document.getElementById('hostname').appendChild(document.createTextNode(hostname));
+
+        const disableEverywhere = document.getElementById('disable-everywhere');
+
+        disableEverywhere.checked = disableEverywhereStatus;
+
+        disableEverywhere.addEventListener('click', () => {
+            browser.storage.sync.set({disableEverywhere: disableEverywhere.checked})
+                .then(() => browser.runtime.sendMessage({hostname}));
+        });
+
+        return hostname;
+    })(),
     browser.storage.sync.get('siteSettings')
         .then(({siteSettings = {}}) => siteSettings)
 ])