Skip to content

Commit e9f9bc8

Browse files
committed
Refact storage from time intervals
1 parent a94316f commit e9f9bc8

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131
<div id="buttons" class="btn-block">
3232
<a class="active" id="btnToday">Today</a>
33-
<a id="btnAll">All time</a>
33+
<a id="btnAll">All-time</a>
3434
<a id="btnByDays">By days</a>
3535
<a id="settings">Settings</a>
3636
</div>

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"scripts/storage.js",
3535
"scripts/activity.js",
3636
"scripts/tab.js",
37-
"scripts/background.js",
3837
"scripts/timeInterval.js",
38+
"scripts/background.js",
3939
"scripts/restriction.js"],
4040
"persistent": false
4141
},

src/scripts/activity.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Activity {
2828
this.addTimeInterval(domain);
2929
}
3030
}
31-
}
31+
} else this.closeIntervalForCurrentTab();
3232
}
3333

3434
isValidPage(tab) {
@@ -110,20 +110,26 @@ class Activity {
110110
}
111111

112112
addTimeInterval(domain) {
113-
var item = timeIntervalList.find(o => o.domain === domain);
113+
var item = timeIntervalList.find(o => o.domain === domain && o.day == new Date().toLocaleDateString("en-US"));
114114
if (item != undefined) {
115-
item.addInterval();
115+
if (item.day == new Date().toLocaleDateString("en-US"))
116+
item.addInterval();
117+
else {
118+
var newInterval = new TimeInterval(new Date().toLocaleDateString("en-US"), domain);
119+
newInterval.addInterval();
120+
timeIntervalList.push(newInterval);
121+
}
116122
} else {
117123
var newInterval = new TimeInterval(new Date().toLocaleDateString("en-US"), domain);
118-
timeIntervalList.push(newInterval);
119124
newInterval.addInterval();
125+
timeIntervalList.push(newInterval);
120126
}
121127
}
122128

123129

124130
closeIntervalForCurrentTab() {
125131
if (currentTab !== '') {
126-
var item = timeIntervalList.find(o => o.domain === currentTab);
132+
var item = timeIntervalList.find(o => o.domain === currentTab && o.day == new Date().toLocaleDateString("en-US"));
127133
if (item != undefined)
128134
item.closeInterval();
129135
}

src/scripts/background.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ function backgroundCheck() {
5252
}
5353
}
5454
}
55-
} else {
56-
activity.closeIntervalForCurrentTab();
57-
}
55+
} else activity.closeIntervalForCurrentTab();
5856
});
5957
}
6058

@@ -115,7 +113,7 @@ function checkPermissions(callback, activeUrl, tab, activeTab) {
115113
callback(activeUrl, tab, activeTab);
116114
else activity.closeIntervalForCurrentTab();
117115
});
118-
}
116+
} else activity.closeIntervalForCurrentTab();
119117
});
120118
}
121119

src/scripts/timeInterval.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ class TimeInterval {
1010
}
1111

1212
addInterval() {
13-
console.log('add interval');
1413
var date = new Date();
1514
var stringDate = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
1615
this.intervals.push(stringDate + '-' + stringDate);
1716
}
1817

1918
closeInterval() {
2019
var today = new Date();
21-
var stringDate = zeroAppend(today.getHours()) + ':' + zeroAppend(today.getMinutes()) + ':' + zeroAppend(today.getSeconds());
22-
var currentInterval = this.intervals.pop();
23-
this.intervals.push(currentInterval.split('-')[0] + '-' + stringDate);
20+
var stringDate = today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
21+
var currentInterval = this.intervals[this.intervals.length - 1];
22+
if (currentInterval != undefined) {
23+
if (currentInterval.split('-')[0] == currentInterval.split('-')[1]) {
24+
this.intervals.pop();
25+
this.intervals.push(currentInterval.split('-')[0] + '-' + stringDate);
26+
}
27+
}
2428
}
2529
};

0 commit comments

Comments
 (0)