From 46d76dfaa3e4b73804723a2b8e7a9927f9c94101 Mon Sep 17 00:00:00 2001 From: Moonloard Date: Mon, 27 Jul 2020 22:12:49 +0200 Subject: [PATCH 1/4] new option to replace current tab when a assigned domain is opened --- src/js/background/assignManager.js | 9 ++++++++- src/js/options.js | 23 +++++++++++++---------- src/options.html | 7 +++++++ test/common.js | 3 ++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index deee22a..032adb1 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -51,6 +51,11 @@ window.assignManager = { return !!syncEnabled; }, + async getReplaceTabEnabled() { + const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled"); + return !!replaceTabEnabled; + }, + getByUrlKey(siteStoreKey) { return new Promise((resolve, reject) => { this.area.get([siteStoreKey]).then((storageResponse) => { @@ -233,9 +238,11 @@ window.assignManager = { return {}; } } + const replaceTabEnabled = await this.storageArea.getReplaceTabEnabled(); const removeTab = backgroundLogic.NEW_TAB_PAGES.has(tab.url) || (messageHandler.lastCreatedTab - && messageHandler.lastCreatedTab.id === tab.id); + && messageHandler.lastCreatedTab.id === tab.id) + || replaceTabEnabled; const openTabId = removeTab ? tab.openerTabId : tab.id; if (!this.canceledRequests[tab.id]) { diff --git a/src/js/options.js b/src/js/options.js index 2d5f910..fab39be 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -16,25 +16,26 @@ async function requestPermissions() { async function enableDisableSync() { const checkbox = document.querySelector("#syncCheck"); - if (checkbox.checked) { - await browser.storage.local.set({syncEnabled: true}); - } else { - await browser.storage.local.set({syncEnabled: false}); - } + await browser.storage.local.set({syncEnabled: !!checkbox.checked}); browser.runtime.sendMessage({ method: "resetSync" }); } +async function enableDisableReplaceTab() { + const checkbox = document.querySelector("#replaceTabCheck"); + await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked}); +} + async function setupOptions() { const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]}); const { syncEnabled } = await browser.storage.local.get("syncEnabled"); + const { replaceTabEnabled } = + await browser.storage.local.get("replaceTabEnabled"); if (hasPermission) { document.querySelector("#bookmarksPermissions").checked = true; } - if (syncEnabled) { - document.querySelector("#syncCheck").checked = true; - } else { - document.querySelector("#syncCheck").checked = false; - } + document.querySelector("#syncCheck").checked = !!syncEnabled; + document.querySelector("#replaceTabCheck").checked = + !!replaceTabEnabled; setupContainerShortcutSelects(); } @@ -82,6 +83,8 @@ function resetOnboarding() { document.addEventListener("DOMContentLoaded", setupOptions); document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions); document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync); +document.querySelector("#replaceTabCheck") + .addEventListener( "change", enableDisableReplaceTab); document.querySelector("button").addEventListener("click", resetOnboarding); for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) { diff --git a/src/options.html b/src/options.html index 6f30fae..ae356ac 100644 --- a/src/options.html +++ b/src/options.html @@ -20,6 +20,13 @@ Enable Sync

This setting allows you to sync your containers and site assignments across devices.

+

Tab behaviour:

+ +

Replace current tab if a page which is assigned to a specific container is opened (instead of keeping the current tab open). + Opening tabs with middle mouse button is not affected.

Keyboard Shortcuts:

Edit which container is opened when using the numbered shortcuts.

Tab behaviour:

-

Replace current tab if a page which is assigned to a specific container is opened (instead of keeping the current tab open). +

Replace the current tab if a page which is assigned to another container is opened (instead of keeping the current tab open). Opening tabs with middle mouse button is not affected.

Keyboard Shortcuts:

Edit which container is opened when using the numbered shortcuts.

From 518f1cca89ce683c2c73f0a1e44437c92b12d865 Mon Sep 17 00:00:00 2001 From: Moonloard Date: Mon, 27 Jul 2020 22:49:33 +0200 Subject: [PATCH 4/4] option name adjusted --- src/options.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.html b/src/options.html index 18feaae..7fe1b24 100644 --- a/src/options.html +++ b/src/options.html @@ -23,7 +23,7 @@

Tab behaviour:

Replace the current tab if a page which is assigned to another container is opened (instead of keeping the current tab open). Opening tabs with middle mouse button is not affected.