From cbe12928f46fbea07364f46d0b15497e97ff4207 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 22 Mar 2019 21:20:05 -0300 Subject: "Disable everywhere for now" setting --- extension/background.js | 26 ++++++++++++++++---------- extension/popup/index.html | 2 ++ extension/popup/main.js | 26 ++++++++++++++++++++------ extension/popup/style.css | 2 +- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/extension/background.js b/extension/background.js index 9b7db26..eedbb73 100644 --- a/extension/background.js +++ b/extension/background.js @@ -26,14 +26,20 @@ port.onDisconnect.addListener(() => { }); browser.runtime.onMessage.addListener(({hostname}) => { - browser.storage.sync.get('siteSettings').then(({siteSettings}) => { - const mode = siteSettings[hostname]; - - if (mode) { - console.log('BGM:', mode); - port.postMessage(mode.map(track => ({track, volume: 100}))); - } else { - console.log('No BGM found for ' + hostname); - } - }); + browser.storage.sync.get(['siteSettings', 'disableEverywhere']) + .then(({siteSettings, disableEverywhere}) => { + if (disableEverywhere) { + port.postMessage([]); + return; + } + + const mode = siteSettings[hostname]; + + if (mode) { + console.log('BGM:', mode); + port.postMessage(mode.map(track => ({track, volume: 100}))); + } else { + console.log('No BGM found for ' + hostname); + } + }); }); diff --git a/extension/popup/index.html b/extension/popup/index.html index 9ddbec4..7a9e920 100644 --- a/extension/popup/index.html +++ b/extension/popup/index.html @@ -13,6 +13,8 @@

Tracks

+

General Settings

+

Sorry, this page doesn't appear to have a hostname. We can't configure music here.

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) ]) diff --git a/extension/popup/style.css b/extension/popup/style.css index 147a94e..d4ac7b2 100644 --- a/extension/popup/style.css +++ b/extension/popup/style.css @@ -31,7 +31,7 @@ input, button { margin-left: 4px; } -ul { +ul, p { margin: 4px 0; } -- cgit 1.3.0-6-gf8a5