@@ -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
7478function 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+
8799function 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+
231240function updateBlackList ( ) {
232241 storage . saveSettings ( STORAGE_BLACK_LIST , blackList ) ;
233242}
234243
235244function updateRestrictionList ( ) {
245+ storage . saveSettings ( STORAGE_RESTRICTION_LIST , restrictionList ) ;
236246}
0 commit comments