aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/index.js')
-rw-r--r--src/content/index.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/content/index.js b/src/content/index.js
index 514f964..e882a68 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,28 +1,33 @@
import * as scrolls from './scrolls';
-const invokeEvent = (type) => {
- switch (type) {
+const invokeEvent = (action) => {
+ if (typeof action === 'undefined' || action === null) {
+ return;
+ }
+
+ switch (action[0]) {
case 'scroll.up':
- scrolls.scrollUp(window);
+ scrolls.scrollUp(window, action[1] || 1);
break;
case 'scroll.down':
- scrolls.scrollDown(window);
+ scrolls.scrollDown(window, action[1] || 1);
break;
}
}
window.addEventListener("keydown", (e) => {
- browser.runtime.sendMessage({
+ let request = {
+ type: 'event.keydown',
code: e.keyCode,
shift: e.shift,
alt: e.alt,
meta: e.meta,
ctrl: e.ctrl,
- }).then((response) => {
- if (response) {
- invokeEvent(response);
- }
- }, (err) => {
- console.log(`Vim Vixen: ${err}`);
- });
+ }
+
+ browser.runtime.sendMessage(request)
+ .then(invokeEvent,
+ (err) => {
+ console.log(`Vim Vixen: ${err}`);
+ });
});