aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-12 11:08:43 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-12 11:22:09 +0900
commite73d405c5640afda27775285f19516a271b5cefb (patch)
treeda08aefd9c5f718f96aff84c4f2c95554796999b /src
parentd169661e030e53b6a1635f86205f9fc42d2b7ef2 (diff)
message passing between background and content
Diffstat (limited to 'src')
-rw-r--r--src/background/index.js4
-rw-r--r--src/content/index.js9
-rw-r--r--src/index.js3
-rw-r--r--src/module.js18
4 files changed, 13 insertions, 21 deletions
diff --git a/src/background/index.js b/src/background/index.js
new file mode 100644
index 0000000..ee02f63
--- /dev/null
+++ b/src/background/index.js
@@ -0,0 +1,4 @@
+browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
+ console.log("Pressed " + request.which);
+ sendResponse({ response: "Response from background script" });
+});
diff --git a/src/content/index.js b/src/content/index.js
new file mode 100644
index 0000000..0fa0720
--- /dev/null
+++ b/src/content/index.js
@@ -0,0 +1,9 @@
+window.addEventListener("keypress", (e) => {
+ browser.runtime.sendMessage({
+ which: e.which || e.keyCode,
+ }).then((msg) => {
+ console.log(`Message from the background script: ${msg.response}`);
+ }, (err) => {
+ console.log(`Error: ${err}`);
+ });
+});
diff --git a/src/index.js b/src/index.js
deleted file mode 100644
index 8c9b627..0000000
--- a/src/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import * as Module from './module';
-
-Module.initialize()
diff --git a/src/module.js b/src/module.js
deleted file mode 100644
index e967a62..0000000
--- a/src/module.js
+++ /dev/null
@@ -1,18 +0,0 @@
-const initialize = () => {
- let p = document.createElement("p");
- p.textContent = "Hello Vim Vixen";
- p.style.position = 'fixed';
- p.style.right = '0';
- p.style.bottom = '0';
- p.style.padding = '0rem .5rem';
- p.style.margin = '0';
- p.style.backgroundColor = 'lightgray';
- p.style.border = 'gray';
- p.style.boxShadow = '0 0 2px gray inset';
- p.style.borderRadius = '3px';
- p.style.fontFamily = 'monospace';
-
- document.body.append(p)
-}
-
-export { initialize };