forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (28 loc) · 1020 Bytes
/
background.js
File metadata and controls
32 lines (28 loc) · 1020 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
'use strict';
var tabs = [];
var activity = new Activity();
var storage = new LocalStorage();
chrome.tabs.onActivated.addListener(function (info) {
chrome.tabs.get(info.tabId, function (tab) {
activity.addTab(tab);
});
});
setInterval(backgroundCheck, SETTINGS_INTERVAL_CHECK);
function backgroundCheck() {
chrome.windows.getLastFocused({ populate: true }, function (currentWindow) {
if (tabs.length > 0) {
var activeTab = currentWindow.tabs.find(o => o.active === true);
if (activeTab !== undefined) {
var activeUrl = activity.extractHostname(activeTab.url);
var tab = activity.getTab(activeUrl);
if (tab !== undefined) {
chrome.idle.queryState(SETTINGS_INTERVAL_INACTIVITY, function (state) {
if (state === 'active') {
tab.summaryTime += 1;
}
});
}
}
}
});
}