Last active
June 8, 2020 14:51
-
-
Save josefandersson/92d66db600802d9ce53f29ec0041a33f to your computer and use it in GitHub Desktop.
Revisions
-
josefandersson revised this gist
Jun 8, 2020 . 1 changed file with 9 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,13 +15,15 @@ chrome.commands.onCommand.addListener(cmd => { function tabMoveWindow(tab, dir) { chrome.windows.getAll(wins => { if (wins.length <= 1) chrome.windows.create({ tabId:tab.id }); else for (let i = 0; i < wins.length; i++) if (tab.windowId === wins[i].id) return chrome.tabs.move(tab.id, { windowId: wins[(i + dir + wins.length) % wins.length].id, index:-1 }, newTab => { chrome.tabs.highlight({ windowId:newTab.windowId, tabs:[newTab.index] }, () => { chrome.windows.update(newTab.windowId, { focused:true }); }); }); }); } -
josefandersson revised this gist
Jun 7, 2020 . No changes.There are no files selected for viewing
-
josefandersson created this gist
Jun 7, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ chrome.commands.onCommand.addListener(cmd => { chrome.tabs.query({ currentWindow:true, active:true }, tabs => { const tab = tabs[0]; if (!tab) return; switch (cmd) { case 'move-left': chrome.tabs.move(tab.id, { index:Math.max(0, tab.index-1) }); break; case 'move-right': chrome.tabs.move(tab.id, { index:tab.index+1 }); break; case 'move-to-first': chrome.tabs.move(tab.id, { index:0 }); break; case 'move-to-last': chrome.tabs.move(tab.id, { index:-1 }); break; case 'move-next-window': tabMoveWindow(tab, 1); break; case 'move-prev-window': tabMoveWindow(tab, -1); break; } }); }); function tabMoveWindow(tab, dir) { chrome.windows.getAll(wins => { if (wins.length <= 1) return; for (let i = 0; i < wins.length; i++) if (tab.windowId === wins[i].id) return chrome.tabs.move(tab.id, { windowId: wins[(i + dir + wins.length) % wins.length].id, index:-1 }, newTab => { chrome.tabs.highlight({ windowId:newTab.windowId, tabs:[newTab.index] }, () => { chrome.windows.update(newTab.windowId, { focused:true }); }); }); }); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ { "name": "Move tabs", "version": "1.0", "description": "Use commands to move tabs", "permissions": ["tabs"], "background": { "scripts": ["background.js"], "persistent": false }, "commands": { "move-to-first": { "suggested_key": { "default": "Alt+K" }, "description": "Move current tab leftmost" }, "move-to-last": { "suggested_key": { "default": "Alt+J" }, "description": "Move current tab rightmost" }, "move-left": { "suggested_key": { "default": "Alt+H" }, "description": "Move current tab left" }, "move-right": { "suggested_key": { "default": "Alt+L" }, "description": "Move current tab right" }, "move-next-window": { "description": "Move current tab to the next window" }, "move-prev-window": { "description": "Move current tab to the previous window" } }, "manifest_version": 2 }