Last active
August 29, 2015 14:00
-
-
Save staydecent/65b7402276b5698b4fb2 to your computer and use it in GitHub Desktop.
Command Tabs Opera Extension
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
// on proper key press | |
chrome.runtime.onMessage.addListener(function(request, sender) { | |
if (!request.tabIndex) { return; } | |
var tabIndex = request.tabIndex; | |
chrome.tabs.query({currentWindow: true, index: tabIndex}, function(tab) { | |
if (!tab.length) { return; } | |
chrome.tabs.update(tab[0].id, {active: true}); | |
}); | |
}); |
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
// Command Tabs | |
var commandIsPressed = false; | |
var commandKeyCode = 91; | |
var numberKeyCodes = { | |
49: 1, | |
50: 2, | |
51: 3, | |
52: 4, | |
53: 5, | |
54: 6, | |
55: 7, | |
56: 8, | |
57: 9 | |
}; | |
window.addEventListener('keydown', keyDown, false); | |
window.addEventListener('keyup', keyUp, false); | |
function keyDown(e) { | |
if (e.which === commandKeyCode) { | |
commandIsPressed = true; | |
} | |
if (!commandIsPressed) { return; } | |
// 1-9 number keys | |
if (e.which > 48 && e.which < 58) { | |
var tabIndex = numberKeyCodes[e.which] - 1; // 0-indexed | |
chrome.runtime.sendMessage({tabIndex: tabIndex}); | |
} | |
} | |
function keyUp(e) { | |
if (e.which === commandKeyCode) { | |
commandIsPressed = false; | |
} | |
} |
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
{ | |
"name": "Command Tabs", | |
"version": "0.1.0", | |
"manifest_version": 2, | |
"description": "Focus tabs based on their index + the Command key.", | |
"developer": { | |
"name": "Adrian Unger", | |
"url": "http://staydecent.ca" | |
}, | |
"background": {"scripts": ["background.js"]}, | |
"content_scripts": [ | |
{ | |
"matches": ["<all_urls>"], | |
"js": ["command-tabs.js"] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment