aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2009-09-20 00:09:05 -0700
committerPhil Crosby2009-09-20 00:09:44 -0700
commitaff9db2640db9aa02858d0a98a75919b67cfc61d (patch)
treeb891be713fd38d8bf5be64a8fc7688ada4e56708
downloadvimium-aff9db2640db9aa02858d0a98a75919b67cfc61d.tar.bz2
Initial project commit
-rw-r--r--README1
-rw-r--r--background_page.html32
-rw-r--r--manifest.json16
-rw-r--r--toolstrip.html3
-rw-r--r--vimiumFrontend.js101
5 files changed, 153 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 00000000..5667fc4a
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+A work in progress.
diff --git a/background_page.html b/background_page.html
new file mode 100644
index 00000000..7ea906fa
--- /dev/null
+++ b/background_page.html
@@ -0,0 +1,32 @@
+<html>
+<head>
+<script type="text/javascript" charset="utf-8">
+ chrome.extension.onConnect.addListener(function(port, name) {
+ if (port.name == "nativeCommand")
+ port.onMessage.addListener(handleNativeCommand);
+ });
+
+ function handleNativeCommand(args) {
+ console.log("received native command:", args);
+
+ switch(args.command) {
+ case "tabs.create":
+ chrome.tabs.create({});
+ break;
+ case "tabs.remove":
+ console.log("removing");
+ chrome.tabs.getSelected(null, function(tab) {
+ chrome.tabs.remove(tab.id);
+ });
+ break;
+ }
+ }
+</script>
+
+</head>
+
+<body>
+ howdy
+</body>
+
+</html> \ No newline at end of file
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 00000000..3310bf34
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,16 @@
+{
+ "name": "Vimium",
+ "version": "1.0",
+ "description": "The hacker's browser.",
+ "toolstrips": [ "toolstrip.html" ],
+ "background_page": "background_page.html",
+ "permissions": [
+ "tabs"
+ ],
+ "content_scripts": [
+ {
+ "matches": ["http://*/*", "https://*/*"],
+ "js": ["vimiumFrontend.js"]
+ }
+ ]
+} \ No newline at end of file
diff --git a/toolstrip.html b/toolstrip.html
new file mode 100644
index 00000000..c984ed06
--- /dev/null
+++ b/toolstrip.html
@@ -0,0 +1,3 @@
+<div class="toolstrip-button">
+ <span>Hello, World!</span>
+</div>
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
new file mode 100644
index 00000000..ea17b97c
--- /dev/null
+++ b/vimiumFrontend.js
@@ -0,0 +1,101 @@
+document.addEventListener("keydown", onKeydown);
+document.addEventListener("focus", onFocusCapturePhase, true);
+document.addEventListener("blur", onBlurCapturePhase, true);
+
+// Used to communicate with the background page and send it native browser commands that
+// we want executed.
+var commandPort = chrome.extension.connect({name: "nativeCommand"});
+
+var keymap = {
+ ESC: 27,
+ a: 65,
+ d: 68,
+ i: 73,
+ t: 84
+};
+
+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) {
+ var key = event.keyCode;
+ console.log(key);
+
+ if (insertMode) {
+ if (key == keymap.ESC)
+ exitInsertMode();
+ return;
+ }
+
+ var request;
+ if (key == keymap.d)
+ request = { command: "tabs.remove" };
+ else if (key == keymap.t)
+ request = { command: "tabs.create" };
+ else if (key == keymap.i)
+ enterInsertMode();
+ else
+ return;
+
+ event.preventDefault();
+ commandPort.postMessage(request);
+ console.log(event);
+}
+
+
+function onFocusCapturePhase(event) {
+ if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA")
+ enterInsertMode();
+}
+
+function onBlurCapturePhase(event) {
+ if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA")
+ exitInsertMode();
+}
+
+function enterInsertMode() {
+ insertMode = true;
+ HUD.show("Insert mode");
+}
+
+function exitInsertMode() {
+ insertMode = false;
+ HUD.hide();
+}
+
+HUD = {
+ show:function(text) {
+ HUD.displayElement().innerHTML = text;
+ HUD.displayElement().style.display = "";
+ },
+
+ /*
+ * Retrieves the HUD HTML element, creating it if necessary.
+ */
+ displayElement: function() {
+ if (!HUD._displayElement) {
+ var element = document.createElement("div");
+ element.innerHTML = "howdy";
+ element.style.position = "fixed";
+ element.style.bottom = "0px";
+ element.style.left = "10px";
+ element.style.backgroundColor = " #e5e5e5";
+ element.style.maxWidth = "400px";
+ element.style.fontSize = "11px";
+ element.style.padding = "3px";
+ element.style.border = "1px solid #cccccc";
+ element.style.borderBottomWidth = "0px";
+ // element.style.fontFamily = "monospace";
+ document.body.appendChild(element);
+ HUD._displayElement = element
+ }
+ return HUD._displayElement
+ },
+
+ hide: function() {
+ HUD.displayElement().style.display = "none";
+ }
+};