Skip to content

Commit 89c38af

Browse files
committed
Disable limits temporarily Stigmatoz#39
1 parent ff94ed5 commit 89c38af

File tree

7 files changed

+85
-32
lines changed

7 files changed

+85
-32
lines changed

src/block.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
<img src="icons/time.svg" height="50">
1616
<p class="title">Time limit</p>
1717
<div class="description">You've reached today your limit on <span id='site' class="current-site"></span></div>
18-
<div class="description margin-top-10">Your current daily limit is <span id='limit' class="current-limit"></span>
19-
</div>
18+
<div class="description margin-top-10">Your current daily limit is <span id='limit' class="current-limit"></span></div>
19+
20+
<div class="margin-top-10"><a id="deffererBtn" class="defferer-link">Set aside for 5 minutes</a></div>
2021
</div>
2122
<p class="product-title">Web Activity Time Tracker</p>
2223
</body>

src/scripts/activity.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Activity {
55
if (this.isValidPage(tab) === true) {
66
if (tab.id && (tab.id != 0)) {
77
tabs = tabs || [];
8-
var domain = this.extractHostname(tab.url);
8+
var domain = extractHostname(tab.url);
99
var isDifferentUrl = false;
1010
if (currentTab !== tab.url) {
1111
isDifferentUrl = true;
@@ -41,13 +41,13 @@ class Activity {
4141

4242
isInBlackList(domain) {
4343
if (setting_black_list !== undefined && setting_black_list.length > 0)
44-
return setting_black_list.find(o => isDomainEquals(this.extractHostname(o), this.extractHostname(domain))) !== undefined;
44+
return setting_black_list.find(o => isDomainEquals(extractHostname(o), extractHostname(domain))) !== undefined;
4545
else return false;
4646
}
4747

4848
isLimitExceeded(domain, tab) {
4949
if (setting_restriction_list !== undefined && setting_restriction_list.length > 0) {
50-
var item = setting_restriction_list.find(o => isDomainEquals(this.extractHostname(o.domain), this.extractHostname(domain)));
50+
var item = setting_restriction_list.find(o => isDomainEquals(extractHostname(o.domain), extractHostname(domain)));
5151
if (item !== undefined) {
5252
var today = new Date().toLocaleDateString("en-US");
5353
var data = tab.days.find(x => x.date == today);
@@ -62,6 +62,27 @@ class Activity {
6262
return false;
6363
}
6464

65+
wasDeferred(domain){
66+
if (deferredRestrictionsList != undefined){
67+
let defItem = deferredRestrictionsList.find(x => extractHostname(x.site) == extractHostname(domain));
68+
if (defItem != null){
69+
let time = defItem.dateOfDeferred;
70+
if (time + DEFERRED_TIMEOUT > new Date().getTime()){
71+
return true;
72+
}
73+
else {
74+
let index = deferredRestrictionsList.indexOf(defItem);
75+
if (index > -1)
76+
deferredRestrictionsList.splice(index, 1);
77+
78+
return false;
79+
}
80+
}
81+
}
82+
83+
return false;
84+
}
85+
6586
isNewUrl(domain) {
6687
if (tabs.length > 0)
6788
return tabs.find(o => o.url === domain) === undefined;
@@ -73,24 +94,9 @@ class Activity {
7394
return tabs.find(o => o.url === domain);
7495
}
7596

76-
extractHostname(url) {
77-
var hostname;
78-
79-
if (url.indexOf("//") > -1) {
80-
hostname = url.split('/')[2];
81-
}
82-
else {
83-
hostname = url.split('/')[0];
84-
}
85-
86-
hostname = hostname.split(':')[0];
87-
hostname = hostname.split('?')[0];
88-
89-
return hostname;
90-
}
91-
97+
9298
updateFavicon(tab) {
93-
var domain = this.extractHostname(tab.url);
99+
var domain = extractHostname(tab.url);
94100
var currentTab = this.getTab(domain);
95101
if (currentTab !== null && currentTab !== undefined) {
96102
if (tab.favIconUrl !== undefined && tab.favIconUrl !== currentTab.favicon) {
@@ -138,7 +144,7 @@ class Activity {
138144

139145
isNeedNotifyView(domain, tab){
140146
if (setting_notification_list !== undefined && setting_notification_list.length > 0) {
141-
var item = setting_notification_list.find(o => isDomainEquals(this.extractHostname(o.domain), this.extractHostname(domain)));
147+
var item = setting_notification_list.find(o => isDomainEquals(extractHostname(o.domain), extractHostname(domain)));
142148
if (item !== undefined) {
143149
var today = new Date().toLocaleDateString("en-US");
144150
var data = tab.days.find(x => x.date == today);

src/scripts/background.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var currentTab;
66
var isNeedDeleteTimeIntervalFromTabs = false;
77
var activity = new Activity();
88
var storage = new LocalStorage();
9+
var deferredRestrictionsList;
910

1011
var setting_black_list;
1112
var setting_restriction_list;
@@ -33,7 +34,7 @@ function backgroundCheck() {
3334
if (currentWindow.focused) {
3435
var activeTab = currentWindow.tabs.find(t => t.active === true);
3536
if (activeTab !== undefined && activity.isValidPage(activeTab)) {
36-
var activeUrl = activity.extractHostname(activeTab.url);
37+
var activeUrl = extractHostname(activeTab.url);
3738
var tab = activity.getTab(activeUrl);
3839
if (tab === undefined) {
3940
activity.addTab(activeTab);
@@ -63,8 +64,8 @@ function backgroundCheck() {
6364
}
6465

6566
function mainTRacker(activeUrl, tab, activeTab) {
66-
if (activity.isLimitExceeded(activeUrl, tab)) {
67-
setBlockPageToCurrent(activeUrl);
67+
if (activity.isLimitExceeded(activeUrl, tab) && !activity.wasDeferred(activeUrl)) {
68+
setBlockPageToCurrent(activeTab.url);
6869
}
6970
if (!activity.isInBlackList(activeUrl)) {
7071
if (activity.isNeedNotifyView(activeUrl, tab)) {
@@ -130,8 +131,8 @@ function notificationAction(activeUrl, tab) {
130131
});
131132
}
132133

133-
function setBlockPageToCurrent(activeUrl) {
134-
var blockUrl = chrome.runtime.getURL("block.html") + '?url=' + activeUrl;
134+
function setBlockPageToCurrent(currentUrl) {
135+
var blockUrl = chrome.runtime.getURL("block.html") + '?url=' + currentUrl;
135136
chrome.tabs.query({ currentWindow: true, active: true }, function(tab) {
136137
chrome.tabs.update(tab.id, { url: blockUrl });
137138
});

src/scripts/block.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
'use strict';
2+
13
var storage = new LocalStorage();
4+
var blockSiteUrl;
25
var restrictionList = [];
36

47
document.addEventListener('DOMContentLoaded', function () {
58
var url = new URL(document.URL);
6-
var blockSiteUrl = url.searchParams.get("url");
7-
document.getElementById('site').innerText = blockSiteUrl;
9+
blockSiteUrl = url.searchParams.get("url");
10+
document.getElementById('site').innerText = extractHostname(blockSiteUrl);
811

912
storage.getValue(STORAGE_RESTRICTION_LIST, function (items) {
1013
restrictionList = items;
@@ -15,4 +18,19 @@ document.addEventListener('DOMContentLoaded', function () {
1518
document.getElementById('limit').innerText = convertShortSummaryTimeToString(currentItem.time);
1619
}
1720
});
21+
22+
document.getElementById('deffererBtn').addEventListener('click', function () {
23+
chrome.runtime.getBackgroundPage(function (bg) {
24+
let defList = bg.deferredRestrictionsList;
25+
if (defList == undefined)
26+
defList = [];
27+
defList.push({ site: blockSiteUrl, dateOfDeferred: new Date().getTime()});
28+
29+
bg.deferredRestrictionsList = defList;
30+
31+
chrome.tabs.query({ currentWindow: true, active: true }, function(tab) {
32+
chrome.tabs.update(tab.id, { url: blockSiteUrl });
33+
});
34+
});
35+
});
1836
});

src/scripts/common.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ var STORAGE_NOTIFICATION_LIST = 'notification_list';
3434
var STORAGE_NOTIFICATION_MESSAGE = 'notification_message';
3535
var STORAGE_TIMEINTERVAL_LIST = 'time_interval';
3636

37+
var DEFERRED_TIMEOUT = 300000;
38+
3739
var SETTINGS_INTERVAL_INACTIVITY_DEFAULT = InactivityInterval.second30;
3840
var SETTINGS_INTERVAL_CHECK_DEFAULT = 1000;
39-
var SETTINGS_INTERVAL_SAVE_STORAGE_DEFAULT = 2000;
40-
var SETTINGS_INTERVAL_CHECK_STORAGE_DEFAULT = 3000;
41+
var SETTINGS_INTERVAL_SAVE_STORAGE_DEFAULT = 5000;
4142
var SETTINGS_INTERVAL_RANGE_DEFAULT = RangeForDays.days7;
4243
var SETTINGS_VIEW_TIME_IN_BADGE_DEFAULT = true;
4344
var SETTINGS_DARK_MODE_DEFAULT = false;
@@ -202,6 +203,22 @@ function isDomainEquals(first, second) {
202203
}
203204
}
204205

206+
function extractHostname(url) {
207+
var hostname;
208+
209+
if (url.indexOf("//") > -1) {
210+
hostname = url.split('/')[2];
211+
}
212+
else {
213+
hostname = url.split('/')[0];
214+
}
215+
216+
hostname = hostname.split(':')[0];
217+
hostname = hostname.split('?')[0];
218+
219+
return hostname;
220+
}
221+
205222
function treatAsUTC(date) {
206223
var result = new Date(date);
207224
result.setMinutes(result.getMinutes() - result.getTimezoneOffset());

src/style/block.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ body{
3535
position: absolute;
3636
bottom: 30px;
3737
right: 30px;
38+
}
39+
40+
.defferer-link{
41+
color: gray;
42+
text-decoration: underline;
43+
cursor: pointer;
3844
}

src/style/chart.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,7 @@ g.slices > path.mouse-over{
109109
.grid path {
110110
stroke-width: 0;
111111
}
112+
113+
#chart{
114+
min-height: 250px;
115+
}

0 commit comments

Comments
 (0)