From f1784f5f041198a1531fd0ecd0cad4edf095199a Mon Sep 17 00:00:00 2001 From: Amine Date: Thu, 25 Feb 2021 22:40:42 +0100 Subject: [PATCH 1/2] Added backend code to set aside single tabs if none are selected --- js/background.js | 53 ++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/js/background.js b/js/background.js index 120a39f..d200813 100644 --- a/js/background.js +++ b/js/background.js @@ -6,14 +6,16 @@ var syncEnabled = true; //This variable controls whether to use the chrome sync var collectionStorage = syncEnabled ? chrome.storage.sync : chrome.storage.local; //Get the tabs to save, either all the window or the selected tabs only, and pass them through a callback. -function GetTabsToSave (callback) +function GetTabsToSave (callback, ignoreSingleTab = true) { - chrome.tabs.query({ currentWindow: true }, (windowTabs) => + chrome.tabs.query({currentWindow: true}, (windowTabs) => { var highlightedTabs = windowTabs.filter(item => item.highlighted); - //If there are more than one selected tab in the window, we set only those aside. - // Otherwise, all the window's tabs get saved. - return callback((highlightedTabs.length > 1 ? highlightedTabs : windowTabs)); + //If there are more than one selected tab in the window, or user asked for the active tab only, we set only those aside. + if (highlightedTabs.length > 1 || !ignoreSingleTab) + return callback(highlightedTabs); + else // Otherwise, all the window's tabs get saved. + return callback(windowTabs); }); } @@ -63,25 +65,32 @@ function TogglePane (tab) function ProcessCommand (command) { - GetTabsToSave((returnedTabs) => + switch(command) { - tabsToSave = returnedTabs; - switch(command) - { - case "set-aside": + case "set-aside": + GetTabsToSave((returnedTabs) => + { + tabsToSave = returnedTabs; SaveCollection(); - break; - case "toggle-pane": - chrome.tabs.query( - { - active: true, - currentWindow: true - }, - (tabs) => TogglePane(tabs[0]) - ) - break; - } - }); + }); + break; + case "set-aside-only-selected": + GetTabsToSave((returnedTabs) => + { + tabsToSave = returnedTabs; + SaveCollection(); + },false); + break; + case "toggle-pane": + chrome.tabs.query( + { + active: true, + currentWindow: true + }, + (tabs) => TogglePane(tabs[0]) + ) + break; + } } chrome.browserAction.onClicked.addListener((tab) => From ac26fbf8c4073c126a075ddf57a99538ab844c4d Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 15 Aug 2021 13:51:02 +0200 Subject: [PATCH 2/2] Add context menu item to set aside selected tabs only --- _locales/en/messages.json | 5 +++++ js/background.js | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 5ddfcda..429313e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -69,6 +69,11 @@ "message": "Set current tabs aside", "description": "Save collection action name. Used in the pane, extension context menu and manifest shortcuts" }, + "setAsideSelected": + { + "message": "Set selected tabs aside", + "description": "Save collection action name, for selected tabs only. Used in the extension context menu" + }, "setMultipleTabsAsideTooltip": { "message": "Tip : You can set aside specific tabs by selecting them (by holding CTRL or SHIFT and clicking on the tabs) before clicking on the TabsAside extension", diff --git a/js/background.js b/js/background.js index d200813..197620f 100644 --- a/js/background.js +++ b/js/background.js @@ -297,6 +297,13 @@ chrome.runtime.onInstalled.addListener((updateInfo) => title: chrome.i18n.getMessage("setAside") } ); + chrome.contextMenus.create( + { + id: "set-aside-only-selected", + contexts: ["browser_action"], + title: chrome.i18n.getMessage("setAsideSelected") + } + ); }); //We receive a message from the pane aside-script, which means the tabsToSave are already assigned on message reception.