-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbg.js
More file actions
27 lines (23 loc) · 828 Bytes
/
Copy pathbg.js
File metadata and controls
27 lines (23 loc) · 828 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
chrome.tabs.onCreated.addListener((tab) => {
// Only in tab restoration case is URL set at creation time -> defer to Chrome's default logic
// (Surprisingly, url is not set at creation time for cmd-click opened tabs...)
if (tab.url && tab.url !== 'chrome://newtab/') {
return;
}
// Otherwise, new tab -> open to the right of last accessed
let tabId = tab.id;
let windowId = tab.windowId;
chrome.windows.get(windowId, { populate: true }, (window) => {
if (chrome.runtime.lastError || !window || !Array.isArray(window.tabs)) {
return;
}
const candidate = window.tabs
.filter(t => t.id !== tabId)
.sort((a, b) => (b.lastAccessed || 0) - (a.lastAccessed || 0))[0];
if (candidate) {
chrome.tabs.move(tabId, {
index: candidate.index + 1
});
}
});
});