Skip to content

Commit deffee2

Browse files
hai-altx-softStigmatoz
authored andcommitted
Add validation domain (www & whitout www) for add to restriction list
1 parent c749cbf commit deffee2

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

block.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="content">
1313
<img src="icons/time.svg" height="50">
1414
<p class="title">Time limit</p>
15-
<div class="description">You've reached today your limit on <span id='site' class="current-site">youtube.com</span></div>
15+
<div class="description">You've reached today your limit on <span id='site' class="current-site"></span></div>
1616
</div>
1717
</body>
1818

scripts/activity.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Activity {
99
this.setCurrentActiveTab(domain);
1010
if (this.isNewUrl(domain) && !this.isInBlackList(domain)) {
1111
var favicon = tab.favIconUrl;
12-
if (favicon === undefined){
12+
if (favicon === undefined) {
1313
favicon = 'chrome://favicon/' + domain;
1414
}
1515
var newTab = new Tab(domain, favicon);
@@ -28,26 +28,45 @@ class Activity {
2828
return true;
2929
}
3030

31-
isInBlackList(domain){
31+
isInBlackList(domain) {
3232
if (setting_black_list !== undefined && setting_black_list.length > 0)
3333
return setting_black_list.find(o => o === domain) !== undefined;
3434
else return false;
3535
}
3636

37-
isLimitExceeded(domain, tab){
38-
if (setting_restriction_list !== undefined && setting_restriction_list.length > 0){
39-
var item = setting_restriction_list.find(o => o.domain === domain);
40-
if (item !== undefined){
41-
var today = new Date().toLocaleDateString();
42-
var todayTimeUse = tab.days.find(x => x.date == today).summary;
43-
if (todayTimeUse >= item.time){
44-
return true;
45-
}
46-
}
37+
isLimitExceeded(domain, tab) {
38+
if (setting_restriction_list !== undefined && setting_restriction_list.length > 0) {
39+
var item = setting_restriction_list.find(o => this.isDomainEquals(o.domain, domain));
40+
if (item !== undefined) {
41+
var today = new Date().toLocaleDateString();
42+
var data = tab.days.find(x => x.date == today);
43+
if (data !== undefined) {
44+
var todayTimeUse = data.summary;
45+
if (todayTimeUse >= item.time) {
46+
return true;
47+
}
48+
}
49+
}
4750
}
4851
return false;
4952
}
5053

54+
isDomainEquals(first, second) {
55+
if (first === second)
56+
return true;
57+
else {
58+
var resultUrl = function (url) {
59+
if (url.indexOf('www.') > -1)
60+
return url.split('www.')[1];
61+
return url;
62+
};
63+
64+
if (resultUrl(first) === resultUrl(second))
65+
return true;
66+
else return false;
67+
}
68+
}
69+
5170
isNewUrl(domain) {
5271
if (tabs.length > 0)
5372
return tabs.find(o => o.url === domain) === undefined;
@@ -74,25 +93,25 @@ class Activity {
7493
return hostname;
7594
}
7695

77-
loadDataFromStorage(){
96+
loadDataFromStorage() {
7897
var tabs = storage.load(STORAGE_TABS);
7998
}
8099

81-
updateFavicon(tab){
100+
updateFavicon(tab) {
82101
var domain = this.extractHostname(tab.url);
83102
var currentTab = this.getTab(domain);
84-
if (currentTab !== null && currentTab !== undefined){
85-
if (tab.favIconUrl !== undefined && tab.favIconUrl !== currentTab.favicon){
103+
if (currentTab !== null && currentTab !== undefined) {
104+
if (tab.favIconUrl !== undefined && tab.favIconUrl !== currentTab.favicon) {
86105
currentTab.favicon = tab.favIconUrl;
87106
}
88107
}
89108
}
90109

91-
setCurrentActiveTab(domain){
110+
setCurrentActiveTab(domain) {
92111
currentTab = domain;
93112
}
94113

95-
clearCurrentActiveTab(){
114+
clearCurrentActiveTab() {
96115
currentTab = '';
97116
}
98117
};

0 commit comments

Comments
 (0)