-
Notifications
You must be signed in to change notification settings - Fork 32
/
badge.js
56 lines (50 loc) · 1.99 KB
/
badge.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
// eslint-disable-next-line no-unused-vars
const setBadgeIcon = () => {
chrome.browserAction.setIcon({ path: options.autoCloseTab ? "images/auto_close_16.png" : "images/manual_close_16.png" });
if (environment.isFirefox) browser.browserAction.setBadgeTextColor({ color: "white" });
};
const setBadge = async (windowId, activeTabId) => {
let nbDuplicateTabs = tabsInfo.getNbDuplicateTabs(windowId);
if (nbDuplicateTabs === "0" && !options.showBadgeIfNoDuplicateTabs) nbDuplicateTabs = "";
const backgroundColor = (nbDuplicateTabs !== "0") ? options.badgeColorDuplicateTabs : options.badgeColorNoDuplicateTabs;
if (environment.isFirefox) {
setWindowBadgeText(windowId, nbDuplicateTabs);
setWindowBadgeBackgroundColor(windowId, backgroundColor);
}
else {
// eslint-disable-next-line no-param-reassign
activeTabId = activeTabId || await getActiveTabId(windowId);
if (activeTabId) {
setTabBadgeText(activeTabId, nbDuplicateTabs);
setTabBadgeBackgroundColor(activeTabId, backgroundColor);
}
}
};
const getNbDuplicateTabs = (duplicateTabsGroups) => {
let nbDuplicateTabs = 0;
if (duplicateTabsGroups.size !== 0) {
duplicateTabsGroups.forEach(duplicateTabs => (nbDuplicateTabs += duplicateTabs.size - 1));
}
return nbDuplicateTabs;
};
const updateBadgeValue = (nbDuplicateTabs, windowId) => {
tabsInfo.setNbDuplicateTabs(windowId, nbDuplicateTabs);
setBadge(windowId);
};
// eslint-disable-next-line no-unused-vars
const updateBadgesValue = async (duplicateTabsGroups, windowId) => {
const nbDuplicateTabs = getNbDuplicateTabs(duplicateTabsGroups);
if (options.searchInAllWindows) {
const windows = await getWindows();
windows.forEach(window => updateBadgeValue(nbDuplicateTabs, window.id));
}
else {
updateBadgeValue(nbDuplicateTabs, windowId);
}
};
// eslint-disable-next-line no-unused-vars
const updateBadgeStyle = async () => {
const windows = await getWindows();
windows.forEach(window => setBadge(window.id));
};