Skip to content

Commit 93ad793

Browse files
committed
add check every second active tab
1 parent 5059a65 commit 93ad793

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"permissions": [
1919
"tabs",
2020
"activeTab",
21-
"storage"
21+
"storage",
22+
"idle"
2223
],
2324
"background": {
2425
"scripts": ["scripts/common.js",

scripts/background.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ chrome.tabs.onActivated.addListener(function (info) {
1010
});
1111
});
1212

13-
chrome.windows.getLastFocused({populate: true}, function (window){
14-
var s = window;
15-
});
13+
setInterval(backgroundCheck, SETTINGS_INTERVAL_CHECK);
14+
15+
function backgroundCheck() {
16+
chrome.windows.getLastFocused({ populate: true }, function (currentWindow) {
17+
if (tabs.length > 0) {
18+
var activeTab = currentWindow.tabs.find(o => o.active === true);
19+
if (activeTab !== undefined) {
20+
var activeUrl = activity.extractHostname(activeTab.url);
21+
var tab = activity.getTab(activeUrl);
22+
if (tab !== undefined) {
23+
chrome.idle.queryState(SETTINGS_INTERVAL_INACTIVITY, function (state) {
24+
if (state === 'active') {
25+
tab.summaryTime += 1;
26+
}
27+
});
28+
}
29+
}
30+
}
31+
});
32+
}

scripts/common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var STORAGE_TABS = 'tabs';
2+
var SETTINGS_INTERVAL_INACTIVITY = 30;
3+
var SETTINGS_INTERVAL_CHECK = 1000;
24

35
function isEmpty(obj) {
46
for (var prop in obj) {

scripts/tab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ class Tab {
44
constructor(url, favicon){
55
this.url = url;
66
this.favicon = favicon;
7-
this.summaryTime = '';
7+
this.summaryTime = 0;
88
}
99
};

0 commit comments

Comments
 (0)