|
|
@ -1,4 +1,5 @@ |
|
|
|
import * as scrolls from './scrolls'; |
|
|
|
import * as scrolls from './scrolls'; |
|
|
|
|
|
|
|
import * as actions from '../shared/actions'; |
|
|
|
|
|
|
|
|
|
|
|
const invokeEvent = (action) => { |
|
|
|
const invokeEvent = (action) => { |
|
|
|
if (typeof action === 'undefined' || action === null) { |
|
|
|
if (typeof action === 'undefined' || action === null) { |
|
|
@ -6,27 +7,43 @@ const invokeEvent = (action) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (action[0]) { |
|
|
|
switch (action[0]) { |
|
|
|
case 'scroll.up': |
|
|
|
case actions.SCROLL_UP: |
|
|
|
scrolls.scrollUp(window, action[1] || 1); |
|
|
|
scrolls.scrollUp(window, action[1] || 1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'scroll.down': |
|
|
|
case actions.SCROLL_DOWN: |
|
|
|
scrolls.scrollDown(window, action[1] || 1); |
|
|
|
scrolls.scrollDown(window, action[1] || 1); |
|
|
|
break; |
|
|
|
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) => { |
|
|
|
window.addEventListener("keydown", (e) => { |
|
|
|
if (e.target instanceof HTMLInputElement) { |
|
|
|
if (e.target instanceof HTMLInputElement) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isModifier(e.keyCode)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let request = { |
|
|
|
let request = { |
|
|
|
type: 'event.keydown', |
|
|
|
type: 'event.keydown', |
|
|
|
code: e.keyCode, |
|
|
|
code: e.keyCode, |
|
|
|
shift: e.shift, |
|
|
|
shift: e.shiftKey, |
|
|
|
alt: e.alt, |
|
|
|
alt: e.altKey, |
|
|
|
meta: e.meta, |
|
|
|
meta: e.metaKey, |
|
|
|
ctrl: e.ctrl, |
|
|
|
ctrl: e.ctrlKey, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
browser.runtime.sendMessage(request) |
|
|
|
browser.runtime.sendMessage(request) |
|
|
|