aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/index.js18
-rw-r--r--src/content/scrolls.js27
2 files changed, 44 insertions, 1 deletions
diff --git a/src/content/index.js b/src/content/index.js
index fceed4b..e77bb0a 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,3 +1,16 @@
+import * as scrolls from './scrolls';
+
+const invokeEvent = (type) => {
+ switch (type) {
+ case 'scroll.up':
+ scrolls.scrollUp(window);
+ break;
+ case 'scroll.down':
+ scrolls.scrollDown(window);
+ break;
+ }
+}
+
window.addEventListener("keypress", (e) => {
browser.runtime.sendMessage({
key: e.which || e.keyCode,
@@ -5,7 +18,10 @@ window.addEventListener("keypress", (e) => {
alt: e.alt,
meta: e.meta,
ctrl: e.ctrl,
- }).then(() => {
+ }).then((response) => {
+ if (response) {
+ invokeEvent(response);
+ }
}, (err) => {
console.log(`Vim Vixen: ${err}`);
});
diff --git a/src/content/scrolls.js b/src/content/scrolls.js
new file mode 100644
index 0000000..76d1aa2
--- /dev/null
+++ b/src/content/scrolls.js
@@ -0,0 +1,27 @@
+const SCROLL_DELTA = 48;
+
+const scrollUp = (page) => {
+ let x = page.scrollX;
+ var y = page.scrollY - SCROLL_DELTA;
+ page.scrollTo(x, y);
+};
+
+const scrollDown = (page) => {
+ let x = page.scrollX;
+ var y = page.scrollY + SCROLL_DELTA;
+ page.scrollTo(x, y);
+};
+
+const scrollToTop = (page) => {
+ let x = page.scrollX;
+ var y = page.scrollMaxY;
+ page.scrollTo(x, y);
+};
+
+const scrollToBottom = (page) => {
+ let x = page.scrollX;
+ var y = 0;
+ page.scrollTo(x, y);
+};
+
+export { scrollUp, scrollDown, scrollToTop, scrollToBottom }