-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding initial functional version of extension
- Loading branch information
0 parents
commit 51092b7
Showing
2 changed files
with
73 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,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"] | ||
} | ||
} |
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,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(); | ||
} | ||
}); |