-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
25 lines (21 loc) · 769 Bytes
/
Copy pathbackground.js
File metadata and controls
25 lines (21 loc) · 769 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
function updateBadge() {
let promises = [
browser.storage.local.get('list').then(result => result.list),
browser.tabs.query({currentWindow: true, active: true}).then(tabs => tabs[0])
];
Promise.all(promises).then(function(results) {
let [list, tab] = results;
if (list) {
let count = Object.keys(list).filter(id => {
let item = JSON.parse(list[id]);
return item.url == tab.url;
}).length;
browser.browserAction.setBadgeText({text: count ? count.toString() : '', tabId: tab.id});
}
});
browser.tabs.onActivated.addListener(updateBadge);
browser.tabs.onUpdated.addListener(updateBadge);
}
browser.browserAction.setBadgeBackgroundColor({'color': '#323031'});
browser.browserAction.setBadgeTextColor({'color': 'white'});
updateBadge();