-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbg.js
42 lines (32 loc) · 930 Bytes
/
bg.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
/* background script:
- updates badge count
- starts the viewer tab
*/
chrome.browserAction.onClicked.addListener(function(tab) {
// start viewer tab
var url = chrome.extension.getURL('maintab.html#'+tab.id);
chrome.tabs.create({url:url});
});
function tab_updated(tabid) {
console.log('active tab: '+tabid);
if (!tabid)
return;
if (!get_config("tooltip"))
return;
// ask counts from content script
chrome.tabs.sendMessage(tabid, {"badge":1}, function(reply){
update_badge(reply);
});
}
// tab activity - update badge
chrome.tabs.onActivated.addListener(function(info){
chrome.tabs.get(info.tabId, function(tab) {
if (tab && tab.id)
tab_updated(tab.id);
});
});
chrome.tabs.onUpdated.addListener(function(tabid, info, tab){
if (info.status == "complete" && tabid)
tab_updated(tabid);
});
console.log('bg loaded');