diff --git a/background.js b/background.js index 8355107..114d2eb 100644 --- a/background.js +++ b/background.js @@ -89,12 +89,16 @@ browser.commands.onCommand.addListener(async function(command) { currentWindow: true, active: true }); - if (tabs?.length) { + if (tabs?.length && tabs[0].id != browser.tabs.TAB_ID_NONE) { const exclKey = 'excludeDefault', - res = await browser.storage.sync.get(exclKey); - browser.tabs.create({ - cookieStoreId: res && res[exclKey] && containers[tabs[0].windowId] || tabs[0].cookieStoreId - }); + res = await browser.storage.sync.get(exclKey), + excl = +(res && res[exclKey] || 0), + mruCookieStoreId = containers[tabs[0].windowId]; + if (excl < 2 || mruCookieStoreId) { + browser.tabs.create({ + cookieStoreId: excl && mruCookieStoreId || tabs[0].cookieStoreId + }); + } } } catch (error) { diff --git a/manifest.json b/manifest.json index 253b36d..31d69fa 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "manifest_version": 2, "name": "Retainer", "author": "Roy Orbison", - "version": "0.1.0", + "version": "0.2.0", "description": "Provides a keyboard shortcut (Shift + Alt + C by default) to create a new tab that retains current/last-used container.", "icons": { "16": "icon.svg", diff --git a/options.html b/options.html index 23fa0c1..54de1f9 100644 --- a/options.html +++ b/options.html @@ -31,9 +31,13 @@
- diff --git a/options.js b/options.js index 26bcf2f..1c2dca0 100644 --- a/options.js +++ b/options.js @@ -5,23 +5,23 @@ * © 2021 Roy Orbison * */ -const excludeCheckbox = document.querySelector('#exclude-default'), +const excludeRadio = document.forms.prefs.elements.restriction, exclKey = 'excludeDefault', store = browser.storage.sync; -excludeCheckbox.indeterminate = true; store.get(exclKey).then(res => { - excludeCheckbox.disabled = false; - excludeCheckbox.indeterminate = false; - excludeCheckbox.checked = !!(res && res[exclKey]); + excludeRadio.forEach(option => { + option.disabled = false; + option.checked = option.value == +(res && res[exclKey] || 0); - excludeCheckbox.addEventListener('change', function() { - excludeCheckbox.indeterminate = true; - const upd = { - [exclKey]: excludeCheckbox.checked - }; - store.set(upd) - .finally(() => excludeCheckbox.indeterminate = false) - .catch(() => excludeCheckbox.checked = !upd[exclKey]); + option.addEventListener('change', function() { + if (option.checked) { + const upd = { + [exclKey]: +option.value + }; + store.set(upd) + .catch(() => excludeRadio.checked = !upd[exclKey]); + } + }); }); });