-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
39 lines (28 loc) · 942 Bytes
/
background.js
File metadata and controls
39 lines (28 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
chrome.commands.onCommand.addListener(keyboardCommand);
chrome.tabs.onActivated.addListener(tabActivated);
let browserWindows = {};
function keyboardCommand(cmd) {
if (cmd != "PreviousTab") {
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, tabsResult => {
if (tabsResult.length != 1 || !browserWindows[tabsResult[0].windowId]) {
return;
}
const tab = tabsResult[0];
const previousTabs = browserWindows[tab.windowId];
if (previousTabs.length < 2) {
return;
}
// newest on the beginning
const prevTabId = previousTabs[1];
chrome.tabs.update(prevTabId, { active: true });
});
}
function tabActivated(activeInfo) {
const windowId = activeInfo.windowId;
const tabs = browserWindows[windowId] = browserWindows[windowId] || [];
tabs.unshift(activeInfo.tabId);
tabs.length = 3;
}