From 764d7a34bda121f97e947861c41722a12af37b15 Mon Sep 17 00:00:00 2001 From: usk Date: Sun, 5 Nov 2017 10:06:26 +0900 Subject: add support for following some buttons on mobile.twitter.com The buttons are: * reply * retweet * favorite * direct message * drop down menu --- src/content/components/common/follow.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/content/components') diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 83aeb0a..15b2a98 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -4,7 +4,8 @@ import * as dom from 'shared/utils/dom'; const TARGET_SELECTOR = [ 'a', 'button', 'input', 'textarea', 'area', - '[contenteditable=true]', '[contenteditable=""]', '[tabindex]' + '[contenteditable=true]', '[contenteditable=""]', '[tabindex]', + '[role="button"]' ].join(','); -- cgit v1.2.3 From 177940981ed9c4f096ad7db20f0b7ee044fd7b17 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Thu, 16 Nov 2017 13:03:38 +0000 Subject: Open adjacent tabs and background tabs --- src/background/actions/tab.js | 6 +----- src/background/components/background.js | 3 ++- src/content/actions/follow-controller.js | 3 ++- src/content/actions/operation.js | 3 ++- src/content/components/common/follow.js | 8 ++++++-- .../components/top-content/follow-controller.js | 3 ++- src/content/reducers/follow-controller.js | 2 ++ src/shared/commands.js | 20 ++++++++++++++++---- src/shared/default-settings.js | 7 ++++--- src/shared/validators/setting.js | 2 +- 10 files changed, 38 insertions(+), 19 deletions(-) (limited to 'src/content/components') diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js index e512b6f..d996b9f 100644 --- a/src/background/actions/tab.js +++ b/src/background/actions/tab.js @@ -1,9 +1,5 @@ -const openNewTab = (url) => { - return browser.tabs.create({ url: url }); -}; - const openToTab = (url, tab) => { return browser.tabs.update(tab.id, { url: url }); }; -export { openToTab, openNewTab }; +export { openToTab }; diff --git a/src/background/components/background.js b/src/background/components/background.js index 2d94310..6026684 100644 --- a/src/background/components/background.js +++ b/src/background/components/background.js @@ -30,7 +30,8 @@ export default class BackgroundComponent { case messages.OPEN_URL: if (message.newTab) { return this.store.dispatch( - tabActions.openNewTab(message.url), sender); + commands.tabopenCommand(message.url, message.background, + settings.value.openAdjacentTabs), sender); } return this.store.dispatch( tabActions.openToTab(message.url, sender.tab), sender); diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.js index 3fd4dce..006b248 100644 --- a/src/content/actions/follow-controller.js +++ b/src/content/actions/follow-controller.js @@ -1,9 +1,10 @@ import actions from 'content/actions'; -const enable = (newTab) => { +const enable = (newTab, background) => { return { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab, + background, }; }; diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 767f14b..5c8fe83 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -40,7 +40,8 @@ const exec = (operation) => { case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, - newTab: operation.newTab + newTab: operation.newTab, + background: operation.background, }), '*'); case operations.NAVIGATE_HISTORY_PREV: return navigates.historyPrev(window); diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 7a35105..43f2ea1 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -34,6 +34,7 @@ export default class Follow { this.win = win; this.store = store; this.newTab = false; + this.background = false; this.hints = {}; this.targets = []; @@ -68,6 +69,7 @@ export default class Follow { type: messages.OPEN_URL, url: element.href, newTab: true, + background: this.background, }); } @@ -79,12 +81,13 @@ export default class Follow { }), '*'); } - createHints(keysArray, newTab) { + createHints(keysArray, newTab, background) { if (keysArray.length !== this.targets.length) { throw new Error('illegal hint count'); } this.newTab = newTab; + this.background = background; this.hints = {}; for (let i = 0; i < keysArray.length; ++i) { let keys = keysArray[i]; @@ -150,7 +153,8 @@ export default class Follow { case messages.FOLLOW_REQUEST_COUNT_TARGETS: return this.countHints(sender, message.viewSize, message.framePosition); case messages.FOLLOW_CREATE_HINTS: - return this.createHints(message.keysArray, message.newTab); + return this.createHints( + message.keysArray, message.newTab, message.background); case messages.FOLLOW_SHOW_HINTS: return this.showHints(message.keys); case messages.FOLLOW_ACTIVATE: diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.js index d373177..f759c8c 100644 --- a/src/content/components/top-content/follow-controller.js +++ b/src/content/components/top-content/follow-controller.js @@ -29,7 +29,7 @@ export default class FollowController { switch (message.type) { case messages.FOLLOW_START: return this.store.dispatch( - followControllerActions.enable(message.newTab)); + followControllerActions.enable(message.newTab, message.background)); case messages.FOLLOW_RESPONSE_COUNT_TARGETS: return this.create(message.count, sender); case messages.FOLLOW_KEY_PRESS: @@ -126,6 +126,7 @@ export default class FollowController { type: messages.FOLLOW_CREATE_HINTS, keysArray: produced, newTab: this.state.newTab, + background: this.state.background, }), '*'); } diff --git a/src/content/reducers/follow-controller.js b/src/content/reducers/follow-controller.js index 2afb232..78fd848 100644 --- a/src/content/reducers/follow-controller.js +++ b/src/content/reducers/follow-controller.js @@ -3,6 +3,7 @@ import actions from 'content/actions'; const defaultState = { enabled: false, newTab: false, + background: false, keys: '', }; @@ -12,6 +13,7 @@ export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { enabled: true, newTab: action.newTab, + background: action.background, keys: '', }); case actions.FOLLOW_CONTROLLER_DISABLE: diff --git a/src/shared/commands.js b/src/shared/commands.js index 8edeb5c..bcad313 100644 --- a/src/shared/commands.js +++ b/src/shared/commands.js @@ -33,8 +33,19 @@ const openCommand = (url) => { }); }; -const tabopenCommand = (url) => { - return browser.tabs.create({ url: url }); +const tabopenCommand = (url, background = false, adjacent = false) => { + if (adjacent) { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((gotTabs) => { + return browser.tabs.create({ + url: url, + active: !background, + index: gotTabs[0].index + 1 + }); + }); + } + return browser.tabs.create({ url: url, active: !background }); }; const winopenCommand = (url) => { @@ -102,7 +113,8 @@ const doCommand = (line, settings) => { return openCommand(normalizeUrl(words, settings.search)); case 't': case 'tabopen': - return tabopenCommand(normalizeUrl(words, settings.search)); + return tabopenCommand( + normalizeUrl(words, settings.search), false, settings.openAdjacentTabs); case 'w': case 'winopen': return winopenCommand(normalizeUrl(words, settings.search)); @@ -166,4 +178,4 @@ const complete = (line, settings) => { return getCompletions(line, settings); }; -export { exec, complete }; +export { exec, complete, tabopenCommand }; diff --git a/src/shared/default-settings.js b/src/shared/default-settings.js index 608890b..d691859 100644 --- a/src/shared/default-settings.js +++ b/src/shared/default-settings.js @@ -37,8 +37,8 @@ export default { "zi": { "type": "zoom.in" }, "zo": { "type": "zoom.out" }, "zz": { "type": "zoom.neutral" }, - "f": { "type": "follow.start", "newTab": false }, - "F": { "type": "follow.start", "newTab": true }, + "f": { "type": "follow.start", "newTab": false, "background": false }, + "F": { "type": "follow.start", "newTab": true, "background": false }, "H": { "type": "navigate.history.prev" }, "L": { "type": "navigate.history.next" }, "[[": { "type": "navigate.link.prev" }, @@ -61,6 +61,7 @@ export default { "twitter": "https://twitter.com/search?q={}", "wikipedia": "https://en.wikipedia.org/w/index.php?search={}" } - } + }, + "openAdjacentTabs": false }` }; diff --git a/src/shared/validators/setting.js b/src/shared/validators/setting.js index 949ab29..5fe75b2 100644 --- a/src/shared/validators/setting.js +++ b/src/shared/validators/setting.js @@ -1,6 +1,6 @@ import operations from 'shared/operations'; -const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist']; +const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'openAdjacentTabs']; const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => { return operations[key]; }); -- cgit v1.2.3 From de7883329bb3d2a5a5a12cd278970b04107a0097 Mon Sep 17 00:00:00 2001 From: usk Date: Sun, 24 Dec 2017 06:14:17 +0900 Subject: do not follow link which has aria-hidden attribute or aria-disabled attribute --- src/content/components/common/follow.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/content/components') diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 7717154..42dd897 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -30,6 +30,21 @@ const inViewport = (win, element, viewSize, framePosition) => { return true; }; +const isAriaHiddenOrAriaDisabled = (win, element) => { + if (!element || win.document.documentElement === element) { + return false; + } + for (let attr of ['aria-hidden', 'aria-disabled']) { + if (element.hasAttribute(attr)) { + let hidden = element.getAttribute(attr).toLowerCase(); + if (hidden === '' || hidden === 'true') { + return true; + } + } + } + return isAriaHiddenOrAriaDisabled(win, element.parentNode); +}; + export default class Follow { constructor(win, store) { this.win = win; @@ -171,6 +186,7 @@ export default class Follow { style.visibility !== 'hidden' && element.type !== 'hidden' && element.offsetHeight > 0 && + !isAriaHiddenOrAriaDisabled(win, element) && inViewport(win, element, viewSize, framePosition); }); return filtered; -- cgit v1.2.3 From 03bb124cce7acf3a245baca1c109e5136979162e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 11 Jan 2018 21:52:07 +0900 Subject: support custom chars as hintchars --- src/content/components/top-content/follow-controller.js | 12 ++++++++---- src/shared/settings/properties.js | 15 +++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/content/components') diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.js index d373177..1e7f3cd 100644 --- a/src/content/components/top-content/follow-controller.js +++ b/src/content/components/top-content/follow-controller.js @@ -1,8 +1,7 @@ import * as followControllerActions from 'content/actions/follow-controller'; import messages from 'shared/messages'; import HintKeyProducer from 'content/hint-key-producer'; - -const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz'; +import * as properties from 'shared/settings/properties'; const broadcastMessage = (win, message) => { let json = JSON.stringify(message); @@ -84,7 +83,7 @@ export default class FollowController { this.store.dispatch(followControllerActions.backspace()); break; default: - if (DEFAULT_HINT_CHARSET.includes(key)) { + if (this.hintchars().includes(key)) { this.store.dispatch(followControllerActions.keyPress(key)); } break; @@ -93,7 +92,7 @@ export default class FollowController { } count() { - this.producer = new HintKeyProducer(DEFAULT_HINT_CHARSET); + this.producer = new HintKeyProducer(this.hintchars()); let doc = this.win.document; let viewWidth = this.win.innerWidth || doc.documentElement.clientWidth; let viewHeight = this.win.innerHeight || doc.documentElement.clientHeight; @@ -135,4 +134,9 @@ export default class FollowController { type: messages.FOLLOW_REMOVE_HINTS, }); } + + hintchars() { + return this.store.getState().setting.properties.hintchars || + properties.defaults.hintchars; + } } diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index ff8039b..f695c58 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -1,15 +1,14 @@ +// describe types of a propety as: +// mystr: 'string', +// mynum: 'number', +// mybool: 'boolean', const types = { - // TODO describe property types here - // mystr: 'string', - // mynum: 'number', - // mybool: 'boolean', + hintchars: 'string', }; +// describe default values of a property const defaults = { - // TODO describe property defaults values - // mystr: 'hello', - // mynum: 123, - // mybool: true, + hintchars: 'abcdefghijklmnopqrstuvwxyz', }; export { types, defaults }; -- cgit v1.2.3 From 2ca1b54faacb261e5a25331e030da13d07c09662 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 15:31:39 +0900 Subject: add smoothscroll property --- src/content/actions/operation.js | 19 +++++++++------- src/content/components/common/keymapper.js | 2 +- src/content/scrolls.js | 36 ++++++++++++++++++------------ src/shared/settings/properties.js | 2 ++ 4 files changed, 36 insertions(+), 23 deletions(-) (limited to 'src/content/components') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 8157127..d2e258c 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -5,9 +5,12 @@ import * as navigates from 'content/navigates'; import * as urls from 'content/urls'; import * as consoleFrames from 'content/console-frames'; import * as addonActions from './addon'; +import * as properties from 'shared/settings/properties'; // eslint-disable-next-line complexity -const exec = (operation) => { +const exec = (operation, settings) => { + let smoothscroll = settings.properties.smoothscroll || + properties.defaults.smoothscroll; switch (operation.type) { case operations.ADDON_ENABLE: return addonActions.enable(); @@ -24,19 +27,19 @@ const exec = (operation) => { type: messages.FIND_PREV, }), '*'); case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(operation.count); + return scrolls.scrollVertically(operation.count, smoothscroll); case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(operation.count); + return scrolls.scrollHorizonally(operation.count, smoothscroll); case operations.SCROLL_PAGES: - return scrolls.scrollPages(operation.count); + return scrolls.scrollPages(operation.count, smoothscroll); case operations.SCROLL_TOP: - return scrolls.scrollTop(); + return scrolls.scrollTop(smoothscroll); case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(); + return scrolls.scrollBottom(smoothscroll); case operations.SCROLL_HOME: - return scrolls.scrollHome(); + return scrolls.scrollHome(smoothscroll); case operations.SCROLL_END: - return scrolls.scrollEnd(); + return scrolls.scrollEnd(smoothscroll); case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index fb8fabe..fa8c33a 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -47,7 +47,7 @@ export default class KeymapperComponent { return true; } let operation = keymaps.get(matched[0]); - this.store.dispatch(operationActions.exec(operation)); + this.store.dispatch(operationActions.exec(operation, state.setting)); this.store.dispatch(inputActions.clearKeys()); return true; } diff --git a/src/content/scrolls.js b/src/content/scrolls.js index 8daa36f..5aef1df 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -108,54 +108,62 @@ const roughScroll = (element, x, y) => { element.scrollTo(x, y); }; -const scrollVertically = (count) => { +const scroll = (element, x, y, smooth) => { + if (smooth) { + smoothScroll(element, x, y); + } else { + roughScroll(element, x, y); + } +}; + +const scrollVertically = (count, smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollTop + SCROLL_DELTA_Y * count; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollHorizonally = (count) => { +const scrollHorizonally = (count, smooth) => { let target = scrollTarget(); let x = target.scrollLeft + SCROLL_DELTA_X * count; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollPages = (count) => { +const scrollPages = (count, smooth) => { let target = scrollTarget(); let height = target.clientHeight; let x = target.scrollLeft; let y = target.scrollTop + height * count; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollTop = () => { +const scrollTop = (smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = 0; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollBottom = () => { +const scrollBottom = (smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollHeight; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollHome = () => { +const scrollHome = (smooth) => { let target = scrollTarget(); let x = 0; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollEnd = () => { +const scrollEnd = (smooth) => { let target = scrollTarget(); let x = target.scrollWidth; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; export { diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index f695c58..37dc881 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -4,11 +4,13 @@ // mybool: 'boolean', const types = { hintchars: 'string', + smoothscroll: 'boolean', }; // describe default values of a property const defaults = { hintchars: 'abcdefghijklmnopqrstuvwxyz', + smoothscroll: false, }; export { types, defaults }; -- cgit v1.2.3 From 335b9ca47458b1817ef7705f4d999c25f423fad9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 19:49:11 +0900 Subject: fix smooth scroll on key repeated --- src/content/actions/operation.js | 16 ++++---- src/content/components/common/keymapper.js | 3 +- src/content/scrolls.js | 63 +++++++++++++++++++++--------- src/shared/utils/keys.js | 1 + 4 files changed, 55 insertions(+), 28 deletions(-) (limited to 'src/content/components') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index d2e258c..1c0a5fb 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -8,7 +8,7 @@ import * as addonActions from './addon'; import * as properties from 'shared/settings/properties'; // eslint-disable-next-line complexity -const exec = (operation, settings) => { +const exec = (operation, repeat, settings) => { let smoothscroll = settings.properties.smoothscroll || properties.defaults.smoothscroll; switch (operation.type) { @@ -27,19 +27,19 @@ const exec = (operation, settings) => { type: messages.FIND_PREV, }), '*'); case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(operation.count, smoothscroll); + return scrolls.scrollVertically(operation.count, smoothscroll, repeat); case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(operation.count, smoothscroll); + return scrolls.scrollHorizonally(operation.count, smoothscroll, repeat); case operations.SCROLL_PAGES: - return scrolls.scrollPages(operation.count, smoothscroll); + return scrolls.scrollPages(operation.count, smoothscroll, repeat); case operations.SCROLL_TOP: - return scrolls.scrollTop(smoothscroll); + return scrolls.scrollTop(smoothscroll, repeat); case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(smoothscroll); + return scrolls.scrollBottom(smoothscroll, repeat); case operations.SCROLL_HOME: - return scrolls.scrollHome(smoothscroll); + return scrolls.scrollHome(smoothscroll, repeat); case operations.SCROLL_END: - return scrolls.scrollEnd(smoothscroll); + return scrolls.scrollEnd(smoothscroll, repeat); case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index fa8c33a..d9d1b2f 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -47,7 +47,8 @@ export default class KeymapperComponent { return true; } let operation = keymaps.get(matched[0]); - this.store.dispatch(operationActions.exec(operation, state.setting)); + this.store.dispatch(operationActions.exec( + operation, key.repeat, state.setting)); this.store.dispatch(inputActions.clearKeys()); return true; } diff --git a/src/content/scrolls.js b/src/content/scrolls.js index 2fe06c0..e8e9642 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -2,6 +2,9 @@ const SCROLL_DELTA_X = 48; const SCROLL_DELTA_Y = 48; const SMOOTH_SCROLL_DURATION = 150; +// dirty way to store scrolling state on globally +let scrolling = [false]; + const isVisible = (element) => { let rect = element.getBoundingClientRect(); if (rect.width === 0 || rect.height === 0) { @@ -67,11 +70,23 @@ const scrollTarget = () => { }; class SmoothScroller { - constructor(element) { + constructor(element, repeat) { this.element = element; + this.repeat = repeat; + this.scrolling = scrolling; + if (repeat) { + this.easing = SmoothScroller.linearEasing; + } else { + this.easing = SmoothScroller.inOutQuadEasing; + } } scroll(x, y) { + if (this.scrolling[0]) { + return; + } + scrolling[0] = true; + this.startX = this.element.scrollLeft; this.startY = this.element.scrollTop; @@ -99,17 +114,21 @@ class SmoothScroller { if (elapsed < SMOOTH_SCROLL_DURATION) { window.requestAnimationFrame(this.loop.bind(this)); } else { + scrolling[0] = false; this.element.scrollTo(this.targetX, this.targetY); } } - // in-out quad easing - easing(t) { + static inOutQuadEasing(t) { if (t < 1) { return t * t; } return -(t - 1) * (t - 1) + 1; } + + static linearEasing(t) { + return t; + } } class RoughtScroller { @@ -122,61 +141,67 @@ class RoughtScroller { } } -const scroller = (element, smooth) => { +const scroller = (element, smooth, repeat) => { if (smooth) { - return new SmoothScroller(element); + return new SmoothScroller(element, repeat); } return new RoughtScroller(element); }; -const scrollVertically = (count, smooth) => { +const scrollVertically = (count, smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollTop + SCROLL_DELTA_Y * count; - scroller(target, smooth).scroll(x, y); + if (repeat && smooth) { + y = target.scrollTop + SCROLL_DELTA_Y * count * 4; + } + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollHorizonally = (count, smooth) => { +const scrollHorizonally = (count, smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft + SCROLL_DELTA_X * count; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + if (repeat && smooth) { + y = target.scrollTop + SCROLL_DELTA_Y * count * 4; + } + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollPages = (count, smooth) => { +const scrollPages = (count, smooth, repeat) => { let target = scrollTarget(); let height = target.clientHeight; let x = target.scrollLeft; let y = target.scrollTop + height * count; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollTop = (smooth) => { +const scrollTop = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = 0; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollBottom = (smooth) => { +const scrollBottom = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollHeight; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollHome = (smooth) => { +const scrollHome = (smooth, repeat) => { let target = scrollTarget(); let x = 0; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollEnd = (smooth) => { +const scrollEnd = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollWidth; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; export { diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.js index fba8ce3..8a86dfb 100644 --- a/src/shared/utils/keys.js +++ b/src/shared/utils/keys.js @@ -18,6 +18,7 @@ const fromKeyboardEvent = (e) => { return { key: modifierdKeyName(e.key), + repeat: e.repeat, shiftKey: shift, ctrlKey: e.ctrlKey, altKey: e.altKey, -- cgit v1.2.3 From c69fdbb14a3eb60d5cfd4f6d1816732dbc2b9163 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 26 Feb 2018 21:03:51 +0900 Subject: Cancel key input by --- src/content/components/common/input.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/content/components') diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js index 22b0a91..eefaf10 100644 --- a/src/content/components/common/input.js +++ b/src/content/components/common/input.js @@ -1,6 +1,10 @@ import * as dom from 'shared/utils/dom'; import * as keys from 'shared/utils/keys'; +const cancelKey = (e) => { + return e.key === 'Escape' || e.key === '[' && e.ctrlKey; +}; + export default class InputComponent { constructor(target) { this.pressed = {}; @@ -37,7 +41,7 @@ export default class InputComponent { capture(e) { if (this.fromInput(e)) { - if (e.key === 'Escape' && e.target.blur) { + if (cancelKey(e) && e.target.blur) { e.target.blur(); } return; -- cgit v1.2.3 From 8cc7d472dff5882e4379869345667dd4ba53ca45 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 26 Feb 2018 21:20:13 +0900 Subject: Cancel following by --- src/content/components/common/follow.js | 1 + src/content/components/top-content/follow-controller.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/content/components') diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 42dd897..a8682c5 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -63,6 +63,7 @@ export default class Follow { this.win.parent.postMessage(JSON.stringify({ type: messages.FOLLOW_KEY_PRESS, key: key.key, + ctrlKey: key.ctrlKey, }), '*'); return true; } diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.js index 1e7f3cd..1b5586b 100644 --- a/src/content/components/top-content/follow-controller.js +++ b/src/content/components/top-content/follow-controller.js @@ -32,7 +32,7 @@ export default class FollowController { case messages.FOLLOW_RESPONSE_COUNT_TARGETS: return this.create(message.count, sender); case messages.FOLLOW_KEY_PRESS: - return this.keyPress(message.key); + return this.keyPress(message.key, message.ctrlKey); } } @@ -69,7 +69,11 @@ export default class FollowController { }); } - keyPress(key) { + keyPress(key, ctrlKey) { + if (key === '[' && ctrlKey) { + this.store.dispatch(followControllerActions.disable()); + return true; + } switch (key) { case 'Enter': this.activate(); -- cgit v1.2.3 From 93bd0bc54fd5ce7a2803f2ebc7c834b1b815afda Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 6 Mar 2018 21:37:12 +0900 Subject: show message on find --- src/content/actions/find.js | 12 +++++++++++- src/content/actions/operation.js | 5 +---- src/content/components/top-content/find.js | 8 ++++++++ src/content/console-frames.js | 9 ++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'src/content/components') diff --git a/src/content/actions/find.js b/src/content/actions/find.js index 80d6210..b266216 100644 --- a/src/content/actions/find.js +++ b/src/content/actions/find.js @@ -14,6 +14,13 @@ const postPatternNotFound = (pattern) => { 'Pattern not found: ' + pattern); }; +const postPatternFound = (pattern) => { + return consoleFrames.postInfo( + window.document, + 'Pattern found: ' + pattern, + ); +}; + const find = (string, backwards) => { let caseSensitive = false; let wrapScan = true; @@ -34,9 +41,12 @@ const findNext = (keyword, reset, backwards) => { window.getSelection().removeAllRanges(); found = find(keyword, backwards); } - if (!found) { + if (found) { + postPatternFound(keyword); + } else { postPatternNotFound(keyword); } + return { type: actions.FIND_SET_KEYWORD, keyword, diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 5fd0f48..71b2470 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -62,10 +62,7 @@ const exec = (operation, repeat, settings) => { return focuses.focusInput(); case operations.URLS_YANK: urls.yank(window); - return consoleFrames.postMessage(window.document, { - type: messages.CONSOLE_SHOW_INFO, - text: 'Current url yanked', - }); + return consoleFrames.postInfo(window.document, 'Current url yanked'); case operations.URLS_PASTE: return urls.paste(window, operation.newTab ? operation.newTab : false); default: diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js index bccf040..9967d36 100644 --- a/src/content/components/top-content/find.js +++ b/src/content/components/top-content/find.js @@ -38,6 +38,10 @@ export default class FindComponent { window.document, 'Pattern not found: ' + state.keyword); } + consoleFrames.postInfo( + window.document, + 'Pattern found: ' + state.keyword, + ); return this.store.dispatch(findActions.next(state.keyword, false)); } @@ -49,6 +53,10 @@ export default class FindComponent { window.document, 'Pattern not found: ' + state.keyword); } + consoleFrames.postInfo( + window.document, + 'Pattern found: ' + state.keyword, + ); return this.store.dispatch(findActions.prev(state.keyword, false)); } } diff --git a/src/content/console-frames.js b/src/content/console-frames.js index 515ae09..0c0ec02 100644 --- a/src/content/console-frames.js +++ b/src/content/console-frames.js @@ -28,4 +28,11 @@ const postError = (doc, message) => { }); }; -export { initialize, blur, postMessage, postError }; +const postInfo = (doc, message) => { + return postMessage(doc, { + type: messages.CONSOLE_SHOW_INFO, + text: message, + }); +}; + +export { initialize, blur, postError, postInfo }; -- cgit v1.2.3 From 4923cb20c77e7cc84d8ecdf1b12ee6c204701e71 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 6 Mar 2018 21:59:08 +0900 Subject: remove redundant checks --- src/content/components/top-content/find.js | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/content/components') diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js index 9967d36..4d46d79 100644 --- a/src/content/components/top-content/find.js +++ b/src/content/components/top-content/find.js @@ -1,6 +1,5 @@ import * as findActions from 'content/actions/find'; import messages from 'shared/messages'; -import * as consoleFrames from '../../console-frames'; export default class FindComponent { constructor(win, store) { @@ -32,31 +31,11 @@ export default class FindComponent { next() { let state = this.store.getState().find; - - if (!state.found) { - return consoleFrames.postError( - window.document, - 'Pattern not found: ' + state.keyword); - } - consoleFrames.postInfo( - window.document, - 'Pattern found: ' + state.keyword, - ); return this.store.dispatch(findActions.next(state.keyword, false)); } prev() { let state = this.store.getState().find; - - if (!state.found) { - return consoleFrames.postError( - window.document, - 'Pattern not found: ' + state.keyword); - } - consoleFrames.postInfo( - window.document, - 'Pattern found: ' + state.keyword, - ); return this.store.dispatch(findActions.prev(state.keyword, false)); } } -- cgit v1.2.3