Skip to content

Commit

Permalink
Adding initial functional version of extension
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed May 21, 2014
0 parents commit 51092b7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
30 changes: 30 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"manifest_version": 2,

"name": "Tab Shortcuts",
"description": "This extension allows shortcuts for next / previous tabs to be reassigned",
"version": "0.1",

"permissions": [
"tabs"
],

"commands" : {
"next-tab" : {
"suggested_key" : { "default" : "Ctrl+J" },
"description" : "Go to next tab"
},
"prev-tab" : {
"suggested_key" : { "default" : "Ctrl+K" },
"description" : "Go to previous tab"
},
"remap-downloads" : {
"suggested_key" : { "default" : "Ctrl+Shift+J" },
"description" : "New downloads shortcut"
}
},

"background" : {
"scripts" : ["script.js"]
}
}
43 changes: 43 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var DL_URL = "chrome://downloads/";

function change_tab(next_prev) {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
for (i in tabs) {
var tab = tabs[i];
chrome.tabs.query({windowId:tab.windowId}, function(alltabs) {
chrome.tabs.query({index: (next_prev(tab.index) + alltabs.length) % alltabs.length,
windowId:tab.windowId}, function(tabs) {
for (i in tabs) {
chrome.tabs.update(tabs[i].id, {active:true});
}
});
});
}
});
}

function open_downloads() {
chrome.tabs.query({currentWindow: true, url: DL_URL}, function (tabs) {
var done = false;
for (i in tabs) {
chrome.tabs.update(tabs[i].id, {active:true});
done = true;
}
// if there is no existing downloads tab
if (done == false) {
chrome.tabs.create({url: DL_URL});
}
});
}

chrome.commands.onCommand.addListener(function(command) {
if (command == 'next-tab') {
change_tab(function(x) { return x + 1 });
}
if (command == 'prev-tab') {
change_tab(function(x) { return x - 1 });
}
if (command == 'remap-downloads') {
open_downloads();
}
});

0 comments on commit 51092b7

Please sign in to comment.