Skip to content

Commit

Permalink
- new
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalis13 committed Dec 8, 2017
0 parents commit 026bd86
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions background.js
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);
}
29 changes: 29 additions & 0 deletions manifest.json
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"
]
}
6 changes: 6 additions & 0 deletions utils.js
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);
});
}

0 comments on commit 026bd86

Please sign in to comment.