-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 026bd86
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
browser.commands.onCommand.addListener(command => closeTabs(command)); | ||
|
||
// ---------------------------------------------------- | ||
|
||
async function closeTabs(commandId) { | ||
var tabs = await browser.tabs.query({}); | ||
var activeTab = await getActiveTab(); | ||
|
||
var removeIds = []; | ||
|
||
switch(commandId) { | ||
case 'close-other-tabs': | ||
removeIds = tabs.filter(tab => !tab.active).map(tab => tab.id); | ||
break; | ||
case 'close-left-tabs': | ||
removeIds = tabs.filter(tab => tab.index < activeTab.index).map(tab => tab.id); | ||
break; | ||
case 'close-right-tabs': | ||
removeIds = tabs.filter(tab => tab.index > activeTab.index).map(tab => tab.id); | ||
break; | ||
} | ||
|
||
browser.tabs.remove(removeIds); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "Close Tabs Shortcuts", | ||
"version": "1.1.5", | ||
"description": "Adds keyboard shortcuts for closing all not active tabs, all to the left of the active one, all to the right", | ||
|
||
"manifest_version": 2, | ||
"background": { | ||
"scripts": ["utils.js", "background.js"] | ||
}, | ||
|
||
"commands": { | ||
"close-other-tabs": { | ||
"suggested_key": { "default": "Alt+W" }, | ||
"description": "Close Other Tabs" | ||
}, | ||
"close-left-tabs": { | ||
"suggested_key": { "default": "Alt+Shift+F1" }, | ||
"description": "Close Left Tabs" | ||
}, | ||
"close-right-tabs": { | ||
"suggested_key": { "default": "Alt+Shift+F2" }, | ||
"description": "Close Right Tabs" | ||
} | ||
}, | ||
|
||
"permissions": [ | ||
"tabs" | ||
] | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
function getActiveTab() { | ||
return browser.tabs.query({}).then(tabs => { | ||
return tabs.find(tab => tab.active); | ||
}); | ||
} |