aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/index.js29
-rw-r--r--src/content/scrolls.js8
2 files changed, 21 insertions, 16 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}`);
+ });
});
diff --git a/src/content/scrolls.js b/src/content/scrolls.js
index 76d1aa2..e640384 100644
--- a/src/content/scrolls.js
+++ b/src/content/scrolls.js
@@ -1,14 +1,14 @@
const SCROLL_DELTA = 48;
-const scrollUp = (page) => {
+const scrollUp = (page, count) => {
let x = page.scrollX;
- var y = page.scrollY - SCROLL_DELTA;
+ var y = page.scrollY - SCROLL_DELTA * count;
page.scrollTo(x, y);
};
-const scrollDown = (page) => {
+const scrollDown = (page, count) => {
let x = page.scrollX;
- var y = page.scrollY + SCROLL_DELTA;
+ var y = page.scrollY + SCROLL_DELTA * count;
page.scrollTo(x, y);
};