-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
29 lines (26 loc) · 1.12 KB
/
background.js
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
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url) {
chrome.tabs.query({}, (tabs) => {
const duplicates = tabs.filter(t => t.url === tab.url && t.id !== tabId);
duplicates.forEach(duplicateTab => {
let tabToClose = (duplicateTab.groupId === -1) ? duplicateTab.id : (tab.groupId === -1 ? tabId : (tabId < duplicateTab.id ? tabId : duplicateTab.id));
let isGrouped = tab.groupId !== -1 || duplicateTab.groupId !== -1;
chrome.tabs.sendMessage(tabId, {
type: "confirm-tab-close",
tabToClose: tabToClose,
tabToFocus: tabId,
isGrouped: isGrouped
});
});
});
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "close-tab") {
chrome.tabs.remove(message.tabToClose, () => {
if (!chrome.runtime.lastError) {
chrome.tabs.update(message.tabToFocus, { active: true });
}
});
}
});