aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html40
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>