Skip to content

Commit d01411c

Browse files
committed
Edit restriction site part 4
1 parent 393792f commit d01411c

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"scripts/storage.js",
3333
"scripts/activity.js",
3434
"scripts/tab.js",
35-
"scripts/background.js"],
35+
"scripts/background.js",
36+
"scripts/restriction.js"],
3637
"persistent": false
3738
},
3839
"browser_action": {

options.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="scripts/common.js"></script>
99
<script src="scripts/storage.js"></script>
1010
<script src="scripts/settings.js"></script>
11+
<script src="scripts/restriction.js"></script>
1112
</head>
1213

1314
<body>

scripts/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var TypeListEnum = {
2929

3030
var STORAGE_TABS = 'tabs';
3131
var STORAGE_BLACK_LIST = 'black_list';
32+
var STORAGE_RESTRICTION_LIST = 'restriction_list';
3233

3334
var SETTINGS_INTERVAL_INACTIVITY_DEFAULT = InactivityInterval.second30;
3435
var SETTINGS_INTERVAL_CHECK_DEFAULT = 1000;

scripts/restriction.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
class Restriction {
4+
constructor(domain, time) {
5+
this.domain = domain;
6+
this.time = time;
7+
}
8+
};

scripts/settings.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function loadSettings() {
6969
blackList = items;
7070
viewBlackList(items);
7171
});
72+
storage.getSettings(STORAGE_RESTRICTION_LIST, function (items) {
73+
restrictionList = items;
74+
viewRestrictionList(items);
75+
});
7276
}
7377

7478
function loadVersion() {
@@ -84,6 +88,14 @@ function viewBlackList(items) {
8488
}
8589
}
8690

91+
function viewRestrictionList(items){
92+
if (items !== undefined) {
93+
for (var i = 0; i < items.length; i++) {
94+
addDomainToRestrictionListBox(items[i]);
95+
}
96+
}
97+
}
98+
8799
function clearAllData() {
88100
var tabs = [];
89101
chrome.extension.getBackgroundPage().tabs = tabs;
@@ -111,10 +123,10 @@ function addNewRestrictionSiteClickHandler() {
111123
var newRestrictionSite = document.getElementById('addRestrictionSiteLbl').value;
112124
var newRestrictionTime = document.getElementById('addRestrictionTimeLbl').value;
113125
if (newRestrictionSite !== '' && newRestrictionTime !== '') {
114-
addDomainToRestrictionListBox(newRestrictionSite, newRestrictionTime);
126+
addDomainToRestrictionListBox(new Restriction(newRestrictionSite, newRestrictionTime));
115127
if (restrictionList === undefined)
116128
restrictionList = [];
117-
restrictionList.push(newRestrictionSite);
129+
restrictionList.push(new Restriction(newRestrictionSite, newRestrictionTime));
118130
document.getElementById('addRestrictionSiteLbl').value = '';
119131
document.getElementById('addRestrictionTimeLbl').value = '';
120132
}
@@ -133,13 +145,13 @@ function addDomainToListBox(domain) {
133145
document.getElementById('blackList').appendChild(li).appendChild(del);
134146
}
135147

136-
function addDomainToRestrictionListBox(domain, time) {
148+
function addDomainToRestrictionListBox(resctiction) {
137149
var li = document.createElement('li');
138150

139151
var domainLbl = document.createElement('input');
140152
domainLbl.type = 'text';
141153
domainLbl.classList.add('readonly-input', 'inline-block', 'restriction-item');
142-
domainLbl.value = domain;
154+
domainLbl.value = resctiction.domain;
143155
domainLbl.readOnly = true;
144156
domainLbl.setAttribute('name', 'domain');
145157

@@ -160,7 +172,7 @@ function addDomainToRestrictionListBox(domain, time) {
160172
});
161173

162174
var timeElement = document.createElement('input');
163-
var timeArray = time.split(':');
175+
var timeArray = resctiction.time.split(':');
164176
var resultTime = timeArray[0] + 'h ' + timeArray[1] + 'm';
165177
timeElement.type = 'text';
166178
timeElement.value = resultTime;
@@ -195,10 +207,7 @@ function editRestrictionSite(e) {
195207
var targetElement = e.path[1];
196208
var domainElement = targetElement.querySelector('[name="domain"]');
197209
var timeElement = targetElement.querySelector('[name="time"]');
198-
var sourceDomain = domainElement.value;
199-
if (domainElement.readOnly == true && timeElement.readOnly == true) {
200-
domainElement.readOnly = false;
201-
domainElement.classList.remove('readonly-input');
210+
if (timeElement.readOnly == true) {
202211
timeElement.classList.remove('readonly-input');
203212
timeElement.readOnly = false;
204213
var timeText = targetElement.querySelector('[name="time"]').value;
@@ -215,22 +224,23 @@ function editRestrictionSite(e) {
215224
if (domain !== '' && time !== '') {
216225
var editCmd = targetElement.querySelector('[name="editCmd"]');
217226
editCmd.src = '/icons/edit.png';
218-
domainElement.classList.add('readonly-input');
219-
domainElement.readOnly = true;
220227
timeElement.classList.add('readonly-input');
221228
timeElement.readOnly = true;
229+
updateItemFromResctrictoinList(domain, time);
222230

223231
updateRestrictionList();
224232
}
225-
else{
226-
227-
}
228233
}
229234
}
230235

236+
function updateItemFromResctrictoinList(domain, time){
237+
restrictionList.find(x => x.domain === domain).time = time;
238+
}
239+
231240
function updateBlackList() {
232241
storage.saveSettings(STORAGE_BLACK_LIST, blackList);
233242
}
234243

235244
function updateRestrictionList() {
245+
storage.saveSettings(STORAGE_RESTRICTION_LIST, restrictionList);
236246
}

0 commit comments

Comments
 (0)