From 1afbde6e199309703f07f2d031632d9d2422a3d5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 23 Aug 2017 21:28:50 +0900 Subject: support history navigation --- src/shared/actions.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/shared/actions.js') diff --git a/src/shared/actions.js b/src/shared/actions.js index bb61dbc..e01813b 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -9,6 +9,8 @@ export const SCROLL_DOWN = 'scroll.down'; export const SCROLL_TOP = 'scroll.top'; export const SCROLL_BOTTOM = 'scroll.bottom'; export const FOLLOW_START = 'follow.start'; +export const HISTORY_PREV = 'history.prev'; +export const HISTORY_NEXT = 'history.next'; const BACKGROUND_ACTION_SET = new Set([ TABS_CLOSE, @@ -24,7 +26,9 @@ const CONTENT_ACTION_SET = new Set([ SCROLL_DOWN, SCROLL_TOP, SCROLL_BOTTOM, - FOLLOW_START + FOLLOW_START, + HISTORY_PREV, + HISTORY_NEXT ]); export const isBackgroundAction = (action) => { -- cgit v1.2.3 From 1f15d2264305a5492f3f95d9fbdaf1e31fbb33fd Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 23 Aug 2017 21:58:58 +0900 Subject: support zi/zo commands --- .eslintrc | 1 - src/background/index.js | 7 +++++++ src/background/key-queue.js | 2 ++ src/background/zooms.js | 34 ++++++++++++++++++++++++++++++++++ src/shared/actions.js | 6 +++++- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/background/zooms.js (limited to 'src/shared/actions.js') diff --git a/.eslintrc b/.eslintrc index 38d7ea9..80fc259 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,6 @@ "multiline-ternary": "off", "max-statements": ["error", 15], "no-console": "off", - "no-magic-numbers": ["error", { "ignore": [0, 1, 2] }], "no-param-reassign": "off", "no-ternary": "off", "object-curly-spacing": [ diff --git a/src/background/index.js b/src/background/index.js index f3bd65a..cfd5e77 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,6 +1,7 @@ import * as actions from '../shared/actions'; import * as tabs from './tabs'; import * as commands from './commands'; +import * as zooms from './zooms'; import KeyQueue from './key-queue'; const queue = new KeyQueue(); @@ -38,6 +39,12 @@ const doBackgroundAction = (sender, action) => { case actions.TABS_NEXT: tabs.selectNextTab(sender.tab.index, actions[1] || 1); break; + case actions.ZOOM_IN: + zooms.zoomIn(); + break; + case actions.ZOOM_OUT: + zooms.zoomOut(); + break; } } diff --git a/src/background/key-queue.js b/src/background/key-queue.js index a07c7f4..6319431 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -13,6 +13,8 @@ const DEFAULT_KEYMAP = [ { keys: [{ code: KeyboardEvent.DOM_VK_U }], action: [ actions.TABS_REOPEN]}, { keys: [{ code: KeyboardEvent.DOM_VK_H }], action: [ actions.TABS_PREV, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_L }], action: [ actions.TABS_NEXT, 1 ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_I }], action: [ actions.ZOOM_IN ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_O }], action: [ actions.ZOOM_OUT ]}, { keys: [{ code: KeyboardEvent.DOM_VK_F }], action: [ actions.FOLLOW_START, false ]}, { keys: [{ code: KeyboardEvent.DOM_VK_F, shift: true }], action: [ actions.FOLLOW_START, true ]}, { keys: [{ code: KeyboardEvent.DOM_VK_H, shift: true }], action: [ actions.HISTORY_PREV ]}, diff --git a/src/background/zooms.js b/src/background/zooms.js new file mode 100644 index 0000000..def2878 --- /dev/null +++ b/src/background/zooms.js @@ -0,0 +1,34 @@ +// For chromium +// const ZOOM_SETTINGS = [ +// 0.25, 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00, +// 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00, 4.00, 5.00 +// ]; + +const ZOOM_SETTINGS = [ + 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00, + 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 +]; + +const zoomIn = (tabId = undefined) => { + browser.tabs.getZoom(tabId).then((factor) => { + for (let f of ZOOM_SETTINGS) { + if (f > factor) { + browser.tabs.setZoom(tabId, f); + break; + } + } + }); +} + +const zoomOut = (tabId = undefined) => { + browser.tabs.getZoom(tabId).then((factor) => { + for (let f of [].concat(ZOOM_SETTINGS).reverse()) { + if (f < factor) { + browser.tabs.setZoom(tabId, f); + break; + } + } + }); +} + +export { zoomIn, zoomOut }; diff --git a/src/shared/actions.js b/src/shared/actions.js index e01813b..768f06e 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -11,12 +11,16 @@ export const SCROLL_BOTTOM = 'scroll.bottom'; export const FOLLOW_START = 'follow.start'; export const HISTORY_PREV = 'history.prev'; export const HISTORY_NEXT = 'history.next'; +export const ZOOM_IN = 'zoom.in'; +export const ZOOM_OUT = 'zoom.out'; const BACKGROUND_ACTION_SET = new Set([ TABS_CLOSE, TABS_REOPEN, TABS_PREV, - TABS_NEXT + TABS_NEXT, + ZOOM_IN, + ZOOM_OUT ]); const CONTENT_ACTION_SET = new Set([ -- cgit v1.2.3 From a5f1e06efcc64c181f2e06337e47e4705aebabb8 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 23 Aug 2017 22:01:29 +0900 Subject: support zz command --- src/background/index.js | 3 +++ src/background/key-queue.js | 1 + src/background/zooms.js | 10 +++++++--- src/shared/actions.js | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/shared/actions.js') diff --git a/src/background/index.js b/src/background/index.js index cfd5e77..62e4a7b 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -45,6 +45,9 @@ const doBackgroundAction = (sender, action) => { case actions.ZOOM_OUT: zooms.zoomOut(); break; + case actions.ZOOM_NEUTRAL: + zooms.neutral(); + break; } } diff --git a/src/background/key-queue.js b/src/background/key-queue.js index 6319431..d3f4621 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -15,6 +15,7 @@ const DEFAULT_KEYMAP = [ { keys: [{ code: KeyboardEvent.DOM_VK_L }], action: [ actions.TABS_NEXT, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_I }], action: [ actions.ZOOM_IN ]}, { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_O }], action: [ actions.ZOOM_OUT ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_Z }], action: [ actions.ZOOM_NEUTRAL]}, { keys: [{ code: KeyboardEvent.DOM_VK_F }], action: [ actions.FOLLOW_START, false ]}, { keys: [{ code: KeyboardEvent.DOM_VK_F, shift: true }], action: [ actions.FOLLOW_START, true ]}, { keys: [{ code: KeyboardEvent.DOM_VK_H, shift: true }], action: [ actions.HISTORY_PREV ]}, diff --git a/src/background/zooms.js b/src/background/zooms.js index def2878..bb65030 100644 --- a/src/background/zooms.js +++ b/src/background/zooms.js @@ -18,7 +18,7 @@ const zoomIn = (tabId = undefined) => { } } }); -} +}; const zoomOut = (tabId = undefined) => { browser.tabs.getZoom(tabId).then((factor) => { @@ -29,6 +29,10 @@ const zoomOut = (tabId = undefined) => { } } }); -} +}; -export { zoomIn, zoomOut }; +const neutral = (tabId = undefined) => { + browser.tabs.setZoom(tabId, 1); +}; + +export { zoomIn, zoomOut, neutral }; diff --git a/src/shared/actions.js b/src/shared/actions.js index 768f06e..656b801 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -13,6 +13,7 @@ export const HISTORY_PREV = 'history.prev'; export const HISTORY_NEXT = 'history.next'; export const ZOOM_IN = 'zoom.in'; export const ZOOM_OUT = 'zoom.out'; +export const ZOOM_NEUTRAL = 'zoom.neutral'; const BACKGROUND_ACTION_SET = new Set([ TABS_CLOSE, @@ -20,7 +21,8 @@ const BACKGROUND_ACTION_SET = new Set([ TABS_PREV, TABS_NEXT, ZOOM_IN, - ZOOM_OUT + ZOOM_OUT, + ZOOM_NEUTRAL ]); const CONTENT_ACTION_SET = new Set([ -- cgit v1.2.3 From cb36fc666cb2615f911bc855bc91249d167f0dba Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 26 Aug 2017 18:43:15 +0900 Subject: support r/R commands --- src/background/index.js | 3 +++ src/background/key-queue.js | 2 ++ src/background/tabs.js | 9 ++++++++- src/shared/actions.js | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/shared/actions.js') diff --git a/src/background/index.js b/src/background/index.js index 62e4a7b..f1a7217 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -39,6 +39,9 @@ const doBackgroundAction = (sender, action) => { case actions.TABS_NEXT: tabs.selectNextTab(sender.tab.index, actions[1] || 1); break; + case actions.TABS_RELOAD: + tabs.reload(sender.tab, actions[1] || false); + break; case actions.ZOOM_IN: zooms.zoomIn(); break; diff --git a/src/background/key-queue.js b/src/background/key-queue.js index d3f4621..f5f9a53 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -13,6 +13,8 @@ const DEFAULT_KEYMAP = [ { keys: [{ code: KeyboardEvent.DOM_VK_U }], action: [ actions.TABS_REOPEN]}, { keys: [{ code: KeyboardEvent.DOM_VK_H }], action: [ actions.TABS_PREV, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_L }], action: [ actions.TABS_NEXT, 1 ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_R }], action: [ actions.TABS_RELOAD, false ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_R, shift: true }], action: [ actions.TABS_RELOAD, true ]}, { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_I }], action: [ actions.ZOOM_IN ]}, { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_O }], action: [ actions.ZOOM_OUT ]}, { keys: [{ code: KeyboardEvent.DOM_VK_Z }, { code: KeyboardEvent.DOM_VK_Z }], action: [ actions.ZOOM_NEUTRAL]}, diff --git a/src/background/tabs.js b/src/background/tabs.js index 899284d..56f86eb 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -40,4 +40,11 @@ const selectNextTab = (current, count) => { }); }; -export { closeTab, reopenTab, selectNextTab, selectPrevTab }; +const reload = (current, cache) => { + browser.tabs.reload( + current.id, + { bypassCache: cache } + ); +}; + +export { closeTab, reopenTab, selectNextTab, selectPrevTab, reload }; diff --git a/src/shared/actions.js b/src/shared/actions.js index 656b801..f0a224c 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -4,6 +4,7 @@ export const TABS_CLOSE = 'tabs.close'; export const TABS_REOPEN = 'tabs.reopen'; export const TABS_PREV = 'tabs.prev'; export const TABS_NEXT = 'tabs.next'; +export const TABS_RELOAD = 'tabs.reload'; export const SCROLL_UP = 'scroll.up'; export const SCROLL_DOWN = 'scroll.down'; export const SCROLL_TOP = 'scroll.top'; @@ -20,6 +21,7 @@ const BACKGROUND_ACTION_SET = new Set([ TABS_REOPEN, TABS_PREV, TABS_NEXT, + TABS_RELOAD, ZOOM_IN, ZOOM_OUT, ZOOM_NEUTRAL -- cgit v1.2.3