Skip to content

Commit da7cb81

Browse files
committed
Add counter of visit
1 parent 4e9f820 commit da7cb81

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

scripts/activity.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class Activity {
66
if (tab.id && (tab.id != 0)) {
77
tabs = tabs || [];
88
var domain = this.extractHostname(tab.url);
9+
var isDifferentUrl = false;
10+
if (currentTab !== tab.url) {
11+
isDifferentUrl = true;
12+
}
913
this.setCurrentActiveTab(domain);
1014
if (this.isNewUrl(domain) && !this.isInBlackList(domain)) {
1115
var favicon = tab.favIconUrl;
@@ -15,6 +19,12 @@ class Activity {
1519
var newTab = new Tab(domain, favicon);
1620
tabs.push(newTab);
1721
}
22+
23+
if (isDifferentUrl) {
24+
var tabUrl = this.getTab(domain);
25+
if (tabUrl !== undefined)
26+
tabUrl.incCounter();
27+
}
1828
}
1929
}
2030
else this.clearCurrentActiveTab();

scripts/background.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ function mainTRacker(activeUrl, tab, activeTab) {
6060
if (activity.isLimitExceeded(activeUrl, tab)) {
6161
setBlockPageToCurrent(activeUrl);
6262
}
63-
if (!activity.isInBlackList(activeUrl))
63+
if (!activity.isInBlackList(activeUrl)) {
6464
tab.incSummaryTime();
65+
}
6566
if (setting_view_in_badge === true) {
6667
if (activity.isInBlackList(activeUrl)) {
6768
chrome.browserAction.setBadgeBackgroundColor({ color: '#FF0000' })
@@ -108,18 +109,18 @@ function checkDOM(state, activeUrl, tab, activeTab) {
108109
}
109110
}
110111

111-
function checkPermissions(callback, activeUrl, tab, activeTab){
112+
function checkPermissions(callback, activeUrl, tab, activeTab) {
112113
chrome.permissions.contains({
113114
permissions: ['tabs'],
114115
origins: ["http://*/*", "https://*/*"]
115-
}, function(result) {
116+
}, function (result) {
116117
if (result) {
117118
chrome.tabs.executeScript({ code: "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" }, (results) => {
118119
if (results !== undefined && results[0] !== undefined && results[0] === true)
119-
callback(activeUrl, tab, activeTab);
120+
callback(activeUrl, tab, activeTab);
120121
});
121122
}
122-
});
123+
});
123124
}
124125

125126
function backgroundUpdateStorage() {
@@ -168,7 +169,7 @@ function loadTabs() {
168169
storage.loadTabs(STORAGE_TABS, function (items) {
169170
tabs = [];
170171
for (var i = 0; i < items.length; i++) {
171-
tabs.push(new Tab(items[i].url, items[i].favicon, items[i].days, items[i].summaryTime));
172+
tabs.push(new Tab(items[i].url, items[i].favicon, items[i].days, items[i].summaryTime, items[i].counter));
172173
}
173174
});
174175
}

scripts/tab.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict';
22

33
class Tab {
4-
constructor(url, favicon, days, summary) {
4+
constructor(url, favicon, days, summary, counter) {
55
this.url = url;
66
this.favicon = favicon;
77
if (summary !== undefined)
88
this.summaryTime = summary;
99
else
1010
this.summaryTime = 0;
11+
if (counter !== undefined)
12+
this.counter = counter;
13+
else
14+
this.counter = 0;
1115
if (days !== undefined)
1216
this.days = days;
1317
else
@@ -27,11 +31,25 @@ class Tab {
2731
}
2832
}
2933

34+
incCounter(){
35+
this.counter +=1;
36+
37+
var today = new Date().toLocaleDateString();
38+
var day = this.days.find(x => x.date == today);
39+
if (day === undefined) {
40+
this.addNewDay(today);
41+
}
42+
else {
43+
day['counter'] += 1;
44+
}
45+
}
46+
3047
addNewDay(today) {
3148
this.days.push(
3249
{
3350
'date': today,
34-
'summary': 1
51+
'summary': 1,
52+
'counter': 1
3553
}
3654
);
3755
}

0 commit comments

Comments
 (0)