1+ const backgroundPage = chrome . extension . getBackgroundPage ( ) ;
2+ const Provider = backgroundPage . Provider ; // class Provider
3+ const msgTimeout = 1800 ;
4+
15/** Utility Functions **/
26const $ = document . querySelector . bind ( document ) ;
37const $$ = document . querySelectorAll . bind ( document ) ;
48const $el = document . createElement . bind ( document ) ;
9+
510function i18nOrdinal ( n ) {
611 const [ prefix , suffix ] = chrome . i18n . getUILanguage ( ) . split ( '-' , 2 ) ;
712 if ( prefix === 'en' ) {
@@ -18,7 +23,7 @@ function alertErrorMsgElement(text) {
1823 $ ( '#alertMessages' ) . appendChild ( msg ) ;
1924 setTimeout ( ( ) => {
2025 msg . remove ( ) ;
21- } , 1800 ) ;
26+ } , msgTimeout ) ;
2227}
2328
2429function createErrorMsgElement ( text ) {
@@ -49,18 +54,18 @@ function validateSpUrl(url, index) {
4954
5055function createSpRemoveElement ( ) {
5156 // <a class="sp-remove input-group-addon">
52- // <i class="fa fa-trash" aria-hidden="true"></i>
57+ // <i class="fa fa-trash" aria-hidden="true"></i>
5358 // </a>
5459 const a = $el ( 'a' ) ;
5560 a . classList . add ( 'sp-remove' , 'input-group-addon' ) ;
56- a . innerHTML = ` <i class="fa fa-trash" aria-hidden="true"></i>` ;
61+ a . innerHTML = ' <i class="fa fa-trash" aria-hidden="true"></i>' ;
5762 return a ;
5863}
5964
6065function createSpStatusElement ( ) {
6166 // <a class="sp-status input-group-addon">
62- // <i class="fa fa-check text-success" aria-hidden="true"></i>
63- // <i class="fa fa-times text-danger" aria-hidden="true"></i>
67+ // <i class="fa fa-check text-success" aria-hidden="true"></i>
68+ // <i class="fa fa-times text-danger" aria-hidden="true"></i>
6469 // </a>
6570 const a = $el ( 'a' ) ;
6671 a . classList . add ( 'sp-status' , 'input-group-addon' ) ;
@@ -86,29 +91,29 @@ function createSpNameElement(text) {
8691 input . classList . add ( 'sp-name' , 'form-control' , 'col-sm-3' , 'sp-edit' ) ;
8792 input . pattern = '\\S{2,9}' ;
8893 input . placeholder = chrome . i18n . getMessage ( 'providerNamePlaceholder' ) ;
89- input . onclick = event => {
94+ input . onclick = ( ) => {
9095 input . classList . add ( 'sp-edit' ) ;
9196 } ;
9297 return input ;
9398}
9499
95100function createSpIconElement ( src ) {
96- // <span class="sp-icon input-group-addon">
97- // <img src=""/>
98- // </span>
101+ // <span class="sp-icon input-group-addon">
102+ // <img src=""/>
103+ // </span>
99104 const span = $el ( 'span' ) ;
100105 span . innerHTML = `<img src="${ src } "/>` ;
101106 span . classList . add ( 'sp-icon' , 'input-group-addon' ) ;
102107 return span ;
103108}
104109
105110function createSpCheckboxElement ( selected ) {
106- // <span class="sp-selected input-group-addon form-check">
107- // <label class="form-check-label custom-control custom-checkbox">
108- // <input class="form-check-input custom-control-input" type="checkbox" />
109- // <span class="custom-control-indicator" />
110- // </label>
111- // </span>
111+ // <span class="sp-selected input-group-addon form-check">
112+ // <label class="form-check-label custom-control custom-checkbox">
113+ // <input class="form-check-input custom-control-input" type="checkbox" />
114+ // <span class="custom-control-indicator" />
115+ // </label>
116+ // </span>
112117 const span = $el ( 'span' ) ;
113118 span . innerHTML = `
114119 <label class="form-check-label custom-control custom-checkbox">
@@ -189,10 +194,10 @@ addSearchProvider.onclick = () => {
189194const restoreDefaultSearchProviders = $ ( '#restoreDefaultSearchProviders' ) ;
190195restoreDefaultSearchProviders . textContent = chrome . i18n . getMessage ( 'restoreDefaultSearchProviders' ) ;
191196restoreDefaultSearchProviders . onclick = ( ) => {
192- while ( searchProviderList . firstChild ) {
193- searchProviderList . removeChild ( searchProviderList . firstChild ) ;
197+ for ( const p of searchProviderList . children ) {
198+ p . remove ( ) ;
194199 }
195- for ( let p of chrome . extension . getBackgroundPage ( ) . getDefaultProvidersClone ( ) ) {
200+ for ( const p of backgroundPage . getDefaultProvidersClone ( ) ) {
196201 searchProviderList . appendChild ( createSearchProviderElement ( p . name , p . icon , p . url , p . selected , false ) ) ;
197202 }
198203} ;
@@ -212,7 +217,7 @@ saveOptions.onclick = () => {
212217 storageProviders : [ ] ,
213218 } ;
214219
215- for ( let li of searchProviderList . children ) {
220+ for ( const li of searchProviderList . children ) {
216221 const index = Array . from ( searchProviderList . children ) . indexOf ( li ) + 1 ;
217222 const selected = li . children [ 0 ] . firstElementChild . firstElementChild . checked ;
218223 const icon = li . children [ 1 ] . firstElementChild . src ;
@@ -236,7 +241,7 @@ saveOptions.onclick = () => {
236241 return ;
237242 }
238243
239- storedSettings . storageProviders . push ( { name, url, icon, selected } ) ;
244+ storedSettings . storageProviders . push ( new Provider ( name , url , icon , selected ) ) ;
240245 nameSet . add ( name ) ;
241246 }
242247
@@ -252,15 +257,15 @@ saveOptions.onclick = () => {
252257
253258 /* All input valid */
254259 chrome . contextMenus . removeAll ( ) ;
255- chrome . extension . getBackgroundPage ( ) . createContextMenu ( storedSettings . storageProviders ) ;
260+ backgroundPage . createContextMenu ( storedSettings . storageProviders ) ;
256261 chrome . storage . sync . set ( storedSettings , ( ) => {
257- for ( let msg of Array . from ( $$ ( '.alert-danger' ) ) ) {
262+ for ( const msg of $$ ( '.alert-danger' ) ) {
258263 msg . classList . add ( 'hidden' ) ;
259264 }
260265 $ ( '.alert-success' ) . classList . remove ( 'hidden' ) ;
261266 setTimeout ( ( ) => {
262267 $ ( '.alert-success' ) . classList . add ( 'hidden' ) ;
263- } , 1800 ) ;
268+ } , msgTimeout ) ;
264269 } ) ;
265270} ;
266271
@@ -271,7 +276,7 @@ function updateUI(storedSettings) {
271276 . indexOf ( storedSettings . openTabAt ) ;
272277 $ ( '#openInBackground' ) . checked = storedSettings . openInBackground ;
273278
274- for ( let p of storedSettings . storageProviders ) {
279+ for ( const p of storedSettings . storageProviders ) {
275280 $ ( '#searchProviderList' ) . appendChild ( createSearchProviderElement ( p . name , p . icon , p . url , p . selected , false ) ) ;
276281 }
277282}
0 commit comments