From 55d59eabd9839f83d90429c48f7a1f5e54769f44 Mon Sep 17 00:00:00 2001 From: Eyal Erez Date: Wed, 10 Feb 2021 16:26:49 +0200 Subject: [PATCH] Cycle tab through windows intead of asking users to choose one. --- scripts/background.js | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/scripts/background.js b/scripts/background.js index 6038449..08fe645 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -108,40 +108,20 @@ function sendTabManager() { if (windows.length === 1) { // do nothing return; - } else if (windows.length === 2) { - // send tab to only other window - utils.getCurrentTab().then((tab) => { - const otherWindow = windows.filter((filterWindow) => { - return (filterWindow.id !== tab.windowId); - }); - - chrome.tabs.move(tab.id, {windowId: otherWindow[0].id, index: -1}); - chrome.windows.update(otherWindow[0].id, {focused: true}); - chrome.tabs.update(tab.id, {selected: true}); - }); } else { + // send tab to next window utils.getCurrentTab().then((tab) => { - return utils.createTab({url : `../tabbo.html#${tab.id}`}); - }).then((newTab) => { - console.log(newTab); - const onTabChange = (response) => { - if (response.tabId !== newTab.id) { - chrome.tabs.onActivated.removeListener(onTabChange); - - utils.getTab(newTab.id).then(() => { - if (!chrome.runtime.lastError) { - chrome.tabs.remove(newTab.id); - } - }, (e) => { - console.error(e); - }); - } - }; - - chrome.tabs.onActivated.addListener(onTabChange); + const currentWindowIndex = windows.findIndex(w => w.id === currentWindow.id); + var nextWindowIndex = currentWindowIndex - 1; + if (nextWindowIndex < 0) { + nextWindowIndex = windows.length - 1; + } + chrome.tabs.move(tab.id, {windowId: windows[nextWindowIndex].id, index: -1}); + chrome.windows.update(windows[nextWindowIndex].id, {focused: true}); + chrome.tabs.update(tab.id, {selected: true}); }); } - }); + }); } function explodeTabs() {