From 8ff302a1f2870994cddc36fd461879eac951203d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 7 Oct 2017 18:38:57 +0900 Subject: store input keys in content script --- src/actions/operation.js | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'src/actions') diff --git a/src/actions/operation.js b/src/actions/operation.js index 295fd4f..0bb8310 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -2,6 +2,9 @@ import operations from 'shared/operations'; import messages from 'content/messages'; import * as tabs from 'background/tabs'; import * as zooms from 'background/zooms'; +import * as scrolls from 'content/scrolls'; +import * as navigates from 'content/navigates'; +import * as followActions from 'actions/follow'; const sendConsoleShowCommand = (tab, command) => { return browser.tabs.sendMessage(tab.id, { @@ -10,7 +13,43 @@ const sendConsoleShowCommand = (tab, command) => { }); }; -const exec = (operation, tab) => { +const exec = (operation) => { + switch (operation.type) { + case operations.SCROLL_LINES: + return scrolls.scrollLines(window, operation.count); + case operations.SCROLL_PAGES: + return scrolls.scrollPages(window, operation.count); + case operations.SCROLL_TOP: + return scrolls.scrollTop(window); + case operations.SCROLL_BOTTOM: + return scrolls.scrollBottom(window); + case operations.SCROLL_HOME: + return scrolls.scrollLeft(window); + case operations.SCROLL_END: + return scrolls.scrollRight(window); + case operations.FOLLOW_START: + return followActions.enable(false); + case operations.NAVIGATE_HISTORY_PREV: + return navigates.historyPrev(window); + case operations.NAVIGATE_HISTORY_NEXT: + return navigates.historyNext(window); + case operations.NAVIGATE_LINK_PREV: + return navigates.linkPrev(window); + case operations.NAVIGATE_LINK_NEXT: + return navigates.linkNext(window); + case operations.NAVIGATE_PARENT: + return navigates.parent(window); + case operations.NAVIGATE_ROOT: + return navigates.root(window); + default: + browser.runtime.sendMessage({ + type: messages.BACKGROUND_OPERATION, + operation, + }); + } +}; + +const execBackground = (operation, tab) => { switch (operation.type) { case operations.TAB_CLOSE: return tabs.closeTab(tab.id); @@ -45,11 +84,8 @@ const exec = (operation, tab) => { case operations.COMMAND_SHOW_BUFFER: return sendConsoleShowCommand(tab, 'buffer '); default: - return browser.tabs.sendMessage(tab.id, { - type: messages.CONTENT_OPERATION, - operation - }); + return Promise.resolve(); } }; -export { exec }; +export { exec, execBackground }; -- cgit v1.2.3