特定の文字列を含むタブ+右側のタブをショートカットで閉じる。
Chromeのタブ操作はほぼショートカットなのだけど、使用頻度の高い「右側のタブを閉じる」だけマウス操作になってしまっており不便だった。
manifest.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
{ "manifest_version": 3, "name": "CloseTabs", "version": "0.0.2", "background": { "service_worker": "script.js" }, "permissions": [ "tabs" ], "commands": { "close-tabs": { "suggested_key": { "default": "Alt+Shift+E" }, "description": "CloseTabs" }, "close-right-tabs": { "suggested_key": { "default": "Alt+Shift+Z" }, "description": "CloseRightTabs" } } } |
script.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
chrome.commands.onCommand.addListener(function (command) { if (command === 'close-tabs') { chrome.tabs.query({}, tabs => { for(let i=0; i<tabs.length; i++){ if (tabs[i].title.indexOf('アラート! - ESET Internet Security') !== -1) { chrome.tabs.remove(tabs[i].id); } } }); } else if (command === 'close-right-tabs') { chrome.tabs.query({currentWindow: true}, tabs => { let rightSide = false; for(let i=0; i<tabs.length; i++) { if (rightSide) { chrome.tabs.remove(tabs[i].id); } else { if (tabs[i].active) rightSide = true; } } }); } }); |
AutoHotkeyから呼び出して利用中。
これで「右側のタブを閉じる」がAlt+Zで実行できる。Chrome拡張のショートカットの都合で今回はAutoHotkeyで置き換えているが通常は不要。
1 2 3 4 5 |
WinGetTitle, this_title, A If(RegExMatch(this_title, "Google Chrome") > 0) { Send, !+{E} ; Chrome拡張 } |
1 |
<!z::Send, !+{Z} ; Chrome拡張 |
Chrome側のショートカットの設定は、
︙>その他ツール>拡張機能>≡>キーボードショートカット
CoseRightTabs:Alt+Shift+Z
CloseTabs:Alt+Shift+E