-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbg_script.js
More file actions
35 lines (28 loc) · 758 Bytes
/
Copy pathbg_script.js
File metadata and controls
35 lines (28 loc) · 758 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
26
27
28
29
30
31
32
33
34
35
function setBadge(text){
chrome.browserAction.setBadgeText({text: String(text)+'%'});
}
function updateBadge(resp) {
x = resp.pos;
var pos = (x >= 0 && x <= 100 && String(x)) || undefined;
if(x && pos != undefined && pos != null) {
setBadge(pos);
} else if(x > 100) {
setBadge(100);
} else {
setBadge(0);
}
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
updateBadge(request);
sendResponse({});
}
);
//credit : http://samdutton.wordpress.com/2010/12/16/debugging-google-chrome-extensions/
chrome.tabs.onSelectionChanged.addListener(
function handleSelectionChange(tabId, selectInfo) {
chrome.tabs.sendRequest(tabId, {},
updateBadge);
}
);
setBadge(0);