-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
40 lines (37 loc) · 1 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
30
31
32
33
34
35
36
37
38
39
40
chrome.tabs.onActivated.addListener(function (activeInfo) {
setTimeout(() => {
chrome.tabs.get(activeInfo.tabId, (tab) => {
var url = tab.url;
var currentTabId = tab.tabId;
if (localStorage.getItem(url) !== null) {
showBadge(currentTabId);
} else {
hideBadge(currentTabId);
}
});
}, 500);
});
chrome.tabs.onUpdated.addListener(function (activeInfo) {
chrome.tabs.getSelected(null, function (tab) {
var url = tab.url;
var currentTabId = tab.tabId;
if (localStorage.getItem(url) !== null) {
showBadge(currentTabId);
} else {
hideBadge(currentTabId);
}
});
});
function showBadge(tabid) {
chrome.browserAction.setBadgeBackgroundColor({ color: "green" }, () => {
chrome.browserAction.setBadgeText({ tabId: tabid, text: "*" });
});
}
function hideBadge(tabid) {
chrome.browserAction.setBadgeBackgroundColor({ color: "green" }, () => {
chrome.browserAction.setBadgeText({
tabId: tabid,
text: "",
});
});
}