@@ -23,7 +23,7 @@ var _SearchHelper2 = _interopRequireDefault(_SearchHelper);
23
23
24
24
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
25
25
26
- var SETTINGS = {
26
+ const SETTINGS = {
27
27
MAX_SUGGESTIONS : 6
28
28
29
29
/**
@@ -37,7 +37,7 @@ Object.assign(_wikiEn2.default, _wikiTemplate2.default);
37
37
Object . assign ( _wikiPl2 . default , _wikiTemplate2 . default ) ;
38
38
39
39
browser . storage . local . get ( 'engines' ) . then ( function ( result ) {
40
- var engines = [ ] ;
40
+ let engines = [ ] ;
41
41
if ( ! ( 'engines' in result ) || ! Array . isArray ( result . engines ) ) {
42
42
engines = [ _wikiEn2 . default , _wikiPl2 . default ] ;
43
43
browser . storage . local . set ( { 'engines' : engines } ) ;
@@ -56,7 +56,7 @@ browser.storage.local.get('engines').then(function (result) {
56
56
* Prepare omnibox for autocomplete.
57
57
*/
58
58
function prepareOmnibox ( engines ) {
59
- var searchHelper = new _SearchHelper2 . default ( SETTINGS , engines ) ;
59
+ let searchHelper = new _SearchHelper2 . default ( SETTINGS , engines ) ;
60
60
61
61
/**
62
62
* Default suggestion displayed after typing in `sa`.
@@ -68,10 +68,10 @@ function prepareOmnibox(engines) {
68
68
/**
69
69
* Reaction for newly entered phrase.
70
70
*/
71
- browser . omnibox . onInputChanged . addListener ( function ( text , addSuggestions ) {
72
- var engineWithTerm = searchHelper . getEngine ( text ) ;
73
- var searchTerm = engineWithTerm . text ;
74
- var engine = engineWithTerm . engine ;
71
+ browser . omnibox . onInputChanged . addListener ( ( text , addSuggestions ) => {
72
+ let engineWithTerm = searchHelper . getEngine ( text ) ;
73
+ let searchTerm = engineWithTerm . text ;
74
+ let engine = engineWithTerm . engine ;
75
75
// no keyword matched
76
76
if ( engine === null ) {
77
77
console . log ( 'no keyword matched' ) ;
@@ -82,12 +82,12 @@ function prepareOmnibox(engines) {
82
82
console . log ( 'no phrase typed in yet after the keyword' ) ;
83
83
return ;
84
84
}
85
- var action = engine . autocompleteAction ;
86
- var headers = new Headers ( { 'Accept' : action . type } ) ;
87
- var init = { method : action . method , headers : headers } ;
88
- var url = searchHelper . buildSearchUrl ( engine , action , searchTerm ) ;
85
+ let action = engine . autocompleteAction ;
86
+ let headers = new Headers ( { 'Accept' : action . type } ) ;
87
+ let init = { method : action . method , headers } ;
88
+ let url = searchHelper . buildSearchUrl ( engine , action , searchTerm ) ;
89
89
console . log ( 'searchTerm:' , searchTerm , 'url:' , url , 'engine:' , engine ) ;
90
- var request = new Request ( url , init ) ;
90
+ let request = new Request ( url , init ) ;
91
91
92
92
fetch ( request ) . then ( function ( response ) {
93
93
return searchHelper . createSuggestionsFromResponse ( engine , response ) ;
@@ -97,15 +97,15 @@ function prepareOmnibox(engines) {
97
97
/**
98
98
* React to choosen phrase or suggestion.
99
99
*/
100
- browser . omnibox . onInputEntered . addListener ( function ( text , disposition ) {
100
+ browser . omnibox . onInputEntered . addListener ( ( text , disposition ) => {
101
101
console . log ( 'onInputEntered: ' , text , disposition ) ;
102
102
// if suggestion was choosen then the text should contain a go-to URL
103
- var url = text ;
103
+ let url = text ;
104
104
// suggestion was not choosen, must build URL
105
105
if ( text . search ( / ^ h t t p s ? : / ) !== 0 ) {
106
- var engineWithTerm = searchHelper . getEngine ( text ) ;
107
- var searchTerm = engineWithTerm . text ;
108
- var engine = engineWithTerm . engine ;
106
+ let engineWithTerm = searchHelper . getEngine ( text ) ;
107
+ let searchTerm = engineWithTerm . text ;
108
+ let engine = engineWithTerm . engine ;
109
109
// no valid search to go to
110
110
if ( engine === null || ! searchTerm . length ) {
111
111
console . log ( 'no valid search to go to' , {
@@ -126,13 +126,13 @@ function prepareOmnibox(engines) {
126
126
// create or update tab as expected
127
127
switch ( disposition ) {
128
128
case 'currentTab' :
129
- browser . tabs . update ( { url : url } ) ;
129
+ browser . tabs . update ( { url } ) ;
130
130
break ;
131
131
case 'newForegroundTab' :
132
- browser . tabs . create ( { url : url } ) ;
132
+ browser . tabs . create ( { url } ) ;
133
133
break ;
134
134
case 'newBackgroundTab' :
135
- browser . tabs . create ( { url : url , active : false } ) ;
135
+ browser . tabs . create ( { url, active : false } ) ;
136
136
break ;
137
137
}
138
138
} ) ;
@@ -220,9 +220,6 @@ exports.default = SearchEngine;
220
220
Object . defineProperty ( exports , "__esModule" , {
221
221
value : true
222
222
} ) ;
223
-
224
- var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
225
-
226
223
function SearchEngineAction ( action ) {
227
224
this . url = '' ;
228
225
if ( typeof action . url === 'string' ) {
@@ -237,7 +234,7 @@ function SearchEngineAction(action) {
237
234
this . type = action . type ;
238
235
}
239
236
this . data = { } ;
240
- if ( _typeof ( action . data ) === 'object' ) {
237
+ if ( typeof action . data === 'object' ) {
241
238
this . data = action . data ;
242
239
}
243
240
}
@@ -251,8 +248,6 @@ Object.defineProperty(exports, "__esModule", {
251
248
value : true
252
249
} ) ;
253
250
254
- var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
255
-
256
251
var _SearchEngine = require ( './SearchEngine.js' ) ;
257
252
258
253
var _SearchEngine2 = _interopRequireDefault ( _SearchEngine ) ;
@@ -279,7 +274,7 @@ function SearchHelper(SETTINGS, engines) {
279
274
this . engineMap = engines ;
280
275
}
281
276
// figure out default (unless explictly defined)
282
- if ( _typeof ( this . engineMap . default ) !== 'object' ) {
277
+ if ( typeof this . engineMap . default !== 'object' ) {
283
278
var firstKeyword = Object . keys ( this . engineMap ) [ 0 ] ;
284
279
this . engineMap . default = this . engineMap [ firstKeyword ] ;
285
280
}
@@ -290,11 +285,11 @@ function SearchHelper(SETTINGS, engines) {
290
285
* @param {Array } engines An array of search engines with `keywords` property.
291
286
*/
292
287
SearchHelper . prototype . buildEngineMap = function ( engines ) {
293
- var engineMap = { } ;
294
- for ( var i = 0 ; i < engines . length ; i ++ ) {
288
+ let engineMap = { } ;
289
+ for ( let i = 0 ; i < engines . length ; i ++ ) {
295
290
var engine = new _SearchEngine2 . default ( engines [ i ] ) ;
296
291
var keywords = engine . keywords ;
297
- for ( var k = 0 ; k < keywords . length ; k ++ ) {
292
+ for ( let k = 0 ; k < keywords . length ; k ++ ) {
298
293
var key = keywords [ k ] ;
299
294
engineMap [ key ] = engine ;
300
295
}
@@ -310,12 +305,12 @@ SearchHelper.prototype.buildEngineMap = function (engines) {
310
305
* @param {String } text Search term.
311
306
*/
312
307
SearchHelper . prototype . buildSearchUrl = function ( engine , action , text ) {
313
- var url = action . url . replace ( '{baseUrl}' , engine . baseUrl ) ;
314
- var first = true ;
315
- for ( var key in action . data ) {
316
- var value = action . data [ key ] . replace ( '{searchTerms}' , text ) ;
308
+ let url = action . url . replace ( '{baseUrl}' , engine . baseUrl ) ;
309
+ let first = true ;
310
+ for ( let key in action . data ) {
311
+ let value = action . data [ key ] . replace ( '{searchTerms}' , text ) ;
317
312
url += first ? '?' : '&' ;
318
- url += key + '=' + encodeURIComponent ( value ) ;
313
+ url += ` ${ key } =` + encodeURIComponent ( value ) ;
319
314
first = false ;
320
315
}
321
316
return url ;
@@ -338,8 +333,8 @@ SearchHelper.prototype.buildSearchUrl = function (engine, action, text) {
338
333
* @return {EngineWithTerm } Engine with term stripped from the engine keyowrd.
339
334
*/
340
335
SearchHelper . prototype . getEngine = function ( text ) {
341
- var keyword = null ;
342
- var me = this ;
336
+ let keyword = null ;
337
+ let me = this ;
343
338
text . replace ( / ^ ( \S * ) \s + ( .* ) $ / , function ( a , word , rest ) {
344
339
if ( ! word . length ) {
345
340
keyword = 'default' ;
@@ -349,7 +344,7 @@ SearchHelper.prototype.getEngine = function (text) {
349
344
text = rest ;
350
345
}
351
346
} ) ;
352
- var engine = void 0 ;
347
+ let engine ;
353
348
if ( keyword === null ) {
354
349
engine = null ;
355
350
} else {
@@ -368,44 +363,42 @@ SearchHelper.prototype.getEngine = function (text) {
368
363
* @param {Object } response The search engine response.
369
364
*/
370
365
SearchHelper . prototype . createSuggestionsFromResponse = function ( engine , response ) {
371
- var _this = this ;
372
-
373
- return new Promise ( function ( resolve ) {
374
- var suggestions = [ ] ;
375
- var suggestionsOnEmptyResults = [ {
366
+ return new Promise ( resolve => {
367
+ let suggestions = [ ] ;
368
+ let suggestionsOnEmptyResults = [ {
376
369
content : engine . baseUrl ,
377
370
description : 'No results found'
378
371
} ] ;
379
- response . json ( ) . then ( function ( json ) {
372
+ response . json ( ) . then ( json => {
380
373
console . log ( 'response:' , json ) ;
381
374
if ( ! json . length ) {
382
375
return resolve ( suggestionsOnEmptyResults ) ;
383
376
}
384
377
385
- var max = _this . SETTINGS . MAX_SUGGESTIONS ;
378
+ let max = this . SETTINGS . MAX_SUGGESTIONS ;
386
379
387
380
// for Wikipedia:
388
381
// json[0] = search term
389
382
// json[1] = [...titles...]
390
383
// json[2] = [...descriptions...]
391
384
// json[3] = [...direct urls...]
392
- var titles = json [ 1 ] ;
393
- var descriptions = json [ 2 ] ;
394
- var urls = json [ 3 ] ;
385
+ let titles = json [ 1 ] ;
386
+ let descriptions = json [ 2 ] ;
387
+ let urls = json [ 3 ] ;
395
388
396
389
if ( titles . length < 1 ) {
397
390
return resolve ( suggestionsOnEmptyResults ) ;
398
391
}
399
392
400
- var count = Math . min ( titles . length , max ) ;
401
- for ( var i = 0 ; i < count ; i ++ ) {
393
+ let count = Math . min ( titles . length , max ) ;
394
+ for ( let i = 0 ; i < count ; i ++ ) {
402
395
// gather data
403
- var title = titles [ i ] ;
404
- var description = title ;
396
+ let title = titles [ i ] ;
397
+ let description = title ;
405
398
if ( descriptions && typeof descriptions [ i ] === 'string' ) {
406
- description += ' -- ' + descriptions [ i ] ;
399
+ description += ` -- ${ descriptions [ i ] } ` ;
407
400
}
408
- var url = '' ;
401
+ let url = '' ;
409
402
if ( urls && typeof urls [ i ] === 'string' ) {
410
403
url = urls [ i ] ;
411
404
} else {
0 commit comments