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.js14
2 files changed, 30 insertions, 13 deletions
diff --git a/src/content/index.js b/src/content/index.js
index 88a668e..03efc5e 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,4 +1,5 @@
import * as scrolls from './scrolls';
+import * as actions from '../shared/actions';
const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) {
@@ -6,27 +7,43 @@ const invokeEvent = (action) => {
}
switch (action[0]) {
- case 'scroll.up':
+ case actions.SCROLL_UP:
scrolls.scrollUp(window, action[1] || 1);
break;
- case 'scroll.down':
+ case actions.SCROLL_DOWN:
scrolls.scrollDown(window, action[1] || 1);
break;
+ case actions.SCROLL_TOP:
+ scrolls.scrollTop(window, action[1]);
+ break;
+ case actions.SCROLL_BOTTOM:
+ scrolls.scrollBottom(window, action[1]);
+ break;
}
}
+const isModifier = (code) => {
+ return code === KeyboardEvent.DOM_VK_SHIFT ||
+ code === KeyboardEvent.DOM_VK_ALT ||
+ code === KeyboardEvent.DOM_VK_CONTROL ||
+ code === KeyboardEvent.DOM_VK_META;
+}
+
window.addEventListener("keydown", (e) => {
if (e.target instanceof HTMLInputElement) {
return;
}
+ if (isModifier(e.keyCode)) {
+ return;
+ }
let request = {
type: 'event.keydown',
code: e.keyCode,
- shift: e.shift,
- alt: e.alt,
- meta: e.meta,
- ctrl: e.ctrl,
+ shift: e.shiftKey,
+ alt: e.altKey,
+ meta: e.metaKey,
+ ctrl: e.ctrlKey,
}
browser.runtime.sendMessage(request)
diff --git a/src/content/scrolls.js b/src/content/scrolls.js
index e640384..2a233c2 100644
--- a/src/content/scrolls.js
+++ b/src/content/scrolls.js
@@ -2,26 +2,26 @@ const SCROLL_DELTA = 48;
const scrollUp = (page, count) => {
let x = page.scrollX;
- var y = page.scrollY - SCROLL_DELTA * count;
+ let y = page.scrollY - SCROLL_DELTA * count;
page.scrollTo(x, y);
};
const scrollDown = (page, count) => {
let x = page.scrollX;
- var y = page.scrollY + SCROLL_DELTA * count;
+ let y = page.scrollY + SCROLL_DELTA * count;
page.scrollTo(x, y);
};
-const scrollToTop = (page) => {
+const scrollTop = (page) => {
let x = page.scrollX;
- var y = page.scrollMaxY;
+ let y = 0;
page.scrollTo(x, y);
};
-const scrollToBottom = (page) => {
+const scrollBottom = (page) => {
let x = page.scrollX;
- var y = 0;
+ let y = page.scrollMaxY;
page.scrollTo(x, y);
};
-export { scrollUp, scrollDown, scrollToTop, scrollToBottom }
+export { scrollUp, scrollDown, scrollTop, scrollBottom }