diff options
| author | ilya | 2009-10-28 23:08:58 -0700 |
|---|---|---|
| committer | ilya | 2009-10-28 23:08:58 -0700 |
| commit | 1bb0d3bcabb0b874cd3684db8f06dd68fad55a3b (patch) | |
| tree | ba3aed25e44dcb2f87dad57b2791718e8f1729ef /background_page.html | |
| parent | aff9db2640db9aa02858d0a98a75919b67cfc61d (diff) | |
| download | vimium-1bb0d3bcabb0b874cd3684db8f06dd68fad55a3b.tar.bz2 | |
First pass at a better framework for mapping keys to commands.
Diffstat (limited to 'background_page.html')
| -rw-r--r-- | background_page.html | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/background_page.html b/background_page.html index 7ea906fa..bddfbb17 100644 --- a/background_page.html +++ b/background_page.html @@ -4,6 +4,8 @@ chrome.extension.onConnect.addListener(function(port, name) { if (port.name == "nativeCommand") port.onMessage.addListener(handleNativeCommand); + else if (port.name == "keyDown") + port.onMessage.addListener(handleKeyDown); }); function handleNativeCommand(args) { @@ -21,6 +23,42 @@ break; } } + + var keyToCommandRegistry = {}; + keyToCommandRegistry['gg'] = {command: 'scrollToTop', executeInPage: true}; + keyToCommandRegistry['G'] = {command: 'scrollToBottom', executeInPage: true}; + + var commandRegistry = {}; + var keyQueue = ""; + + function handleKeyDown(key) { + keyQueue = keyQueue + key; + console.log("current keyQueue: [", keyQueue, "]"); + checkKeyQueue(); + } + + function checkKeyQueue() { + if (keyToCommandRegistry[keyQueue]) + { + registryEntry = keyToCommandRegistry[keyQueue]; + console.log("command found for [", keyQueue, "],", registryEntry.command); + + if (registryEntry.executeInPage) + { + chrome.tabs.getSelected(null, function (tab) { + var port = chrome.tabs.connect(tab.id, {name: "executePageCommand"}); + port.postMessage({command: registryEntry.command}); + }); + } + else + { + } + + keyQueue = ""; + } + else if (keyQueue.length > 1) + keyQueue = ""; + } </script> </head> @@ -29,4 +67,4 @@ howdy </body> -</html>
\ No newline at end of file +</html> |
