-
Notifications
You must be signed in to change notification settings - Fork 4
/
background.html
63 lines (58 loc) · 1.5 KB
/
background.html
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
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var popupWindow;
function init() {
var count = 0;
// set up the initial tab count
chrome.windows.getAll({"populate": true},function(windows) {
for( var i in windows ) {
count += windows[i].tabs.length;
}
chrome.browserAction.setBadgeText({text: "" + count});
});
// listen for new tabs
chrome.tabs.onCreated.addListener(function(tab) {
chrome.browserAction.setBadgeText({text: "" + (++count)});
});
// listen for closed tabs
chrome.tabs.onRemoved.addListener(function(tab) {
chrome.browserAction.setBadgeText({text: "" + (--count)});
});
/*var lastTabId = 0;
var id = 0;
chrome.tabs.getSelected(null, function(tab) {
lastTabId = id = tab.id;
});
chrome.tabs.onSelectionChanged.addListener(function(tabId, selectInfo) {
lastTabId = id;
id = tabId;
});
*/
// set up onclick for the browser action
// TODO user preference for onclick action
/*chrome.browserAction.onClicked.addListener(function(tab) {
if (tab.id != lastTabId) {
chrome.tabs.update(lastTabId, { selected : true });
lastTabId = tab.id;
}
});*/
}
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.action == "popup") {
if (popupWindow != null) {
popupWindow.close();
}
popupWindow = window.open(chrome.extension.getURL("popup.html"), "Tab Glutton", "width=400,height=530");
sendResponse({response: "open"});
}
else {
sendResponse({});
}
});
</script>
</head>
<body onload="init()">
</body>
</html>