From c60d0e7392fc708e961614d6b756a045de74f458 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:00:07 +0900 Subject: Rename .js/.jsx to .ts/.tsx --- src/content/actions/addon.js | 19 ------ src/content/actions/addon.ts | 19 ++++++ src/content/actions/find.js | 68 -------------------- src/content/actions/find.ts | 68 ++++++++++++++++++++ src/content/actions/follow-controller.js | 30 --------- src/content/actions/follow-controller.ts | 30 +++++++++ src/content/actions/index.js | 31 --------- src/content/actions/index.ts | 31 +++++++++ src/content/actions/input.js | 16 ----- src/content/actions/input.ts | 16 +++++ src/content/actions/mark.js | 46 -------------- src/content/actions/mark.ts | 46 ++++++++++++++ src/content/actions/operation.js | 104 ------------------------------- src/content/actions/operation.ts | 104 +++++++++++++++++++++++++++++++ src/content/actions/setting.js | 37 ----------- src/content/actions/setting.ts | 37 +++++++++++ 16 files changed, 351 insertions(+), 351 deletions(-) delete mode 100644 src/content/actions/addon.js create mode 100644 src/content/actions/addon.ts delete mode 100644 src/content/actions/find.js create mode 100644 src/content/actions/find.ts delete mode 100644 src/content/actions/follow-controller.js create mode 100644 src/content/actions/follow-controller.ts delete mode 100644 src/content/actions/index.js create mode 100644 src/content/actions/index.ts delete mode 100644 src/content/actions/input.js create mode 100644 src/content/actions/input.ts delete mode 100644 src/content/actions/mark.js create mode 100644 src/content/actions/mark.ts delete mode 100644 src/content/actions/operation.js create mode 100644 src/content/actions/operation.ts delete mode 100644 src/content/actions/setting.js create mode 100644 src/content/actions/setting.ts (limited to 'src/content/actions') diff --git a/src/content/actions/addon.js b/src/content/actions/addon.js deleted file mode 100644 index b30cf16..0000000 --- a/src/content/actions/addon.js +++ /dev/null @@ -1,19 +0,0 @@ -import messages from 'shared/messages'; -import actions from 'content/actions'; - -const enable = () => setEnabled(true); - -const disable = () => setEnabled(false); - -const setEnabled = async(enabled) => { - await browser.runtime.sendMessage({ - type: messages.ADDON_ENABLED_RESPONSE, - enabled, - }); - return { - type: actions.ADDON_SET_ENABLED, - enabled, - }; -}; - -export { enable, disable, setEnabled }; diff --git a/src/content/actions/addon.ts b/src/content/actions/addon.ts new file mode 100644 index 0000000..b30cf16 --- /dev/null +++ b/src/content/actions/addon.ts @@ -0,0 +1,19 @@ +import messages from 'shared/messages'; +import actions from 'content/actions'; + +const enable = () => setEnabled(true); + +const disable = () => setEnabled(false); + +const setEnabled = async(enabled) => { + await browser.runtime.sendMessage({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled, + }); + return { + type: actions.ADDON_SET_ENABLED, + enabled, + }; +}; + +export { enable, disable, setEnabled }; diff --git a/src/content/actions/find.js b/src/content/actions/find.js deleted file mode 100644 index e08d7e5..0000000 --- a/src/content/actions/find.js +++ /dev/null @@ -1,68 +0,0 @@ -// -// window.find(aString, aCaseSensitive, aBackwards, aWrapAround, -// aWholeWord, aSearchInFrames); -// -// NOTE: window.find is not standard API -// https://developer.mozilla.org/en-US/docs/Web/API/Window/find - -import messages from 'shared/messages'; -import actions from 'content/actions'; -import * as consoleFrames from '../console-frames'; - -const find = (string, backwards) => { - let caseSensitive = false; - let wrapScan = true; - - - // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work - // because of same origin policy - let found = window.find(string, caseSensitive, backwards, wrapScan); - if (found) { - return found; - } - window.getSelection().removeAllRanges(); - return window.find(string, caseSensitive, backwards, wrapScan); -}; - -const findNext = async(currentKeyword, reset, backwards) => { - if (reset) { - window.getSelection().removeAllRanges(); - } - - let keyword = currentKeyword; - if (currentKeyword) { - browser.runtime.sendMessage({ - type: messages.FIND_SET_KEYWORD, - keyword: currentKeyword, - }); - } else { - keyword = await browser.runtime.sendMessage({ - type: messages.FIND_GET_KEYWORD, - }); - } - if (!keyword) { - return consoleFrames.postError('No previous search keywords'); - } - let found = find(keyword, backwards); - if (found) { - consoleFrames.postInfo('Pattern found: ' + keyword); - } else { - consoleFrames.postError('Pattern not found: ' + keyword); - } - - return { - type: actions.FIND_SET_KEYWORD, - keyword, - found, - }; -}; - -const next = (currentKeyword, reset) => { - return findNext(currentKeyword, reset, false); -}; - -const prev = (currentKeyword, reset) => { - return findNext(currentKeyword, reset, true); -}; - -export { next, prev }; diff --git a/src/content/actions/find.ts b/src/content/actions/find.ts new file mode 100644 index 0000000..e08d7e5 --- /dev/null +++ b/src/content/actions/find.ts @@ -0,0 +1,68 @@ +// +// window.find(aString, aCaseSensitive, aBackwards, aWrapAround, +// aWholeWord, aSearchInFrames); +// +// NOTE: window.find is not standard API +// https://developer.mozilla.org/en-US/docs/Web/API/Window/find + +import messages from 'shared/messages'; +import actions from 'content/actions'; +import * as consoleFrames from '../console-frames'; + +const find = (string, backwards) => { + let caseSensitive = false; + let wrapScan = true; + + + // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work + // because of same origin policy + let found = window.find(string, caseSensitive, backwards, wrapScan); + if (found) { + return found; + } + window.getSelection().removeAllRanges(); + return window.find(string, caseSensitive, backwards, wrapScan); +}; + +const findNext = async(currentKeyword, reset, backwards) => { + if (reset) { + window.getSelection().removeAllRanges(); + } + + let keyword = currentKeyword; + if (currentKeyword) { + browser.runtime.sendMessage({ + type: messages.FIND_SET_KEYWORD, + keyword: currentKeyword, + }); + } else { + keyword = await browser.runtime.sendMessage({ + type: messages.FIND_GET_KEYWORD, + }); + } + if (!keyword) { + return consoleFrames.postError('No previous search keywords'); + } + let found = find(keyword, backwards); + if (found) { + consoleFrames.postInfo('Pattern found: ' + keyword); + } else { + consoleFrames.postError('Pattern not found: ' + keyword); + } + + return { + type: actions.FIND_SET_KEYWORD, + keyword, + found, + }; +}; + +const next = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, false); +}; + +const prev = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, true); +}; + +export { next, prev }; diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.js deleted file mode 100644 index 006b248..0000000 --- a/src/content/actions/follow-controller.js +++ /dev/null @@ -1,30 +0,0 @@ -import actions from 'content/actions'; - -const enable = (newTab, background) => { - return { - type: actions.FOLLOW_CONTROLLER_ENABLE, - newTab, - background, - }; -}; - -const disable = () => { - return { - type: actions.FOLLOW_CONTROLLER_DISABLE, - }; -}; - -const keyPress = (key) => { - return { - type: actions.FOLLOW_CONTROLLER_KEY_PRESS, - key: key - }; -}; - -const backspace = () => { - return { - type: actions.FOLLOW_CONTROLLER_BACKSPACE, - }; -}; - -export { enable, disable, keyPress, backspace }; diff --git a/src/content/actions/follow-controller.ts b/src/content/actions/follow-controller.ts new file mode 100644 index 0000000..006b248 --- /dev/null +++ b/src/content/actions/follow-controller.ts @@ -0,0 +1,30 @@ +import actions from 'content/actions'; + +const enable = (newTab, background) => { + return { + type: actions.FOLLOW_CONTROLLER_ENABLE, + newTab, + background, + }; +}; + +const disable = () => { + return { + type: actions.FOLLOW_CONTROLLER_DISABLE, + }; +}; + +const keyPress = (key) => { + return { + type: actions.FOLLOW_CONTROLLER_KEY_PRESS, + key: key + }; +}; + +const backspace = () => { + return { + type: actions.FOLLOW_CONTROLLER_BACKSPACE, + }; +}; + +export { enable, disable, keyPress, backspace }; diff --git a/src/content/actions/index.js b/src/content/actions/index.js deleted file mode 100644 index 0a16fdf..0000000 --- a/src/content/actions/index.js +++ /dev/null @@ -1,31 +0,0 @@ -export default { - // Enable/disable - ADDON_SET_ENABLED: 'addon.set.enabled', - - // Settings - SETTING_SET: 'setting.set', - - // User input - INPUT_KEY_PRESS: 'input.key.press', - INPUT_CLEAR_KEYS: 'input.clear.keys', - - // Completion - COMPLETION_SET_ITEMS: 'completion.set.items', - COMPLETION_SELECT_NEXT: 'completions.select.next', - COMPLETION_SELECT_PREV: 'completions.select.prev', - - // Follow - FOLLOW_CONTROLLER_ENABLE: 'follow.controller.enable', - FOLLOW_CONTROLLER_DISABLE: 'follow.controller.disable', - FOLLOW_CONTROLLER_KEY_PRESS: 'follow.controller.key.press', - FOLLOW_CONTROLLER_BACKSPACE: 'follow.controller.backspace', - - // Find - FIND_SET_KEYWORD: 'find.set.keyword', - - // Mark - MARK_START_SET: 'mark.start.set', - MARK_START_JUMP: 'mark.start.jump', - MARK_CANCEL: 'mark.cancel', - MARK_SET_LOCAL: 'mark.set.local', -}; diff --git a/src/content/actions/index.ts b/src/content/actions/index.ts new file mode 100644 index 0000000..0a16fdf --- /dev/null +++ b/src/content/actions/index.ts @@ -0,0 +1,31 @@ +export default { + // Enable/disable + ADDON_SET_ENABLED: 'addon.set.enabled', + + // Settings + SETTING_SET: 'setting.set', + + // User input + INPUT_KEY_PRESS: 'input.key.press', + INPUT_CLEAR_KEYS: 'input.clear.keys', + + // Completion + COMPLETION_SET_ITEMS: 'completion.set.items', + COMPLETION_SELECT_NEXT: 'completions.select.next', + COMPLETION_SELECT_PREV: 'completions.select.prev', + + // Follow + FOLLOW_CONTROLLER_ENABLE: 'follow.controller.enable', + FOLLOW_CONTROLLER_DISABLE: 'follow.controller.disable', + FOLLOW_CONTROLLER_KEY_PRESS: 'follow.controller.key.press', + FOLLOW_CONTROLLER_BACKSPACE: 'follow.controller.backspace', + + // Find + FIND_SET_KEYWORD: 'find.set.keyword', + + // Mark + MARK_START_SET: 'mark.start.set', + MARK_START_JUMP: 'mark.start.jump', + MARK_CANCEL: 'mark.cancel', + MARK_SET_LOCAL: 'mark.set.local', +}; diff --git a/src/content/actions/input.js b/src/content/actions/input.js deleted file mode 100644 index 465a486..0000000 --- a/src/content/actions/input.js +++ /dev/null @@ -1,16 +0,0 @@ -import actions from 'content/actions'; - -const keyPress = (key) => { - return { - type: actions.INPUT_KEY_PRESS, - key, - }; -}; - -const clearKeys = () => { - return { - type: actions.INPUT_CLEAR_KEYS - }; -}; - -export { keyPress, clearKeys }; diff --git a/src/content/actions/input.ts b/src/content/actions/input.ts new file mode 100644 index 0000000..465a486 --- /dev/null +++ b/src/content/actions/input.ts @@ -0,0 +1,16 @@ +import actions from 'content/actions'; + +const keyPress = (key) => { + return { + type: actions.INPUT_KEY_PRESS, + key, + }; +}; + +const clearKeys = () => { + return { + type: actions.INPUT_CLEAR_KEYS + }; +}; + +export { keyPress, clearKeys }; diff --git a/src/content/actions/mark.js b/src/content/actions/mark.js deleted file mode 100644 index 712a811..0000000 --- a/src/content/actions/mark.js +++ /dev/null @@ -1,46 +0,0 @@ -import actions from 'content/actions'; -import messages from 'shared/messages'; - -const startSet = () => { - return { type: actions.MARK_START_SET }; -}; - -const startJump = () => { - return { type: actions.MARK_START_JUMP }; -}; - -const cancel = () => { - return { type: actions.MARK_CANCEL }; -}; - -const setLocal = (key, x, y) => { - return { - type: actions.MARK_SET_LOCAL, - key, - x, - y, - }; -}; - -const setGlobal = (key, x, y) => { - browser.runtime.sendMessage({ - type: messages.MARK_SET_GLOBAL, - key, - x, - y, - }); - return { type: '' }; -}; - -const jumpGlobal = (key) => { - browser.runtime.sendMessage({ - type: messages.MARK_JUMP_GLOBAL, - key, - }); - return { type: '' }; -}; - -export { - startSet, startJump, cancel, setLocal, - setGlobal, jumpGlobal, -}; diff --git a/src/content/actions/mark.ts b/src/content/actions/mark.ts new file mode 100644 index 0000000..712a811 --- /dev/null +++ b/src/content/actions/mark.ts @@ -0,0 +1,46 @@ +import actions from 'content/actions'; +import messages from 'shared/messages'; + +const startSet = () => { + return { type: actions.MARK_START_SET }; +}; + +const startJump = () => { + return { type: actions.MARK_START_JUMP }; +}; + +const cancel = () => { + return { type: actions.MARK_CANCEL }; +}; + +const setLocal = (key, x, y) => { + return { + type: actions.MARK_SET_LOCAL, + key, + x, + y, + }; +}; + +const setGlobal = (key, x, y) => { + browser.runtime.sendMessage({ + type: messages.MARK_SET_GLOBAL, + key, + x, + y, + }); + return { type: '' }; +}; + +const jumpGlobal = (key) => { + browser.runtime.sendMessage({ + type: messages.MARK_JUMP_GLOBAL, + key, + }); + return { type: '' }; +}; + +export { + startSet, startJump, cancel, setLocal, + setGlobal, jumpGlobal, +}; diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js deleted file mode 100644 index ed9b2cf..0000000 --- a/src/content/actions/operation.js +++ /dev/null @@ -1,104 +0,0 @@ -import operations from 'shared/operations'; -import messages from 'shared/messages'; -import * as scrolls from 'content/scrolls'; -import * as navigates from 'content/navigates'; -import * as focuses from 'content/focuses'; -import * as urls from 'content/urls'; -import * as consoleFrames from 'content/console-frames'; -import * as addonActions from './addon'; -import * as markActions from './mark'; -import * as properties from 'shared/settings/properties'; - -// eslint-disable-next-line complexity, max-lines-per-function -const exec = (operation, settings, addonEnabled) => { - let smoothscroll = settings.properties.smoothscroll || - properties.defaults.smoothscroll; - switch (operation.type) { - case operations.ADDON_ENABLE: - return addonActions.enable(); - case operations.ADDON_DISABLE: - return addonActions.disable(); - case operations.ADDON_TOGGLE_ENABLED: - return addonActions.setEnabled(!addonEnabled); - case operations.FIND_NEXT: - window.top.postMessage(JSON.stringify({ - type: messages.FIND_NEXT, - }), '*'); - break; - case operations.FIND_PREV: - window.top.postMessage(JSON.stringify({ - type: messages.FIND_PREV, - }), '*'); - break; - case operations.SCROLL_VERTICALLY: - scrolls.scrollVertically(operation.count, smoothscroll); - break; - case operations.SCROLL_HORIZONALLY: - scrolls.scrollHorizonally(operation.count, smoothscroll); - break; - case operations.SCROLL_PAGES: - scrolls.scrollPages(operation.count, smoothscroll); - break; - case operations.SCROLL_TOP: - scrolls.scrollToTop(smoothscroll); - break; - case operations.SCROLL_BOTTOM: - scrolls.scrollToBottom(smoothscroll); - break; - case operations.SCROLL_HOME: - scrolls.scrollToHome(smoothscroll); - break; - case operations.SCROLL_END: - scrolls.scrollToEnd(smoothscroll); - break; - case operations.FOLLOW_START: - window.top.postMessage(JSON.stringify({ - type: messages.FOLLOW_START, - newTab: operation.newTab, - background: operation.background, - }), '*'); - break; - case operations.MARK_SET_PREFIX: - return markActions.startSet(); - case operations.MARK_JUMP_PREFIX: - return markActions.startJump(); - case operations.NAVIGATE_HISTORY_PREV: - navigates.historyPrev(window); - break; - case operations.NAVIGATE_HISTORY_NEXT: - navigates.historyNext(window); - break; - case operations.NAVIGATE_LINK_PREV: - navigates.linkPrev(window); - break; - case operations.NAVIGATE_LINK_NEXT: - navigates.linkNext(window); - break; - case operations.NAVIGATE_PARENT: - navigates.parent(window); - break; - case operations.NAVIGATE_ROOT: - navigates.root(window); - break; - case operations.FOCUS_INPUT: - focuses.focusInput(); - break; - case operations.URLS_YANK: - urls.yank(window); - consoleFrames.postInfo('Yanked ' + window.location.href); - break; - case operations.URLS_PASTE: - urls.paste( - window, operation.newTab ? operation.newTab : false, settings.search - ); - break; - default: - browser.runtime.sendMessage({ - type: messages.BACKGROUND_OPERATION, - operation, - }); - } - return { type: '' }; -}; - -export { exec }; diff --git a/src/content/actions/operation.ts b/src/content/actions/operation.ts new file mode 100644 index 0000000..ed9b2cf --- /dev/null +++ b/src/content/actions/operation.ts @@ -0,0 +1,104 @@ +import operations from 'shared/operations'; +import messages from 'shared/messages'; +import * as scrolls from 'content/scrolls'; +import * as navigates from 'content/navigates'; +import * as focuses from 'content/focuses'; +import * as urls from 'content/urls'; +import * as consoleFrames from 'content/console-frames'; +import * as addonActions from './addon'; +import * as markActions from './mark'; +import * as properties from 'shared/settings/properties'; + +// eslint-disable-next-line complexity, max-lines-per-function +const exec = (operation, settings, addonEnabled) => { + let smoothscroll = settings.properties.smoothscroll || + properties.defaults.smoothscroll; + switch (operation.type) { + case operations.ADDON_ENABLE: + return addonActions.enable(); + case operations.ADDON_DISABLE: + return addonActions.disable(); + case operations.ADDON_TOGGLE_ENABLED: + return addonActions.setEnabled(!addonEnabled); + case operations.FIND_NEXT: + window.top.postMessage(JSON.stringify({ + type: messages.FIND_NEXT, + }), '*'); + break; + case operations.FIND_PREV: + window.top.postMessage(JSON.stringify({ + type: messages.FIND_PREV, + }), '*'); + break; + case operations.SCROLL_VERTICALLY: + scrolls.scrollVertically(operation.count, smoothscroll); + break; + case operations.SCROLL_HORIZONALLY: + scrolls.scrollHorizonally(operation.count, smoothscroll); + break; + case operations.SCROLL_PAGES: + scrolls.scrollPages(operation.count, smoothscroll); + break; + case operations.SCROLL_TOP: + scrolls.scrollToTop(smoothscroll); + break; + case operations.SCROLL_BOTTOM: + scrolls.scrollToBottom(smoothscroll); + break; + case operations.SCROLL_HOME: + scrolls.scrollToHome(smoothscroll); + break; + case operations.SCROLL_END: + scrolls.scrollToEnd(smoothscroll); + break; + case operations.FOLLOW_START: + window.top.postMessage(JSON.stringify({ + type: messages.FOLLOW_START, + newTab: operation.newTab, + background: operation.background, + }), '*'); + break; + case operations.MARK_SET_PREFIX: + return markActions.startSet(); + case operations.MARK_JUMP_PREFIX: + return markActions.startJump(); + case operations.NAVIGATE_HISTORY_PREV: + navigates.historyPrev(window); + break; + case operations.NAVIGATE_HISTORY_NEXT: + navigates.historyNext(window); + break; + case operations.NAVIGATE_LINK_PREV: + navigates.linkPrev(window); + break; + case operations.NAVIGATE_LINK_NEXT: + navigates.linkNext(window); + break; + case operations.NAVIGATE_PARENT: + navigates.parent(window); + break; + case operations.NAVIGATE_ROOT: + navigates.root(window); + break; + case operations.FOCUS_INPUT: + focuses.focusInput(); + break; + case operations.URLS_YANK: + urls.yank(window); + consoleFrames.postInfo('Yanked ' + window.location.href); + break; + case operations.URLS_PASTE: + urls.paste( + window, operation.newTab ? operation.newTab : false, settings.search + ); + break; + default: + browser.runtime.sendMessage({ + type: messages.BACKGROUND_OPERATION, + operation, + }); + } + return { type: '' }; +}; + +export { exec }; diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js deleted file mode 100644 index 1c15dd7..0000000 --- a/src/content/actions/setting.js +++ /dev/null @@ -1,37 +0,0 @@ -import actions from 'content/actions'; -import * as keyUtils from 'shared/utils/keys'; -import operations from 'shared/operations'; -import messages from 'shared/messages'; - -const reservedKeymaps = { - '': { type: operations.CANCEL }, - '': { type: operations.CANCEL }, -}; - -const set = (value) => { - let entries = []; - if (value.keymaps) { - let keymaps = { ...value.keymaps, ...reservedKeymaps }; - entries = Object.entries(keymaps).map((entry) => { - return [ - keyUtils.fromMapKeys(entry[0]), - entry[1], - ]; - }); - } - - return { - type: actions.SETTING_SET, - value: { ...value, - keymaps: entries, } - }; -}; - -const load = async() => { - let settings = await browser.runtime.sendMessage({ - type: messages.SETTINGS_QUERY, - }); - return set(settings); -}; - -export { set, load }; diff --git a/src/content/actions/setting.ts b/src/content/actions/setting.ts new file mode 100644 index 0000000..1c15dd7 --- /dev/null +++ b/src/content/actions/setting.ts @@ -0,0 +1,37 @@ +import actions from 'content/actions'; +import * as keyUtils from 'shared/utils/keys'; +import operations from 'shared/operations'; +import messages from 'shared/messages'; + +const reservedKeymaps = { + '': { type: operations.CANCEL }, + '': { type: operations.CANCEL }, +}; + +const set = (value) => { + let entries = []; + if (value.keymaps) { + let keymaps = { ...value.keymaps, ...reservedKeymaps }; + entries = Object.entries(keymaps).map((entry) => { + return [ + keyUtils.fromMapKeys(entry[0]), + entry[1], + ]; + }); + } + + return { + type: actions.SETTING_SET, + value: { ...value, + keymaps: entries, } + }; +}; + +const load = async() => { + let settings = await browser.runtime.sendMessage({ + type: messages.SETTINGS_QUERY, + }); + return set(settings); +}; + +export { set, load }; -- cgit v1.2.3