aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_page.html40
-rw-r--r--vimiumFrontend.js39
2 files changed, 77 insertions, 2 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>
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index ea17b97c..1ef865ff 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -6,6 +6,33 @@ document.addEventListener("blur", onBlurCapturePhase, true);
// we want executed.
var commandPort = chrome.extension.connect({name: "nativeCommand"});
+// Send the key to the key handler in the background page.
+var keyPort = chrome.extension.connect({name: "keyDown"});
+
+function scrollToBottom() {
+ console.log("scrollToBottom()");
+ window.scrollTo(0, document.body.scrollHeight);
+}
+
+function scrollToTop() {
+ console.log("scrollToTop()");
+ window.scrollTo(0, 0);
+}
+
+var commandRegistry = {
+ 'scrollToBottom': scrollToBottom,
+ 'scrollToTop': scrollToTop
+};
+
+chrome.extension.onConnect.addListener(function (port, name) {
+ if (port.name == "executePageCommand")
+ {
+ port.onMessage.addListener(function (args) {
+ commandRegistry[args.command].call();
+ });
+ }
+});
+
var keymap = {
ESC: 27,
a: 65,
@@ -20,7 +47,7 @@ var insertMode = false;
* Executes commands based on the keystroke.
* Note that some keys will only register keydown events and not keystroke events, e.g. ESC.
*/
-function onKeydown(event) {
+function onKeydown(event) {
var key = event.keyCode;
console.log(key);
@@ -30,6 +57,16 @@ function onKeydown(event) {
return;
}
+ // Ignore modifier keys by themselves.
+ if (key > 31 && key < 127)
+ {
+ var keyChar = String.fromCharCode(key);
+ if (event.shiftKey)
+ keyPort.postMessage(keyChar.toUpperCase());
+ else
+ keyPort.postMessage(keyChar.toLowerCase());
+ }
+
var request;
if (key == keymap.d)
request = { command: "tabs.remove" };