diff options
-rw-r--r-- | manifest.json | 5 | ||||
-rw-r--r-- | src/background/index.js | 6 | ||||
-rw-r--r-- | src/background/key-queue.js | 2 | ||||
-rw-r--r-- | src/background/tabs.js | 22 | ||||
-rw-r--r-- | src/shared/actions.js | 4 |
5 files changed, 37 insertions, 2 deletions
diff --git a/manifest.json b/manifest.json index 2621c5e..1d511fa 100644 --- a/manifest.json +++ b/manifest.json @@ -11,5 +11,8 @@ ], "background": { "scripts": ["build/background.js"] - } + }, + "permissions": [ + "sessions" + ] } diff --git a/src/background/index.js b/src/background/index.js index 8544c0f..f3bd65a 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -26,6 +26,12 @@ const keyDownHandle = (request, sender, sendResponse) => { const doBackgroundAction = (sender, action) => { switch(action[0]) { + case actions.TABS_CLOSE: + tabs.closeTab(sender.tab.id); + break; + case actions.TABS_REOPEN: + tabs.reopenTab(); + break; case actions.TABS_PREV: tabs.selectPrevTab(sender.tab.index, actions[1] || 1); break; diff --git a/src/background/key-queue.js b/src/background/key-queue.js index 3f25791..d753bc1 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -9,6 +9,8 @@ const DEFAULT_KEYMAP = [ { keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_DOWN, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_G }, { code: KeyboardEvent.DOM_VK_G }], action: [ actions.SCROLL_TOP ]}, { keys: [{ code: KeyboardEvent.DOM_VK_G, shift: true }], action: [ actions.SCROLL_BOTTOM ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_D }], action: [ actions.TABS_CLOSE ]}, + { 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 ]}, ] diff --git a/src/background/tabs.js b/src/background/tabs.js index 000bd7d..899284d 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -1,3 +1,23 @@ +const closeTab = (id) => { + browser.tabs.remove(id); +}; + +const reopenTab = () => { + browser.sessions.getRecentlyClosed({ + maxResults: 1 + }).then((sessions) => { + if (sessions.length === 0) { + return; + } + let session = sessions[0]; + if (session.tab) { + browser.sessions.restore(session.tab.sessionId); + } else { + browser.sessions.restore(session.window.sessionId); + } + }); +}; + const selectPrevTab = (current, count) => { chrome.tabs.query({ currentWindow: true }, (tabs) => { if (tabs.length < 2) { @@ -20,4 +40,4 @@ const selectNextTab = (current, count) => { }); }; -export { selectNextTab, selectPrevTab }; +export { closeTab, reopenTab, selectNextTab, selectPrevTab }; diff --git a/src/shared/actions.js b/src/shared/actions.js index e1bf1e8..be25d72 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -1,5 +1,7 @@ export const CMD_OPEN = 'cmd.open'; export const CMD_TABS_OPEN = 'cmd.tabs.open'; +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 SCROLL_UP = 'scroll.up'; @@ -8,6 +10,8 @@ export const SCROLL_TOP = 'scroll.top'; export const SCROLL_BOTTOM = 'scroll.bottom'; const BACKGROUND_ACTION_SET = new Set([ + TABS_CLOSE, + TABS_REOPEN, TABS_PREV, TABS_NEXT ]); |