Skip to content

Commit 3ef8475

Browse files
committed
Add contains in lists
1 parent cc07124 commit 3ef8475

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

scripts/settings.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function viewBlackList(items) {
8888
}
8989
}
9090

91-
function viewRestrictionList(items){
91+
function viewRestrictionList(items) {
9292
if (items !== undefined) {
9393
for (var i = 0; i < items.length; i++) {
9494
addDomainToRestrictionListBox(items[i]);
@@ -110,27 +110,33 @@ function viewNotify() {
110110
function addNewBlackSiteClickHandler() {
111111
var newBlackSite = document.getElementById('addBlackSiteLbl').value;
112112
if (newBlackSite !== '') {
113-
addDomainToListBox(newBlackSite);
114-
if (blackList === undefined)
115-
blackList = [];
116-
blackList.push(newBlackSite);
117-
document.getElementById('addBlackSiteLbl').value = '';
113+
if (!isContainsBlackSite(newBlackSite)) {
114+
addDomainToListBox(newBlackSite);
115+
if (blackList === undefined)
116+
blackList = [];
117+
blackList.push(newBlackSite);
118+
document.getElementById('addBlackSiteLbl').value = '';
119+
120+
updateBlackList();
121+
}
118122
}
119-
updateBlackList();
120123
}
121124

122125
function addNewRestrictionSiteClickHandler() {
123126
var newRestrictionSite = document.getElementById('addRestrictionSiteLbl').value;
124127
var newRestrictionTime = document.getElementById('addRestrictionTimeLbl').value;
125128
if (newRestrictionSite !== '' && newRestrictionTime !== '') {
126-
addDomainToRestrictionListBox(new Restriction(newRestrictionSite, newRestrictionTime));
127-
if (restrictionList === undefined)
128-
restrictionList = [];
129-
restrictionList.push(new Restriction(newRestrictionSite, newRestrictionTime));
130-
document.getElementById('addRestrictionSiteLbl').value = '';
131-
document.getElementById('addRestrictionTimeLbl').value = '';
129+
if (!isContainsRestrictionSite(newRestrictionSite)) {
130+
addDomainToRestrictionListBox(new Restriction(newRestrictionSite, newRestrictionTime));
131+
if (restrictionList === undefined)
132+
restrictionList = [];
133+
restrictionList.push(new Restriction(newRestrictionSite, newRestrictionTime));
134+
document.getElementById('addRestrictionSiteLbl').value = '';
135+
document.getElementById('addRestrictionTimeLbl').value = '';
136+
137+
updateRestrictionList();
138+
}
132139
}
133-
updateRestrictionList();
134140
}
135141

136142
function addDomainToListBox(domain) {
@@ -233,7 +239,15 @@ function editRestrictionSite(e) {
233239
}
234240
}
235241

236-
function updateItemFromResctrictoinList(domain, time){
242+
function isContainsRestrictionSite(domain) {
243+
return restrictionList.find(x => x.domain == domain) != undefined;
244+
}
245+
246+
function isContainsBlackSite(domain) {
247+
return blackList.find(x => x == domain) != undefined;
248+
}
249+
250+
function updateItemFromResctrictoinList(domain, time) {
237251
restrictionList.find(x => x.domain === domain).time = time;
238252
}
239253

0 commit comments

Comments
 (0)