Skip to content

Commit 3dbf539

Browse files
committed
refactor: format with prettier & eslint
1 parent 49e4801 commit 3dbf539

File tree

6 files changed

+283
-176
lines changed

6 files changed

+283
-176
lines changed

.eslintrc.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* global module */
22

33
module.exports = {
4-
'env': {
5-
'es2017': true,
6-
'browser': true,
7-
'webextensions': true,
4+
env: {
5+
es2017: true,
6+
browser: true,
7+
webextensions: true,
88
},
9-
'extends': ['eslint:recommended', 'google'],
10-
'parserOptions': {
11-
'ecmaVersion': 11,
9+
extends: ['eslint:recommended', 'google'],
10+
parserOptions: {
11+
ecmaVersion: 11,
1212
},
13-
'rules': {
13+
rules: {
1414
'require-jsdoc': 0,
1515
},
1616
};

gulpfile.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const extraFiles = [
2020
exports.default = () => {
2121
return gulp
2222
.src(extraFiles)
23-
// only minify in production
2423
.pipe(gulpif(argv.env === 'production', terser()))
2524
.pipe(gulp.dest('./src'));
2625
};

src/main.js

+49-25
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class SearchResultsManager {
7070
}
7171
return this.searchResults[this.focusedIndex].anchor;
7272
}
73-
const isLink = focusedElement.localName === 'a' &&
74-
focusedElement.hasAttribute('href');
73+
const isLink =
74+
focusedElement.localName === 'a' && focusedElement.hasAttribute('href');
7575
if (!linkOnly || isLink) {
7676
return focusedElement;
7777
}
@@ -214,7 +214,8 @@ class WebSearchNavigator {
214214

215215
initSearchInputNavigation() {
216216
const searchInput = document.querySelector(
217-
this.searchEngine.searchBoxSelector);
217+
this.searchEngine.searchBoxSelector,
218+
);
218219
if (searchInput == null) {
219220
return;
220221
}
@@ -235,8 +236,10 @@ class WebSearchNavigator {
235236
return !shouldHandleSearchInputKey(event);
236237
}
237238
const element = document.activeElement;
238-
if (element.isContentEditable || ['textarea', 'input'].includes(
239-
element.tagName.toLowerCase())) {
239+
if (
240+
element.isContentEditable ||
241+
['textarea', 'input'].includes(element.tagName.toLowerCase())
242+
) {
240243
return true;
241244
}
242245
// Scroll to the search box in case it's outside the viewport so that it's
@@ -252,13 +255,17 @@ class WebSearchNavigator {
252255
return true;
253256
}
254257
// Everything is selected; deselect all.
255-
if (searchInput.selectionStart === 0 &&
256-
searchInput.selectionEnd === searchInput.value.length) {
258+
if (
259+
searchInput.selectionStart === 0 &&
260+
searchInput.selectionEnd === searchInput.value.length
261+
) {
257262
// Scroll to the search box in case it's outside the viewport so that
258263
// it's clear to the user that it has focus.
259264
scrollToElement(this.searchEngine, searchInput);
260265
searchInput.setSelectionRange(
261-
searchInput.value.length, searchInput.value.length);
266+
searchInput.value.length,
267+
searchInput.value.length,
268+
);
262269
return false;
263270
}
264271
// Closing search suggestions via document.body.click() or
@@ -274,15 +281,21 @@ class WebSearchNavigator {
274281
// focus.
275282
return true;
276283
};
277-
this.register(this.options.sync.get('focusSearchInput'),
278-
outsideSearchboxHandler);
284+
this.register(
285+
this.options.sync.get('focusSearchInput'),
286+
outsideSearchboxHandler,
287+
);
279288
// Bind globally, otherwise Mousetrap ignores keypresses inside inputs.
280289
// We must bind it separately to the search box element, or otherwise the
281290
// key event won't always be captured (for example this is the case on
282291
// Google Search as of 2020-06-22), presumably because the javascript in the
283292
// page will disable further processing.
284-
this.register(this.options.sync.get('focusSearchInput'),
285-
insideSearchboxHandler, searchInput, true);
293+
this.register(
294+
this.options.sync.get('focusSearchInput'),
295+
insideSearchboxHandler,
296+
searchInput,
297+
true,
298+
);
286299
}
287300

288301
initTabsNavigation() {
@@ -321,15 +334,18 @@ class WebSearchNavigator {
321334
resetResultsManager() {
322335
if (this.resultsManager != null) {
323336
const searchResult = this.resultsManager.searchResults[
324-
this.resultsManager.focusedIndex];
337+
this.resultsManager.focusedIndex
338+
];
325339
// NOTE: it seems that search results can become undefined when the DOM
326340
// elements are removed (for example when the results change).
327341
if (searchResult != null) {
328342
this.resultsManager.unhighlight(searchResult);
329343
}
330344
}
331-
this.resultsManager = new SearchResultsManager(this.searchEngine,
332-
this.options.sync.getAll());
345+
this.resultsManager = new SearchResultsManager(
346+
this.searchEngine,
347+
this.options.sync.getAll(),
348+
);
333349
this.resultsManager.reloadSearchResults();
334350
this.isFirstNavigation = true;
335351
if (this.resultsManager.searchResults.length === 0) {
@@ -371,15 +387,15 @@ class WebSearchNavigator {
371387
}
372388
return false;
373389
});
374-
this.register(getOpt('navigateKey'), () => {
390+
this.register(getOpt('navigateKey'), async () => {
375391
const link = this.resultsManager.getElementToNavigate();
376392
if (link == null) {
377393
return true;
378394
}
379395
const lastNavigation = this.options.local.values;
380396
lastNavigation.lastQueryUrl = location.href;
381397
lastNavigation.lastFocusedIndex = this.resultsManager.focusedIndex;
382-
this.options.local.save();
398+
await this.options.local.save();
383399
// If the element is a link, use the href to directly navigate, since some
384400
// websites will open it in a new tab.
385401
if (link.localName === 'a' && link.href) {
@@ -427,21 +443,29 @@ class WebSearchNavigator {
427443
return this.options.sync.get(key);
428444
};
429445
this.register(getOpt('navigateShowAll'), () =>
430-
this.searchEngine.changeTools('a'));
446+
this.searchEngine.changeTools('a'),
447+
);
431448
this.register(getOpt('navigateShowHour'), () =>
432-
this.searchEngine.changeTools('h'));
449+
this.searchEngine.changeTools('h'),
450+
);
433451
this.register(getOpt('navigateShowDay'), () =>
434-
this.searchEngine.changeTools('d'));
452+
this.searchEngine.changeTools('d'),
453+
);
435454
this.register(getOpt('navigateShowWeek'), () =>
436-
this.searchEngine.changeTools('w'));
455+
this.searchEngine.changeTools('w'),
456+
);
437457
this.register(getOpt('navigateShowMonth'), () =>
438-
this.searchEngine.changeTools('m'));
458+
this.searchEngine.changeTools('m'),
459+
);
439460
this.register(getOpt('navigateShowYear'), () =>
440-
this.searchEngine.changeTools('y'));
461+
this.searchEngine.changeTools('y'),
462+
);
441463
this.register(getOpt('toggleVerbatimSearch'), () =>
442-
this.searchEngine.changeTools('v'));
464+
this.searchEngine.changeTools('v'),
465+
);
443466
this.register(getOpt('toggleSort'), () =>
444-
this.searchEngine.changeTools(null));
467+
this.searchEngine.changeTools(null),
468+
);
445469
}
446470

447471
register(shortcuts, callback, element = document, global = false) {

src/options.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ const DEFAULT_KEYBINDINGS = {
8686
navigatePreviousResultPage: ['left', 'h'],
8787
navigateNextResultPage: ['right', 'l'],
8888
navigateKey: ['return', 'space'],
89-
navigateNewTabBackgroundKey:
90-
['ctrl+return', 'command+return', 'ctrl+space'],
91-
navigateNewTabKey:
92-
['ctrl+shift+return', 'command+shift+return', 'ctrl+shift+space'],
89+
navigateNewTabBackgroundKey: ['ctrl+return', 'command+return', 'ctrl+space'],
90+
navigateNewTabKey: [
91+
'ctrl+shift+return',
92+
'command+shift+return',
93+
'ctrl+shift+space',
94+
],
9395
navigateSearchTab: ['a', 's'],
9496
navigateImagesTab: ['i'],
9597
navigateVideosTab: ['v'],
@@ -145,7 +147,9 @@ class BrowserStorage {
145147
this.defaultValues = defaultValues;
146148
}
147149
load() {
148-
return this.storage.get(this.values).then((values) => {
150+
// this.storage.get(null) returns all the data stored:
151+
// https://developer.chrome.com/extensions/storage#method-StorageArea-get
152+
return this.storage.get(null).then((values) => {
149153
this.values = values;
150154
// Prior to versions 0.4.* the keybindings were stored as strings, so we
151155
// migrate them to arrays if needed.

src/options_page.js

+69-41
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const GOOGLE_DOMAINS = [
2727
];
2828

2929
const AMAZON_DOMAINS = [
30-
'ca', 'cn', 'co.jp', 'co.uk', 'com', 'com.au', 'com.br', 'com.mx', 'de', 'es',
31-
'fr', 'in', 'it', 'nl',
30+
'ca',
31+
'cn',
32+
'co.jp',
33+
'co.uk',
34+
'com',
35+
'com.au',
36+
'com.br',
37+
'com.mx',
38+
'de',
39+
'es',
40+
'fr',
41+
'in',
42+
'it',
43+
'nl',
3244
];
3345

3446
const generateURLPatterns = (prefix, domains, suffix) => {
@@ -49,14 +61,14 @@ const OPTIONAL_PERMISSIONS_URLS = {
4961
'https://www.startpage.com/*',
5062
'https://startpage.com/*',
5163
],
52-
'youtube': [
53-
'https://www.youtube.com/*',
54-
],
64+
'youtube': ['https://www.youtube.com/*'],
5565
'google-scholar': generateURLPatterns(
56-
'https://scholar.google', GOOGLE_DOMAINS, '/*'),
66+
'https://scholar.google',
67+
GOOGLE_DOMAINS,
68+
'/*',
69+
),
5770
'github': ['https://github.com/*'],
58-
'amazon': generateURLPatterns(
59-
'https://www.amazon', AMAZON_DOMAINS, '/*'),
71+
'amazon': generateURLPatterns('https://www.amazon', AMAZON_DOMAINS, '/*'),
6072
};
6173

6274
const KEYBINDING_TO_DIV = {
@@ -88,9 +100,9 @@ const KEYBINDING_TO_DIV = {
88100
};
89101

90102
/**
91-
* Add other search engines domain on user input
92-
* @param {Element} checkbox
93-
*/
103+
* Add other search engines domain on user input
104+
* @param {Element} checkbox
105+
*/
94106
const setSearchEnginePermission_ = async (checkbox) => {
95107
const urls = OPTIONAL_PERMISSIONS_URLS[checkbox.id];
96108
if (checkbox.checked) {
@@ -144,26 +156,36 @@ class OptionsPageManager {
144156
this.options.set(key, value);
145157
};
146158
// Handle non-keybindings settings first
147-
setOpt('wrapNavigation',
148-
document.getElementById('wrap-navigation').checked);
149-
setOpt('autoSelectFirst',
150-
document.getElementById( 'auto-select-first').checked);
151-
setOpt('hideOutline',
152-
document.getElementById('hide-outline').checked);
153-
setOpt('delay',
154-
document.getElementById('delay').value);
155-
setOpt('googleIncludeCards',
156-
document.getElementById('google-include-cards').checked);
157-
setOpt('googleIncludeMemex',
158-
document.getElementById('google-include-memex').checked);
159-
setOpt('googleIncludePlaces',
160-
document.getElementById('google-include-places').checked);
159+
setOpt(
160+
'wrapNavigation',
161+
document.getElementById('wrap-navigation').checked,
162+
);
163+
setOpt(
164+
'autoSelectFirst',
165+
document.getElementById('auto-select-first').checked,
166+
);
167+
setOpt('hideOutline', document.getElementById('hide-outline').checked);
168+
setOpt('delay', document.getElementById('delay').value);
169+
setOpt(
170+
'googleIncludeCards',
171+
document.getElementById('google-include-cards').checked,
172+
);
173+
setOpt(
174+
'googleIncludeMemex',
175+
document.getElementById('google-include-memex').checked,
176+
);
177+
setOpt(
178+
'googleIncludePlaces',
179+
document.getElementById('google-include-places').checked,
180+
);
161181
// Handle keybinding options
162182
for (const [key, optName] of Object.entries(KEYBINDING_TO_DIV)) {
163183
// Keybindings are stored internally as arrays, but edited by users as
164184
// comman delimited strings.
165-
setOpt(key, keybindingStringToArray(
166-
document.getElementById(optName).value));
185+
setOpt(
186+
key,
187+
keybindingStringToArray(document.getElementById(optName).value),
188+
);
167189
}
168190
const customCSS = document.getElementById('custom-css-textarea').value;
169191
if (getOpt('customCSS') !== DEFAULT_CSS || customCSS !== DEFAULT_CSS) {
@@ -195,7 +217,8 @@ class OptionsPageManager {
195217
googleScholar.checked = OPTIONAL_PERMISSIONS_URLS['google-scholar'].every(
196218
(url) => {
197219
return permissions.origins.includes(url);
198-
});
220+
},
221+
);
199222
const amazon = document.getElementById('amazon');
200223
amazon.checked = OPTIONAL_PERMISSIONS_URLS['amazon'].every((url) => {
201224
return permissions.origins.includes(url);
@@ -218,25 +241,30 @@ class OptionsPageManager {
218241
return this.options.get(key);
219242
};
220243
// Handle checks separately.
221-
document.getElementById('wrap-navigation').checked =
222-
getOpt('wrapNavigation');
223-
document.getElementById('auto-select-first').checked =
224-
getOpt('autoSelectFirst');
225-
document.getElementById('hide-outline').checked =
226-
getOpt('hideOutline');
244+
document.getElementById('wrap-navigation').checked = getOpt(
245+
'wrapNavigation',
246+
);
247+
document.getElementById('auto-select-first').checked = getOpt(
248+
'autoSelectFirst',
249+
);
250+
document.getElementById('hide-outline').checked = getOpt('hideOutline');
227251
document.getElementById('delay').value = getOpt('delay');
228-
document.getElementById('google-include-cards').checked =
229-
getOpt('googleIncludeCards');
230-
document.getElementById('google-include-memex').checked =
231-
getOpt('googleIncludeMemex');
232-
document.getElementById('google-include-places').checked =
233-
getOpt('googleIncludePlaces');
252+
document.getElementById('google-include-cards').checked = getOpt(
253+
'googleIncludeCards',
254+
);
255+
document.getElementById('google-include-memex').checked = getOpt(
256+
'googleIncludeMemex',
257+
);
258+
document.getElementById('google-include-places').checked = getOpt(
259+
'googleIncludePlaces',
260+
);
234261
// Restore options from divs.
235262
for (const [key, optName] of Object.entries(KEYBINDING_TO_DIV)) {
236263
// Keybindings are stored internally as arrays, but edited by users as
237264
// comman delimited strings.
238265
document.getElementById(optName).value = keybindingArrayToString(
239-
getOpt(key));
266+
getOpt(key),
267+
);
240268
}
241269
// Load custom CSS
242270
document.getElementById('custom-css-textarea').value = getOpt('customCSS');

0 commit comments

Comments
 (0)