-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
29 lines (26 loc) · 867 Bytes
/
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
var timedTabs = Array();
var totalCreated = 0;
var totalRemoved = 0;
// Count currently open tabs when script starts.
chrome.windows.getAll(null, function (windows) {
for (i in windows) {
chrome.tabs.getAllInWindow(windows[i].id, function (tabs) {
totalCreated += tabs.length;
timedTabs.push([getCurrentTime(), totalCreated - totalRemoved]);
});
}
});
// Listeners for created and removed tabs.
chrome.tabs.onCreated.addListener(function(tab) {
totalCreated++;
timedTabs.push([getCurrentTime(), totalCreated - totalRemoved]);
});
chrome.tabs.onRemoved.addListener(function(tab) {
totalRemoved++;
timedTabs.push([getCurrentTime(), totalCreated - totalRemoved]);
});
// Get current time with timezone offset for flot.
function getCurrentTime() {
time = new Date()
return time.getTime() - (time.getTimezoneOffset() * 60 * 1000);
}