diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-22 10:01:24 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-22 10:48:39 +0900 |
commit | 2e7006ce24c42ec2b6642346d153429338e7334e (patch) | |
tree | f1eb9e843ab4ec5d7d3f08fff8c858174b6f1284 /src | |
parent | 0881f92d20cb7b4f5a75671df739c3eaa3cd0ff0 (diff) |
npm run lint:fix
Diffstat (limited to 'src')
85 files changed, 423 insertions, 423 deletions
diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index 11fed01..7297ef8 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -17,13 +17,13 @@ export default class CommandController { } getCompletions(line: string): Promise<CompletionGroup[]> { - let trimmed = trimStart(line); - let words = trimmed.split(/ +/); - let name = words[0]; + const trimmed = trimStart(line); + const words = trimmed.split(/ +/); + const name = words[0]; if (words.length === 1) { return this.completionsUseCase.queryConsoleCommand(name); } - let keywords = trimStart(trimmed.slice(name.length)); + const keywords = trimStart(trimmed.slice(name.length)); switch (words[0]) { case 'o': case 'open': @@ -53,14 +53,14 @@ export default class CommandController { // eslint-disable-next-line complexity exec(line: string): Promise<any> { - let trimmed = trimStart(line); - let words = trimmed.split(/ +/); - let name = words[0]; + const trimmed = trimStart(line); + const words = trimmed.split(/ +/); + const name = words[0]; if (words[0].length === 0) { return Promise.resolve(); } - let keywords = trimStart(trimmed.slice(name.length)); + const keywords = trimStart(trimmed.slice(name.length)); switch (words[0]) { case 'o': case 'open': diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index 2f5d4a6..181dd19 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -105,7 +105,7 @@ export default class OperationController { return () => this.navigateUseCase.openRoot(); case operations.REPEAT_LAST: return () => { - let last = this.repeatUseCase.getLastOperation(); + const last = this.repeatUseCase.getLastOperation(); if (typeof last !== 'undefined') { return this.doOperation(1, last); } diff --git a/src/background/index.ts b/src/background/index.ts index 26b0f6b..51fde56 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -2,5 +2,5 @@ import 'reflect-metadata'; import { container } from 'tsyringe'; import Application from './Application'; -let app = container.resolve(Application); +const app = container.resolve(Application); app.run(); diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts index 4d2284c..b6c0c23 100644 --- a/src/background/infrastructures/ContentMessageClient.ts +++ b/src/background/infrastructures/ContentMessageClient.ts @@ -4,8 +4,8 @@ import * as messages from '../../shared/messages'; @injectable() export default class ContentMessageClient { async broadcastSettingsChanged(): Promise<void> { - let tabs = await browser.tabs.query({}); - for (let tab of tabs) { + const tabs = await browser.tabs.query({}); + for (const tab of tabs) { if (!tab.id || tab.url && tab.url.startsWith('about:')) { continue; } @@ -16,7 +16,7 @@ export default class ContentMessageClient { } async getAddonEnabled(tabId: number): Promise<boolean> { - let enabled = await browser.tabs.sendMessage(tabId, { + const enabled = await browser.tabs.sendMessage(tabId, { type: messages.ADDON_ENABLED_QUERY, }); return enabled as any as boolean; diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index f20340b..d063810 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -31,7 +31,7 @@ export default class ContentMessageListener { message: any, sender: browser.runtime.MessageSender, ) => { try { - let ret = this.onMessage(message, sender.tab as browser.tabs.Tab); + const ret = this.onMessage(message, sender.tab as browser.tabs.Tab); if (!(ret instanceof Promise)) { return {}; } @@ -94,7 +94,7 @@ export default class ContentMessageListener { } async onConsoleQueryCompletions(line: string): Promise<CompletionGroup[]> { - let completions = await this.commandController.getCompletions(line); + const completions = await this.commandController.getCompletions(line); return Promise.resolve(completions); } @@ -140,7 +140,7 @@ export default class ContentMessageListener { } onConsoleFrameMessage(tabId: number, message: any): void { - let port = this.consolePorts[tabId]; + const port = this.consolePorts[tabId]; if (!port) { return; } @@ -153,7 +153,7 @@ export default class ContentMessageListener { } if (port.sender && port.sender.tab && port.sender.tab.id) { - let id = port.sender.tab.id; + const id = port.sender.tab.id; this.consolePorts[id] = port; } } diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/infrastructures/MemoryStorage.ts index baf9ffa..af445a6 100644 --- a/src/background/infrastructures/MemoryStorage.ts +++ b/src/background/infrastructures/MemoryStorage.ts @@ -2,7 +2,7 @@ const db: {[key: string]: any} = {}; export default class MemoryStorage { set(name: string, value: any): void { - let data = JSON.stringify(value); + const data = JSON.stringify(value); if (typeof data === 'undefined') { throw new Error('value is not serializable'); } @@ -10,7 +10,7 @@ export default class MemoryStorage { } get(name: string): any { - let data = db[name]; + const data = db[name]; if (!data) { return undefined; } diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts index 99f92b5..6a33e62 100644 --- a/src/background/presenters/IndicatorPresenter.ts +++ b/src/background/presenters/IndicatorPresenter.ts @@ -3,7 +3,7 @@ import { injectable } from 'tsyringe'; @injectable() export default class IndicatorPresenter { indicate(enabled: boolean): Promise<void> { - let path = enabled + const path = enabled ? 'resources/enabled_32x32.png' : 'resources/disabled_32x32.png'; if (typeof browser.browserAction.setIcon === 'function') { diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts index defb601..b7f4f99 100644 --- a/src/background/presenters/NotifyPresenter.ts +++ b/src/background/presenters/NotifyPresenter.ts @@ -6,8 +6,8 @@ const NOTIFICATION_ID_INVALID_SETTINGS = 'vimvixen-update-invalid-settings'; @injectable() export default class NotifyPresenter { async notifyUpdated(version: string, onclick: () => void): Promise<void> { - let title = `Vim Vixen ${version} has been installed`; - let message = 'Click here to see release notes'; + const title = `Vim Vixen ${version} has been installed`; + const message = 'Click here to see release notes'; const listener = (id: string) => { if (id !== NOTIFICATION_ID_UPDATE) { @@ -27,9 +27,9 @@ export default class NotifyPresenter { } async notifyInvalidSettings(onclick: () => void): Promise<void> { - let title = `Loaded settings is invalid`; + const title = `Loaded settings is invalid`; // eslint-disable-next-line max-len - let message = 'The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference'; + const message = 'The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference'; const listener = (id: string) => { if (id !== NOTIFICATION_ID_INVALID_SETTINGS) { diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts index ed88f26..33d8bea 100644 --- a/src/background/presenters/TabPresenter.ts +++ b/src/background/presenters/TabPresenter.ts @@ -17,7 +17,7 @@ export default class TabPresenter { } async getCurrent(): Promise<Tab> { - let tabs = await browser.tabs.query({ + const tabs = await browser.tabs.query({ active: true, currentWindow: true }); return tabs[0]; @@ -28,8 +28,8 @@ export default class TabPresenter { } async getLastSelectedId(): Promise<number | undefined> { - let cache = new MemoryStorage(); - let tabId = await cache.get(LAST_SELECTED_KEY); + const cache = new MemoryStorage(); + const tabId = await cache.get(LAST_SELECTED_KEY); if (tabId === null || typeof tabId === 'undefined') { return; } @@ -37,9 +37,9 @@ export default class TabPresenter { } async getByKeyword( - keyword: string, excludePinned: boolean = false, + keyword: string, excludePinned = false, ): Promise<Tab[]> { - let tabs = await browser.tabs.query({ currentWindow: true }); + const tabs = await browser.tabs.query({ currentWindow: true }); return tabs.filter((t) => { return t.url && t.url.toLowerCase().includes(keyword.toLowerCase()) || t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); @@ -57,9 +57,9 @@ export default class TabPresenter { } async reopen(): Promise<any> { - let window = await browser.windows.getCurrent(); - let sessions = await browser.sessions.getRecentlyClosed(); - let session = sessions.find((s) => { + const window = await browser.windows.getCurrent(); + const sessions = await browser.sessions.getRecentlyClosed(); + const session = sessions.find((s) => { return s.tab && s.tab.windowId === window.id; }); if (!session) { @@ -100,11 +100,11 @@ export default class TabPresenter { } } -let tabPresenter = new TabPresenter(); +const tabPresenter = new TabPresenter(); tabPresenter.onSelected((tab: any) => { - let cache = new MemoryStorage(); + const cache = new MemoryStorage(); - let lastId = cache.get(CURRENT_SELECTED_KEY); + const lastId = cache.get(CURRENT_SELECTED_KEY); if (lastId) { cache.set(LAST_SELECTED_KEY, lastId); } diff --git a/src/background/repositories/BookmarkRepository.ts b/src/background/repositories/BookmarkRepository.ts index d266ae6..0d2a1fc 100644 --- a/src/background/repositories/BookmarkRepository.ts +++ b/src/background/repositories/BookmarkRepository.ts @@ -5,7 +5,7 @@ export default class BookmarkRepository { async create( title: string, url: string ): Promise<browser.bookmarks.BookmarkTreeNode> { - let item = await browser.bookmarks.create({ + const item = await browser.bookmarks.create({ type: 'bookmark', title, url, diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts index 9cfb35e..a47b64d 100644 --- a/src/background/repositories/BrowserSettingRepository.ts +++ b/src/background/repositories/BrowserSettingRepository.ts @@ -20,7 +20,7 @@ declare namespace browser.browserSettings.homepageOverride { @injectable() export default class BrowserSettingRepository { async getHomepageUrls(): Promise<string[]> { - let { value } = await browser.browserSettings.homepageOverride.get({}); + const { value } = await browser.browserSettings.homepageOverride.get({}); return value.split('|').map(urls.normalizeUrl); } } diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts index dfdbc27..dfecff0 100644 --- a/src/background/repositories/CompletionsRepository.ts +++ b/src/background/repositories/CompletionsRepository.ts @@ -6,7 +6,7 @@ type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode; @injectable() export default class CompletionsRepository { async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> { - let items = await browser.bookmarks.search({ query: keywords }); + const items = await browser.bookmarks.search({ query: keywords }); return items.filter((item) => { if (!item.url) { return false; @@ -29,7 +29,7 @@ export default class CompletionsRepository { } async queryTabs(keywords: string, excludePinned: boolean): Promise<Tab[]> { - let tabs = await browser.tabs.query({ currentWindow: true }); + const tabs = await browser.tabs.query({ currentWindow: true }); return tabs.filter((t) => { return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) || t.title && t.title.toLowerCase().includes(keywords.toLowerCase()); diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts index c106fff..1f4ab0c 100644 --- a/src/background/repositories/MarkRepository.ts +++ b/src/background/repositories/MarkRepository.ts @@ -13,17 +13,17 @@ export default class MarkRepository { } getMark(key: string): Promise<GlobalMark | undefined> { - let marks = this.getOrEmptyMarks(); - let data = marks[key]; + const marks = this.getOrEmptyMarks(); + const data = marks[key]; if (!data) { return Promise.resolve(undefined); } - let mark = { tabId: data.tabId, url: data.url, x: data.x, y: data.y }; + const mark = { tabId: data.tabId, url: data.url, x: data.x, y: data.y }; return Promise.resolve(mark); } setMark(key: string, mark: GlobalMark): Promise<any> { - let marks = this.getOrEmptyMarks(); + const marks = this.getOrEmptyMarks(); marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y }; this.cache.set(MARK_KEY, marks); diff --git a/src/background/repositories/PersistentSettingRepository.ts b/src/background/repositories/PersistentSettingRepository.ts index e3b78b3..c10f2cf 100644 --- a/src/background/repositories/PersistentSettingRepository.ts +++ b/src/background/repositories/PersistentSettingRepository.ts @@ -4,7 +4,7 @@ import SettingData from '../../shared/SettingData'; @injectable() export default class SettingRepository { async load(): Promise<SettingData | null> { - let { settings } = await browser.storage.local.get('settings'); + const { settings } = await browser.storage.local.get('settings'); if (!settings) { return null; } diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/SettingRepository.ts index e775a32..ba24e36 100644 --- a/src/background/repositories/SettingRepository.ts +++ b/src/background/repositories/SettingRepository.ts @@ -14,7 +14,7 @@ export default class SettingRepository { } get(): Promise<Settings> { - let data = this.cache.get(CACHED_SETTING_KEY); + const data = this.cache.get(CACHED_SETTING_KEY); return Promise.resolve(Settings.fromJSON(data)); } @@ -25,7 +25,7 @@ export default class SettingRepository { async setProperty( name: string, value: string | number | boolean, ): Promise<void> { - let def = Properties.def(name); + const def = Properties.def(name); if (!def) { throw new Error('unknown property: ' + name); } @@ -37,7 +37,7 @@ export default class SettingRepository { newValue = def.defaultValue; } - let current = await this.get(); + const current = await this.get(); switch (name) { case 'hintchars': current.properties.hintchars = newValue as string; diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts index bb5cd90..9abd3dc 100644 --- a/src/background/usecases/AddonEnabledUseCase.ts +++ b/src/background/usecases/AddonEnabledUseCase.ts @@ -27,7 +27,7 @@ export default class AddonEnabledUseCase { } async onTabSelected(tabId: number): Promise<void> { - let enabled = await this.contentMessageClient.getAddonEnabled(tabId); + const enabled = await this.contentMessageClient.getAddonEnabled(tabId); return this.indicatorPresentor.indicate(enabled); } } diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index d757215..fcb898d 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -26,7 +26,7 @@ export default class CommandIndicator { } async open(keywords: string): Promise<browser.tabs.Tab> { - let url = await this.urlOrSearch(keywords); + const url = await this.urlOrSearch(keywords); this.repeatUseCase.storeLastOperation({ type: operations.INTERNAL_OPEN_URL, url, @@ -35,7 +35,7 @@ export default class CommandIndicator { } async tabopen(keywords: string): Promise<browser.tabs.Tab> { - let url = await this.urlOrSearch(keywords); + const url = await this.urlOrSearch(keywords); this.repeatUseCase.storeLastOperation({ type: operations.INTERNAL_OPEN_URL, url, @@ -45,7 +45,7 @@ export default class CommandIndicator { } async winopen(keywords: string): Promise<browser.windows.Window> { - let url = await this.urlOrSearch(keywords); + const url = await this.urlOrSearch(keywords); this.repeatUseCase.storeLastOperation({ type: operations.INTERNAL_OPEN_URL, url, @@ -61,8 +61,8 @@ export default class CommandIndicator { } if (!isNaN(Number(keywords))) { - let tabs = await this.tabPresenter.getAll(); - let index = parseInt(keywords, 10) - 1; + const tabs = await this.tabPresenter.getAll(); + const index = parseInt(keywords, 10) - 1; if (index < 0 || tabs.length <= index) { throw new RangeError(`tab ${index + 1} does not exist`); } @@ -72,19 +72,19 @@ export default class CommandIndicator { return; } else if (keywords.trim() === '#') { // Select last selected window - let lastId = await this.tabPresenter.getLastSelectedId(); + const lastId = await this.tabPresenter.getLastSelectedId(); if (typeof lastId === 'undefined' || lastId === null) { throw new Error('No last selected tab'); } return this.tabPresenter.select(lastId); } - let current = await this.tabPresenter.getCurrent(); - let tabs = await this.tabPresenter.getByKeyword(keywords); + const current = await this.tabPresenter.getCurrent(); + const tabs = await this.tabPresenter.getByKeyword(keywords); if (tabs.length === 0) { throw new RangeError('No matching buffer for ' + keywords); } - for (let tab of tabs) { + for (const tab of tabs) { if (tab.index > current.index) { return this.tabPresenter.select(tab.id as number); } @@ -93,8 +93,8 @@ export default class CommandIndicator { } async bdelete(force: boolean, keywords: string): Promise<any> { - let excludePinned = !force; - let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); + const excludePinned = !force; + const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); if (tabs.length === 0) { throw new Error('No matching buffer for ' + keywords); } else if (tabs.length > 1) { @@ -104,27 +104,27 @@ export default class CommandIndicator { } async bdeletes(force: boolean, keywords: string): Promise<any> { - let excludePinned = !force; - let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); - let ids = tabs.map(tab => tab.id as number); + const excludePinned = !force; + const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); + const ids = tabs.map(tab => tab.id as number); return this.tabPresenter.remove(ids); } async quit(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.remove([tab.id as number]); } async quitAll(): Promise<any> { - let tabs = await this.tabPresenter.getAll(); - let ids = tabs.map(tab => tab.id as number); + const tabs = await this.tabPresenter.getAll(); + const ids = tabs.map(tab => tab.id as number); this.tabPresenter.remove(ids); } async addbookmark(title: string): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let item = await this.bookmarkRepository.create(title, tab.url as string); - let message = 'Saved current page: ' + item.url; + const tab = await this.tabPresenter.getCurrent(); + const item = await this.bookmarkRepository.create(title, tab.url as string); + const message = 'Saved current page: ' + item.url; return this.consoleClient.showInfo(tab.id as number, message); } @@ -132,7 +132,7 @@ export default class CommandIndicator { if (keywords.length === 0) { return; } - let [name, value] = parsers.parseSetOption(keywords); + const [name, value] = parsers.parseSetOption(keywords); await this.settingRepository.setProperty(name, value); return this.contentMessageClient.broadcastSettingsChanged(); @@ -143,7 +143,7 @@ export default class CommandIndicator { } private async urlOrSearch(keywords: string): Promise<any> { - let settings = await this.settingRepository.get(); + const settings = await this.settingRepository.get(); return urls.searchUrl(keywords, settings.search); } } diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts index bfff1e6..779c61d 100644 --- a/src/background/usecases/CompletionsUseCase.ts +++ b/src/background/usecases/CompletionsUseCase.ts @@ -22,8 +22,8 @@ export default class CompletionsUseCase { } queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> { - let keys = Object.keys(CommandDocs); - let items = keys + const keys = Object.keys(CommandDocs); + const items = keys .filter(name => name.startsWith(prefix)) .map(name => ({ caption: name, @@ -41,28 +41,28 @@ export default class CompletionsUseCase { // TODO This logic contains view entities. They should be defined on // content script - let settings = await this.settingRepository.get(); - let groups: CompletionGroup[] = []; + const settings = await this.settingRepository.get(); + const groups: CompletionGroup[] = []; - let complete = settings.properties.complete; - for (let c of complete) { + const complete = settings.properties.complete; + for (const c of complete) { if (c === 's') { // eslint-disable-next-line no-await-in-loop - let engines = await this.querySearchEngineItems(name, keywords); + const engines = await this.querySearchEngineItems(name, keywords); if (engines.length > 0) { groups.push({ name: 'Search Engines', items: engines }); } // browser.history not supported on Android } else if (c === 'h' && typeof browser.history === 'object') { // eslint-disable-next-line no-await-in-loop - let histories = await this.queryHistoryItems(name, keywords); + const histories = await this.queryHistoryItems(name, keywords); if (histories.length > 0) { groups.push({ name: 'History', items: histories }); } // browser.bookmarks not supported on Android } else if (c === 'b' && typeof browser.bookmarks === 'object') { // eslint-disable-next-line no-await-in-loop - let bookmarks = await this.queryBookmarkItems(name, keywords); + const bookmarks = await this.queryBookmarkItems(name, keywords); if (bookmarks.length > 0) { groups.push({ name: 'Bookmarks', items: bookmarks }); } @@ -76,23 +76,23 @@ export default class CompletionsUseCase { name: string, keywords: string, ): Promise<CompletionGroup[]> { - let lastId = await this.tabPresenter.getLastSelectedId(); - let trimmed = keywords.trim(); + const lastId = await this.tabPresenter.getLastSelectedId(); + const trimmed = keywords.trim(); let tabs: Tab[] = []; if (trimmed.length > 0 && !isNaN(Number(trimmed))) { - let all = await this.tabPresenter.getAll(); - let index = parseInt(trimmed, 10) - 1; + const all = await this.tabPresenter.getAll(); + const index = parseInt(trimmed, 10) - 1; if (index >= 0 && index < all.length) { tabs = [all[index]]; } } else if (trimmed === '%') { - let all = await this.tabPresenter.getAll(); - let tab = all.find(t => t.active) as Tab; + const all = await this.tabPresenter.getAll(); + const tab = all.find(t => t.active) as Tab; tabs = [tab]; } else if (trimmed === '#') { if (typeof lastId !== 'undefined' && lastId !== null) { - let all = await this.tabPresenter.getAll(); - let tab = all.find(t => t.id === lastId) as Tab; + const all = await this.tabPresenter.getAll(); + const tab = all.find(t => t.id === lastId) as Tab; tabs = [tab]; } } else { @@ -106,7 +106,7 @@ export default class CompletionsUseCase { } return ' '; }; - let items = tabs.map(tab => ({ + const items = tabs.map(tab => ({ caption: tab.index + 1 + ': ' + flag(tab) + ' ' + tab.title, content: name + ' ' + tab.title, url: tab.url, @@ -129,7 +129,7 @@ export default class CompletionsUseCase { } querySet(name: string, keywords: string): Promise<CompletionGroup[]> { - let items = Properties.defs().map((def) => { + const items = Properties.defs().map((def) => { if (def.type === 'boolean') { return [ { @@ -166,8 +166,8 @@ export default class CompletionsUseCase { async queryTabs( name: string, excludePinned: boolean, args: string, ): Promise<CompletionGroup[]> { - let tabs = await this.completionsRepository.queryTabs(args, excludePinned); - let items = tabs.map(tab => ({ + const tabs = await this.completionsRepository.queryTabs(args, excludePinned); + const items = tabs.map(tab => ({ caption: tab.title, content: name + ' ' + tab.title, url: tab.url, @@ -180,8 +180,8 @@ export default class CompletionsUseCase { } async querySearchEngineItems(name: string, keywords: string) { - let settings = await this.settingRepository.get(); - let engines = Object.keys(settings.search.engines) + const settings = await this.settingRepository.get(); + const engines = Object.keys(settings.search.engines) .filter(key => key.startsWith(keywords)); return engines.map(key => ({ caption: key, @@ -209,7 +209,7 @@ export default class CompletionsUseCase { } async queryBookmarkItems(name: string, keywords: string) { - let bookmarks = await this.completionsRepository.queryBookmarks(keywords); + const bookmarks = await this.completionsRepository.queryBookmarks(keywords); return bookmarks.slice(0, COMPLETION_ITEM_LIMIT) .map(page => ({ caption: page.title, diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts index d0bd7bb..775a1e0 100644 --- a/src/background/usecases/ConsoleUseCase.ts +++ b/src/background/usecases/ConsoleUseCase.ts @@ -12,12 +12,12 @@ export default class ConsoleUseCase { } async showCommand(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.consoleClient.showCommand(tab.id as number, ''); } async showOpenCommand(alter: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); let command = 'open '; if (alter) { command += tab.url || ''; @@ -26,7 +26,7 @@ export default class ConsoleUseCase { } async showTabopenCommand(alter: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); let command = 'tabopen '; if (alter) { command += tab.url || ''; @@ -35,7 +35,7 @@ export default class ConsoleUseCase { } async showWinopenCommand(alter: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); let command = 'winopen '; if (alter) { command += tab.url || ''; @@ -44,13 +44,13 @@ export default class ConsoleUseCase { } async showBufferCommand(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let command = 'buffer '; + const tab = await this.tabPresenter.getCurrent(); + const command = 'buffer '; return this.consoleClient.showCommand(tab.id as number, command); } async showAddbookmarkCommand(alter: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); let command = 'addbookmark '; if (alter) { command += tab.title || ''; @@ -59,7 +59,7 @@ export default class ConsoleUseCase { } async hideConsole(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.consoleClient.hide(tab.id as number); } } diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index 41b9cbd..b8593c6 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -21,7 +21,7 @@ export default class FindUseCase { } async findStart(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.consoleClient.showFind(tab.id as number); } } diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts index e87867d..9c0eab5 100644 --- a/src/background/usecases/LinkUseCase.ts +++ b/src/background/usecases/LinkUseCase.ts @@ -15,9 +15,9 @@ export default class LinkUseCase { async openNewTab( url: string, openerId: number, background: boolean, ): Promise<any> { - let properties: any = { active: !background }; + const properties: any = { active: !background }; - let platform = await browser.runtime.getPlatformInfo(); + const platform = await browser.runtime.getPlatformInfo(); if (platform.os !== 'android') { // openerTabId not supported on Android properties.openerTabId = openerId; diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index 8cb96da..eeac40f 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -15,15 +15,15 @@ export default class MarkUseCase { } async setGlobal(key: string, x: number, y: number): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let mark = { tabId: tab.id as number, url: tab.url as string, x, y }; + const tab = await this.tabPresenter.getCurrent(); + const mark = { tabId: tab.id as number, url: tab.url as string, x, y }; return this.markRepository.setMark(key, mark); } async jumpGlobal(key: string): Promise<any> { - let current = await this.tabPresenter.getCurrent(); + const current = await this.tabPresenter.getCurrent(); - let mark = await this.markRepository.getMark(key); + const mark = await this.markRepository.getMark(key); if (!mark) { return this.consoleClient.showError( current.id as number, 'Mark is not set'); @@ -32,7 +32,7 @@ export default class MarkUseCase { await this.contentMessageClient.scrollTo(mark.tabId, mark.x, mark.y); return this.tabPresenter.select(mark.tabId); } catch (e) { - let tab = await this.tabPresenter.create(mark.url); + const tab = await this.tabPresenter.create(mark.url); return this.markRepository.setMark(key, { tabId: tab.id as number, url: mark.url, x: mark.x, y: mark.y, }); diff --git a/src/background/usecases/NavigateUseCase.ts b/src/background/usecases/NavigateUseCase.ts index 152339a..25e7f20 100644 --- a/src/background/usecases/NavigateUseCase.ts +++ b/src/background/usecases/NavigateUseCase.ts @@ -11,28 +11,28 @@ export default class NavigateUseCase { } async openHistoryNext(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); await this.navigateClient.historyNext(tab.id!!); } async openHistoryPrev(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); await this.navigateClient.historyPrev(tab.id!!); } async openLinkNext(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); await this.navigateClient.linkNext(tab.id!!); } async openLinkPrev(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); await this.navigateClient.linkPrev(tab.id!!); } async openParent(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); - let url = new URL(tab.url!!); + const tab = await this.tabPresenter.getCurrent(); + const url = new URL(tab.url!!); if (url.hash.length > 0) { url.hash = ''; } else if (url.search.length > 0) { @@ -50,8 +50,8 @@ export default class NavigateUseCase { } async openRoot(): Promise<void> { - let tab = await this.tabPresenter.getCurrent(); - let url = new URL(tab.url!!); + const tab = await this.tabPresenter.getCurrent(); + const url = new URL(tab.url!!); await this.tabPresenter.open(url.origin); } } diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts index df3db94..62098de 100644 --- a/src/background/usecases/TabSelectUseCase.ts +++ b/src/background/usecases/TabSelectUseCase.ts @@ -9,43 +9,43 @@ export default class TabSelectUseCase { } async selectPrev(count: number): Promise<any> { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); if (tabs.length < 2) { return; } - let tab = tabs.find(t => t.active); + const tab = tabs.find(t => t.active); if (!tab) { return; } - let select = (tab.index - count + tabs.length) % tabs.length; + const select = (tab.index - count + tabs.length) % tabs.length; return this.tabPresenter.select(tabs[select].id as number); } async selectNext(count: number): Promise<any> { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); if (tabs.length < 2) { return; } - let tab = tabs.find(t => t.active); + const tab = tabs.find(t => t.active); if (!tab) { return; } - let select = (tab.index + count) % tabs.length; + const select = (tab.index + count) % tabs.length; return this.tabPresenter.select(tabs[select].id as number); } async selectFirst(): Promise<any> { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); return this.tabPresenter.select(tabs[0].id as number); } async selectLast(): Promise<any> { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); return this.tabPresenter.select(tabs[tabs.length - 1].id as number); } async selectPrevSelected(): Promise<any> { - let tabId = await this.tabPresenter.getLastSelectedId(); + const tabId = await this.tabPresenter.getLastSelectedId(); if (tabId === null || typeof tabId === 'undefined') { return Promise.resolve(); } diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts index 386307e..66f8573 100644 --- a/src/background/usecases/TabUseCase.ts +++ b/src/background/usecases/TabUseCase.ts @@ -13,26 +13,26 @@ export default class TabUseCase { } async close(force: boolean, selectLeft = false): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); if (!force && tab.pinned) { return Promise.resolve(); } if (selectLeft && tab.index > 0) { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); await this.tabPresenter.select(tabs[tab.index - 1].id as number); } return this.tabPresenter.remove([tab.id as number]); } async closeRight(): Promise<any> { - let tabs = await this.tabPresenter.getAll(); + const tabs = await this.tabPresenter.getAll(); tabs.sort((t1, t2) => t1.index - t2.index); - let index = tabs.findIndex(t => t.active); + const index = tabs.findIndex(t => t.active); if (index < 0) { return; } for (let i = index + 1; i < tabs.length; ++i) { - let tab = tabs[i]; + const tab = tabs[i]; if (!tab.pinned) { this.tabPresenter.remove([tab.id as number]); } @@ -44,34 +44,34 @@ export default class TabUseCase { } async reload(cache: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.reload(tab.id as number, cache); } async setPinned(pinned: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.setPinned(tab.id as number, pinned); } async togglePinned(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.setPinned(tab.id as number, !tab.pinned); } async duplicate(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.duplicate(tab.id as number); } async openPageSource(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let url = 'view-source:' + tab.url; + const tab = await this.tabPresenter.getCurrent(); + const url = 'view-source:' + tab.url; return this.tabPresenter.create(url); } async openHome(newTab: boolean): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let urls = await this.browserSettingRepository.getHomepageUrls(); + const tab = await this.tabPresenter.getCurrent(); + const urls = await this.browserSettingRepository.getHomepageUrls(); if (urls.length === 1 && urls[0] === 'about:home') { // eslint-disable-next-line max-len throw new Error('Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs'); @@ -79,7 +79,7 @@ export default class TabUseCase { if (urls.length === 1 && !newTab) { return this.tabPresenter.open(urls[0], tab.id); } - for (let url of urls) { + for (const url of urls) { this.tabPresenter.create(url); } } @@ -92,7 +92,7 @@ export default class TabUseCase { } else if (newTab) { await this.tabPresenter.create(url); } else { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); await this.tabPresenter.open(url, tab.id); } } diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index 0ff0e9b..645c859 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -11,8 +11,8 @@ export default class VersionUseCase { } notify(): Promise<void> { - let manifest = browser.runtime.getManifest(); - let url = this.releaseNoteUrl(manifest.version); + const manifest = browser.runtime.getManifest(); + const url = this.releaseNoteUrl(manifest.version); return this.notifyPresenter.notifyUpdated(manifest.version, () => { this.tabPresenter.create(url); }); diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts index 32ba897..f598871 100644 --- a/src/background/usecases/ZoomUseCase.ts +++ b/src/background/usecases/ZoomUseCase.ts @@ -14,27 +14,27 @@ export default class ZoomUseCase { } async zoomIn(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let tabId = tab.id as number; - let current = await this.tabPresenter.getZoom(tabId); - let factor = ZOOM_SETTINGS.find(f => f > current); + const tab = await this.tabPresenter.getCurrent(); + const tabId = tab.id as number; + const current = await this.tabPresenter.getZoom(tabId); + const factor = ZOOM_SETTINGS.find(f => f > current); if (factor) { return this.tabPresenter.setZoom(tabId as number, factor); } } async zoomOut(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); - let tabId = tab.id as number; - let current = await this.tabPresenter.getZoom(tabId); - let factor = ZOOM_SETTINGS.slice(0).reverse().find(f => f < current); + const tab = await this.tabPresenter.getCurrent(); + const tabId = tab.id as number; + const current = await this.tabPresenter.getZoom(tabId); + const factor = ZOOM_SETTINGS.slice(0).reverse().find(f => f < current); if (factor) { return this.tabPresenter.setZoom(tabId as number, factor); } } async zoomNutoral(): Promise<any> { - let tab = await this.tabPresenter.getCurrent(); + const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.setZoom(tab.id as number, 1); } } diff --git a/src/background/usecases/filters.ts b/src/background/usecases/filters.ts index 84a42fb..98957a7 100644 --- a/src/background/usecases/filters.ts +++ b/src/background/usecases/filters.ts @@ -1,13 +1,13 @@ type Item = browser.history.HistoryItem; const filterHttp = (items: Item[]): Item[] => { - let httpsHosts = items.map(x => new URL(x.url as string)) + const httpsHosts = items.map(x => new URL(x.url as string)) .filter(x => x.protocol === 'https:') .map(x => x.host); - let hostsSet = new Set(httpsHosts); + const hostsSet = new Set(httpsHosts); return items.filter((item: Item) => { - let url = new URL(item.url as string); + const url = new URL(item.url as string); return url.protocol === 'https:' || !hostsSet.has(url.host); }); }; @@ -17,14 +17,14 @@ const filterBlankTitle = (items: Item[]): Item[] => { }; const filterByTailingSlash = (items: Item[]): Item[] => { - let urls = items.map(item => new URL(item.url as string)); - let simplePaths = urls + const urls = items.map(item => new URL(item.url as string)); + const simplePaths = urls .filter(url => url.hash === '' && url.search === '') .map(url => url.origin + url.pathname); - let pathsSet = new Set(simplePaths); + const pathsSet = new Set(simplePaths); return items.filter((item) => { - let url = new URL(item.url as string); + const url = new URL(item.url as string); if (url.hash !== '' || url.search !== '' || url.pathname.slice(-1) !== '/') { return true; @@ -34,10 +34,10 @@ const filterByTailingSlash = (items: Item[]): Item[] => { }; const filterByPathname = (items: Item[], min: number): Item[] => { - let hash: {[key: string]: Item} = {}; - for (let item of items) { - let url = new URL(item.url as string); - let pathname = url.origin + url.pathname; + const hash: {[key: string]: Item} = {}; + for (const item of items) { + const url = new URL(item.url as string); + const pathname = url.origin + url.pathname; if (!hash[pathname]) { hash[pathname] = item; } else if ((hash[pathname].url as string).length > @@ -45,7 +45,7 @@ const filterByPathname = (items: Item[], min: number): Item[] => { hash[pathname] = item; } } - let filtered = Object.values(hash); + const filtered = Object.values(hash); if (filtered.length < min) { return items; } @@ -53,9 +53,9 @@ const filterByPathname = (items: Item[], min: number): Item[] => { }; const filterByOrigin = (items: Item[], min: number): Item[] => { - let hash: {[key: string]: Item} = {}; - for (let item of items) { - let origin = new URL(item.url as string).origin; + const hash: {[key: string]: Item} = {}; + for (const item of items) { + const origin = new URL(item.url as string).origin; if (!hash[origin]) { hash[origin] = item; } else if ((hash[origin].url as string).length > @@ -63,7 +63,7 @@ const filterByOrigin = (items: Item[], min: number): Item[] => { hash[origin] = item; } } - let filtered = Object.values(hash); + const filtered = Object.values(hash); if (filtered.length < min) { return items; } diff --git a/src/background/usecases/parsers.ts b/src/background/usecases/parsers.ts index e8a1149..544dce4 100644 --- a/src/background/usecases/parsers.ts +++ b/src/background/usecases/parsers.ts @@ -1,7 +1,7 @@ import Properties from '../../shared/settings/Properties'; const mustNumber = (v: any): number => { - let num = Number(v); + const num = Number(v); if (isNaN(num)) { throw new Error('Not number: ' + v); } @@ -16,7 +16,7 @@ const parseSetOption = ( value = !key.startsWith('no'); key = value ? key : key.slice(2); } - let def = Properties.def(key); + const def = Properties.def(key); if (!def) { throw new Error('Unknown property: ' + key); } diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts index d03f52c..f7fa7a2 100644 --- a/src/console/actions/console.ts +++ b/src/console/actions/console.ts @@ -69,7 +69,7 @@ const setConsoleText = (consoleText: string): actions.ConsoleAction => { }; const getCompletions = async(text: string): Promise<actions.ConsoleAction> => { - let completions = await browser.runtime.sendMessage({ + const completions = await browser.runtime.sendMessage({ type: messages.CONSOLE_QUERY_COMPLETIONS, text, }); diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx index 1743d15..eafe2a7 100644 --- a/src/console/components/Console.tsx +++ b/src/console/components/Console.tsx @@ -34,7 +34,7 @@ class Console extends React.Component<Props> { e.stopPropagation(); e.preventDefault(); - let value = (e.target as HTMLInputElement).value; + const value = (e.target as HTMLInputElement).value; if (this.props.mode === 'command') { return this.props.dispatch(consoleActions.enterCommand(value)); } else if (this.props.mode === 'find') { @@ -101,7 +101,7 @@ class Console extends React.Component<Props> { } onChange(e: React.ChangeEvent<HTMLInputElement>) { - let text = e.target.value; + const text = e.target.value; this.props.dispatch(consoleActions.setConsoleText(text)); if (this.props.mode === 'command') { this.props.dispatch(consoleActions.getCompletions(text)); diff --git a/src/console/components/console/Completion.tsx b/src/console/components/console/Completion.tsx index 169a39c..e2fa1de 100644 --- a/src/console/components/console/Completion.tsx +++ b/src/console/components/console/Completion.tsx @@ -35,11 +35,11 @@ class Completion extends React.Component<Props, State> { return null; } - let viewSelect = (() => { + const viewSelect = (() => { let index = 0; for (let i = 0; i < nextProps.completions.length; ++i) { ++index; - let g = nextProps.completions[i]; + const g = nextProps.completions[i]; if (nextProps.select + i + 1 < index + g.items.length) { return nextProps.select + i + 1; } @@ -64,12 +64,12 @@ class Completion extends React.Component<Props, State> { let eles = []; let index = 0; - for (let group of this.props.completions) { + for (const group of this.props.completions) { eles.push(<CompletionTitle key={`group-${index}`} title={ group.name } />); - for (let item of group.items) { + for (const item of group.items) { eles.push(<CompletionItem key={`item-${index}`} icon={item.icon} @@ -81,7 +81,7 @@ class Completion extends React.Component<Props, State> { } } - let viewOffset = this.state.viewOffset; + const viewOffset = this.state.viewOffset; eles = eles.slice(viewOffset, viewOffset + this.props.size); return ( diff --git a/src/console/index.tsx b/src/console/index.tsx index b655154..1209ec2 100644 --- a/src/console/index.tsx +++ b/src/console/index.tsx @@ -14,7 +14,7 @@ const store = createStore( ); window.addEventListener('load', () => { - let wrapper = document.getElementById('vimvixen-console'); + const wrapper = document.getElementById('vimvixen-console'); ReactDOM.render( <Provider store={store} > <Console></Console> @@ -23,7 +23,7 @@ window.addEventListener('load', () => { }); const onMessage = (message: any): any => { - let msg = messages.valueOf(message); + const msg = messages.valueOf(message); switch (msg.type) { case messages.CONSOLE_SHOW_COMMAND: return store.dispatch(consoleActions.showCommand(msg.command)); @@ -39,5 +39,5 @@ const onMessage = (message: any): any => { }; browser.runtime.onMessage.addListener(onMessage); -let port = browser.runtime.connect(undefined, { name: 'vimvixen-console' }); +const port = browser.runtime.connect(undefined, { name: 'vimvixen-console' }); port.onMessage.addListener(onMessage); diff --git a/src/console/reducers/index.ts b/src/console/reducers/index.ts index b6be483..048a24f 100644 --- a/src/console/reducers/index.ts +++ b/src/console/reducers/index.ts @@ -28,7 +28,7 @@ const nextSelection = (state: State): number => { return 0; } - let length = state.completions + const length = state.completions .map(g => g.items.length) .reduce((x, y) => x + y); if (state.select + 1 < length) { @@ -38,7 +38,7 @@ const nextSelection = (state: State): number => { }; const prevSelection = (state: State): number => { - let length = state.completions + const length = state.completions .map(g => g.items.length) .reduce((x, y) => x + y); if (state.select < 0) { @@ -51,7 +51,7 @@ const nextConsoleText = (completions: any[], select: number, defaults: any) => { if (select < 0) { return defaults; } - let items = completions.map(g => g.items).reduce((g1, g2) => g1.concat(g2)); + const items = completions.map(g => g.items).reduce((g1, g2) => g1.concat(g2)); return items[select].content; }; @@ -96,14 +96,14 @@ export default function reducer( completionSource: action.completionSource, select: -1 }; case actions.CONSOLE_COMPLETION_NEXT: { - let select = nextSelection(state); + const select = nextSelection(state); return { ...state, select: select, consoleText: nextConsoleText( state.completions, select, state.completionSource) }; } case actions.CONSOLE_COMPLETION_PREV: { - let select = prevSelection(state); + const select = prevSelection(state); return { ...state, select: select, consoleText: nextConsoleText( diff --git a/src/content/Application.ts b/src/content/Application.ts index 1677655..cfa01fd 100644 --- a/src/content/Application.ts +++ b/src/content/Application.ts @@ -111,7 +111,7 @@ export default class Application { } }); - let inputDriver = new InputDriver(window.document.body); + const inputDriver = new InputDriver(window.document.body); inputDriver.onKey(key => this.followKeyController.press(key)); inputDriver.onKey(key => this.markKeyController.press(key)); inputDriver.onKey(key => this.keymapController.press(key)); diff --git a/src/content/InputDriver.ts b/src/content/InputDriver.ts index bc184d2..cf28205 100644 --- a/src/content/InputDriver.ts +++ b/src/content/InputDriver.ts @@ -25,7 +25,7 @@ const modifiedKeyName = (name: string): string => { // visible for testing export const keyFromKeyboardEvent = (e: KeyboardEvent): Key => { - let key = modifiedKeyName(e.key); + const key = modifiedKeyName(e.key); let shift = e.shiftKey; if (key.length === 1 && key.toUpperCase() === key.toLowerCase()) { // make shift false for symbols to enable key bindings by symbold keys. @@ -83,7 +83,7 @@ export default class InputDriver { // eslint-disable-next-line max-statements private capture(e: KeyboardEvent) { - let target = e.target; + const target = e.target; if (!(target instanceof HTMLElement)) { return; } @@ -98,9 +98,9 @@ export default class InputDriver { return; } - let key = keyFromKeyboardEvent(e); - for (let listener of this.onKeyListeners) { - let stop = listener(key); + const key = keyFromKeyboardEvent(e); + for (const listener of this.onKeyListeners) { + const stop = listener(key); if (stop) { e.preventDefault(); e.stopPropagation(); diff --git a/src/content/MessageListener.ts b/src/content/MessageListener.ts index d035825..e1f7c75 100644 --- a/src/content/MessageListener.ts +++ b/src/content/MessageListener.ts @@ -9,7 +9,7 @@ export default class MessageListener { listener: (msg: Message, sender: Window) => void, ) { window.addEventListener('message', (event: MessageEvent) => { - let sender = event.source; + const sender = event.source; if (!(sender instanceof Window)) { return; } diff --git a/src/content/client/FindClient.ts b/src/content/client/FindClient.ts index af0b427..8b2aca4 100644 --- a/src/content/client/FindClient.ts +++ b/src/content/client/FindClient.ts @@ -8,7 +8,7 @@ export default interface FindClient { export class FindClientImpl implements FindClient { async getGlobalLastKeyword(): Promise<string | null> { - let keyword = await browser.runtime.sendMessage({ + const keyword = await browser.runtime.sendMessage({ type: messages.FIND_GET_KEYWORD, }); return keyword as string; diff --git a/src/content/client/SettingClient.ts b/src/content/client/SettingClient.ts index fc62720..f89f3cd 100644 --- a/src/content/client/SettingClient.ts +++ b/src/content/client/SettingClient.ts @@ -7,7 +7,7 @@ export default interface SettingClient { export class SettingClientImpl { async load(): Promise<Settings> { - let settings = await browser.runtime.sendMessage({ + const settings = await browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, }); return Settings.fromJSON(settings); diff --git a/src/content/controllers/AddonEnabledController.ts b/src/content/controllers/AddonEnabledController.ts index bae95bf..59b45fa 100644 --- a/src/content/controllers/AddonEnabledController.ts +++ b/src/content/controllers/AddonEnabledController.ts @@ -12,7 +12,7 @@ export default class AddonEnabledController { getAddonEnabled( _message: messages.AddonEnabledQueryMessage, ): Promise<boolean> { - let enabled = this.addonEnabledUseCase.getEnabled(); + const enabled = this.addonEnabledUseCase.getEnabled(); return Promise.resolve(enabled); } } diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts index 452e3d4..f9c2545 100644 --- a/src/content/controllers/KeymapController.ts +++ b/src/content/controllers/KeymapController.ts @@ -32,7 +32,7 @@ export default class KeymapController { // eslint-disable-next-line complexity, max-lines-per-function press(key: Key): boolean { - let nextOp = this.keymapUseCase.nextOps(key); + const nextOp = this.keymapUseCase.nextOps(key); if (nextOp === null) { return false; } diff --git a/src/content/controllers/SettingController.ts b/src/content/controllers/SettingController.ts index e1c7f01..9124188 100644 --- a/src/content/controllers/SettingController.ts +++ b/src/content/controllers/SettingController.ts @@ -14,9 +14,9 @@ export default class SettingController { async initSettings(): Promise<void> { try { - let current = await this.settingUseCase.reload(); - let url = new URL(window.location.href); - let disabled = current.blacklist.includesEntireBlacklist(url); + const current = await this.settingUseCase.reload(); + const url = new URL(window.location.href); + const disabled = current.blacklist.includesEntireBlacklist(url); if (disabled) { this.addonEnabledUseCase.disable(); } else { diff --git a/src/content/domains/KeySequence.ts b/src/content/domains/KeySequence.ts index 4534b60..cf59125 100644 --- a/src/content/domains/KeySequence.ts +++ b/src/content/domains/KeySequence.ts @@ -38,7 +38,7 @@ export default class KeySequence { if (nonDigitAt === -1) { nonDigitAt = this.keys.length; } - let digits = this.keys.slice(0, nonDigitAt) + const digits = this.keys.slice(0, nonDigitAt) .map(key => key.key) .join(''); return Number(digits); @@ -53,7 +53,7 @@ export default class KeySequence { } splitNumericPrefix(): [KeySequence, KeySequence] { - let nonDigitIndex = this.keys.findIndex(key => !key.isDigit()); + const nonDigitIndex = this.keys.findIndex(key => !key.isDigit()); if (nonDigitIndex === -1) { return [this, new KeySequence([])]; } @@ -73,7 +73,7 @@ export default class KeySequence { let nextPos = 1; if (remaining.startsWith('<')) { - let ltPos = remaining.indexOf('>'); + const ltPos = remaining.indexOf('>'); if (ltPos > 0) { nextPos = ltPos + 1; } @@ -85,7 +85,7 @@ export default class KeySequence { ); }; - let data = fromMapKeysRecursive(keys, []); + const data = fromMapKeysRecursive(keys, []); return new KeySequence(data); } } diff --git a/src/content/hint-key-producer.ts b/src/content/hint-key-producer.ts index 935394e..3c9482f 100644 --- a/src/content/hint-key-producer.ts +++ b/src/content/hint-key-producer.ts @@ -19,14 +19,14 @@ export default class HintKeyProducer { } private increment(): void { - let max = this.charset.length - 1; + const max = this.charset.length - 1; if (this.counter.every(x => x === max)) { this.counter = new Array(this.counter.length + 1).fill(0); return; } this.counter.reverse(); - let len = this.charset.length; + const len = this.charset.length; let num = this.counter.reduce((x, y, index) => x + y * len ** index) + 1; for (let i = 0; i < this.counter.length; ++i) { this.counter[i] = num % len; diff --git a/src/content/index.ts b/src/content/index.ts index 5b9b92c..176a157 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -11,10 +11,10 @@ if (window.self === window.top) { } try { - let app = container.resolve(Application); + const app = container.resolve(Application); app.run(); } catch (e) { console.error(e); } -let style = window.document.createElement('style'); +const style = window.document.createElement('style'); style.textContent = consoleFrameStyle; window.document.head.appendChild(style); diff --git a/src/content/presenters/ConsoleFramePresenter.ts b/src/content/presenters/ConsoleFramePresenter.ts index 62db2bb..63c78fb 100644 --- a/src/content/presenters/ConsoleFramePresenter.ts +++ b/src/content/presenters/ConsoleFramePresenter.ts @@ -6,7 +6,7 @@ export default interface ConsoleFramePresenter { export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { initialize(): void { - let iframe = document.createElement('iframe'); + const iframe = document.createElement('iframe'); iframe.src = browser.runtime.getURL('build/console.html'); iframe.id = 'vimvixen-console-frame'; iframe.className = 'vimvixen-console-frame'; @@ -14,7 +14,7 @@ export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { } blur(): void { - let ele = document.getElementById('vimvixen-console-frame'); + const ele = document.getElementById('vimvixen-console-frame'); if (!ele) { throw new Error('console frame not created'); } diff --git a/src/content/presenters/FindPresenter.ts b/src/content/presenters/FindPresenter.ts index f171d2f..98d8088 100644 --- a/src/content/presenters/FindPresenter.ts +++ b/src/content/presenters/FindPresenter.ts @@ -26,13 +26,13 @@ declare var window: MyWindow; export class FindPresenterImpl implements FindPresenter { find(keyword: string, backwards: boolean): boolean { - let caseSensitive = false; - let wrapScan = true; + const caseSensitive = false; + const wrapScan = true; // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work // because of same origin policy - let found = window.find(keyword, caseSensitive, backwards, wrapScan); + const found = window.find(keyword, caseSensitive, backwards, wrapScan); if (found) { return found; } @@ -42,7 +42,7 @@ export class FindPresenterImpl implements FindPresenter { } clearSelection(): void { - let sel = window.getSelection(); + const sel = window.getSelection(); if (sel) { sel.removeAllRanges(); } diff --git a/src/content/presenters/FocusPresenter.ts b/src/content/presenters/FocusPresenter.ts index 7e20cd6..842c41e 100644 --- a/src/content/presenters/FocusPresenter.ts +++ b/src/content/presenters/FocusPresenter.ts @@ -6,10 +6,10 @@ export default interface FocusPresenter { export class FocusPresenterImpl implements FocusPresenter { focusFirstElement(): boolean { - let inputTypes = ['email', 'number', 'search', 'tel', 'text', 'url']; - let inputSelector = inputTypes.map(type => `input[type=${type}]`).join(','); - let targets = window.document.querySelectorAll(inputSelector + ',textarea'); - let target = Array.from(targets).find(doms.isVisible); + const inputTypes = ['email', 'number', 'search', 'tel', 'text', 'url']; + const inputSelector = inputTypes.map(type => `input[type=${type}]`).join(','); + const targets = window.document.querySelectorAll(inputSelector + ',textarea'); + const target = Array.from(targets).find(doms.isVisible); if (target instanceof HTMLInputElement) { target.focus(); return true; diff --git a/src/content/presenters/FollowPresenter.ts b/src/content/presenters/FollowPresenter.ts index 0132621..fef8140 100644 --- a/src/content/presenters/FollowPresenter.ts +++ b/src/content/presenters/FollowPresenter.ts @@ -23,12 +23,12 @@ const inViewport = ( viewSize: Size, framePosition: Point, ): boolean => { - let { + const { top, left, bottom, right } = doms.viewportRect(element); - let doc = win.document; - let frameWidth = doc.documentElement.clientWidth; - let frameHeight = doc.documentElement.clientHeight; + const doc = win.document; + const frameWidth = doc.documentElement.clientWidth; + const frameHeight = doc.documentElement.clientHeight; if (right < 0 || bottom < 0 || top > frameHeight || left > frameWidth) { // out of frame @@ -47,10 +47,10 @@ const isAriaHiddenOrAriaDisabled = (win: Window, element: Element): boolean => { if (!element || win.document.documentElement === element) { return false; } - for (let attr of ['aria-hidden', 'aria-disabled']) { - let value = element.getAttribute(attr); + for (const attr of ['aria-hidden', 'aria-disabled']) { + const value = element.getAttribute(attr); if (value !== null) { - let hidden = value.toLowerCase(); + const hidden = value.toLowerCase(); if (hidden === '' || hidden === 'true') { return true; } @@ -79,15 +79,15 @@ export class FollowPresenterImpl implements FollowPresenter { } getTargetCount(viewSize: Size, framePosition: Point): number { - let targets = this.getTargets(viewSize, framePosition); + const targets = this.getTargets(viewSize, framePosition); return targets.length; } createHints(viewSize: Size, framePosition: Point, tags: string[]): void { - let targets = this.getTargets(viewSize, framePosition); - let min = Math.min(targets.length, tags.length); + const targets = this.getTargets(viewSize, framePosition); + const min = Math.min(targets.length, tags.length); for (let i = 0; i < min; ++i) { - let target = targets[i]; + const target = targets[i]; if (target instanceof HTMLAnchorElement || target instanceof HTMLAreaElement) { this.hints.push(new LinkHint(target, tags[i])); @@ -98,8 +98,8 @@ export class FollowPresenterImpl implements FollowPresenter { } filterHints(prefix: string): void { - let shown = this.hints.filter(h => h.getTag().startsWith(prefix)); - let hidden = this.hints.filter(h => !h.getTag().startsWith(prefix)); + const shown = this.hints.filter(h => h.getTag().startsWith(prefix)); + const hidden = this.hints.filter(h => !h.getTag().startsWith(prefix)); shown.forEach(h => h.show()); hidden.forEach(h => h.hide()); @@ -115,9 +115,9 @@ export class FollowPresenterImpl implements FollowPresenter { } private getTargets(viewSize: Size, framePosition: Point): HTMLElement[] { - let all = window.document.querySelectorAll(TARGET_SELECTOR); - let filtered = Array.prototype.filter.call(all, (element: HTMLElement) => { - let style = window.getComputedStyle(element); + const all = window.document.querySelectorAll(TARGET_SELECTOR); + const filtered = Array.prototype.filter.call(all, (element: HTMLElement) => { + const style = window.getComputedStyle(element); // AREA's 'display' in Browser style is 'none' return (element.tagName === 'AREA' || style.display !== 'none') && diff --git a/src/content/presenters/Hint.ts b/src/content/presenters/Hint.ts index 60c0f4c..44b8185 100644 --- a/src/content/presenters/Hint.ts +++ b/src/content/presenters/Hint.ts @@ -6,7 +6,7 @@ interface Point { } const hintPosition = (element: Element): Point => { - let { left, top, right, bottom } = doms.viewportRect(element); + const { left, top, right, bottom } = doms.viewportRect(element); if (element.tagName !== 'AREA') { return { x: left, y: top }; @@ -26,15 +26,15 @@ export default abstract class Hint { constructor(target: HTMLElement, tag: string) { this.tag = tag; - let doc = target.ownerDocument; + const doc = target.ownerDocument; if (doc === null) { throw new TypeError('ownerDocument is null'); } - let { x, y } = hintPosition(target); - let { scrollX, scrollY } = window; + const { x, y } = hintPosition(target); + const { scrollX, scrollY } = window; - let hint = doc.createElement('span'); + const hint = doc.createElement('span'); hint.className = 'vimvixen-hint'; hint.textContent = tag; hint.style.left = x + scrollX + 'px'; @@ -95,7 +95,7 @@ export class InputHint extends Hint { } activate(): void { - let target = this.target; + const target = this.target; switch (target.tagName.toLowerCase()) { case 'input': switch ((target as HTMLInputElement).type) { diff --git a/src/content/presenters/NavigationPresenter.ts b/src/content/presenters/NavigationPresenter.ts index 11d96ec..951e62a 100644 --- a/src/content/presenters/NavigationPresenter.ts +++ b/src/content/presenters/NavigationPresenter.ts @@ -49,7 +49,7 @@ export class NavigationPresenterImpl implements NavigationPresenter { // Code common to linkPrev and linkNext which navigates to the specified page. private linkRel(rel: 'prev' | 'next'): void { - let link = selectLast<HTMLLinkElement>(`link[rel~=${rel}][href]`); + const link = selectLast<HTMLLinkElement>(`link[rel~=${rel}][href]`); if (link) { window.location.href = link.href; return; @@ -57,7 +57,7 @@ export class NavigationPresenterImpl implements NavigationPresenter { const pattern = REL_PATTERN[rel]; - let a = selectLast<HTMLAnchorElement>(`a[rel~=${rel}][href]`) || + const a = selectLast<HTMLAnchorElement>(`a[rel~=${rel}][href]`) || // `innerText` is much slower than `textContent`, but produces much better // (i.e. less unexpected) results selectLast('a[href]', lnk => pattern.test(lnk.innerText)); diff --git a/src/content/presenters/ScrollPresenter.ts b/src/content/presenters/ScrollPresenter.ts index e83f172..387ab62 100644 --- a/src/content/presenters/ScrollPresenter.ts +++ b/src/content/presenters/ScrollPresenter.ts @@ -8,7 +8,7 @@ let scrolling = false; let lastTimeoutId: number | null = null; const isScrollableStyle = (element: Element): boolean => { - let { overflowX, overflowY } = window.getComputedStyle(element); + const { overflowX, overflowY } = window.getComputedStyle(element); return !(overflowX !== 'scroll' && overflowX !== 'auto' && overflowY !== 'scroll' && overflowY !== 'auto'); }; @@ -27,9 +27,9 @@ const findScrollable = (element: Element): Element | null => { return element; } - let children = Array.from(element.children).filter(doms.isVisible); - for (let child of children) { - let scrollable = findScrollable(child); + const children = Array.from(element.children).filter(doms.isVisible); + for (const child of children) { + const scrollable = findScrollable(child); if (scrollable) { return scrollable; } @@ -44,7 +44,7 @@ const scrollTarget = () => { if (isOverflowed(window.document.body)) { return window.document.body; } - let target = findScrollable(window.document.documentElement); + const target = findScrollable(window.document.documentElement); if (target) { return target; } @@ -79,8 +79,8 @@ class Scroller { } scrollBy(x: number, y: number): void { - let left = this.element.scrollLeft + x; - let top = this.element.scrollTop + y; + const left = this.element.scrollLeft + x; + const top = this.element.scrollTop + y; this.scrollTo(left, top); } @@ -110,12 +110,12 @@ export default interface ScrollPresenter { export class ScrollPresenterImpl { getScroll(): Point { - let target = scrollTarget(); + const target = scrollTarget(); return { x: target.scrollLeft, y: target.scrollTop }; } scrollVertically(count: number, smooth: boolean): void { - let target = scrollTarget(); + const target = scrollTarget(); let delta = SCROLL_DELTA_Y * count; if (scrolling) { delta = SCROLL_DELTA_Y * count * 4; @@ -124,7 +124,7 @@ export class ScrollPresenterImpl { } scrollHorizonally(count: number, smooth: boolean): void { - let target = scrollTarget(); + const target = scrollTarget(); let delta = SCROLL_DELTA_X * count; if (scrolling) { delta = SCROLL_DELTA_X * count * 4; @@ -133,8 +133,8 @@ export class ScrollPresenterImpl { } scrollPages(count: number, smooth: boolean): void { - let target = scrollTarget(); - let height = target.clientHeight; + const target = scrollTarget(); + const height = target.clientHeight; let delta = height * count; if (scrolling) { delta = height * count; @@ -143,35 +143,35 @@ export class ScrollPresenterImpl { } scrollTo(x: number, y: number, smooth: boolean): void { - let target = scrollTarget(); + const target = scrollTarget(); new Scroller(target, smooth).scrollTo(x, y); } scrollToTop(smooth: boolean): void { - let target = scrollTarget(); - let x = target.scrollLeft; - let y = 0; + const target = scrollTarget(); + const x = target.scrollLeft; + const y = 0; new Scroller(target, smooth).scrollTo(x, y); } scrollToBottom(smooth: boolean): void { - let target = scrollTarget(); - let x = target.scrollLeft; - let y = target.scrollHeight; + const target = scrollTarget(); + const x = target.scrollLeft; + const y = target.scrollHeight; new Scroller(target, smooth).scrollTo(x, y); } scrollToHome(smooth: boolean): void { - let target = scrollTarget(); - let x = 0; - let y = target.scrollTop; + const target = scrollTarget(); + const x = 0; + const y = target.scrollTop; new Scroller(target, smooth).scrollTo(x, y); } scrollToEnd(smooth: boolean): void { - let target = scrollTarget(); - let x = target.scrollWidth; - let y = target.scrollTop; + const target = scrollTarget(); + const x = target.scrollWidth; + const y = target.scrollTop; new Scroller(target, smooth).scrollTo(x, y); } } diff --git a/src/content/repositories/AddonEnabledRepository.ts b/src/content/repositories/AddonEnabledRepository.ts index 7921bdb..ce3f521 100644 --- a/src/content/repositories/AddonEnabledRepository.ts +++ b/src/content/repositories/AddonEnabledRepository.ts @@ -1,4 +1,4 @@ -let enabled: boolean = false; +let enabled = false; export default interface AddonEnabledRepository { set(on: boolean): void; diff --git a/src/content/repositories/ClipboardRepository.ts b/src/content/repositories/ClipboardRepository.ts index a046851..8219835 100644 --- a/src/content/repositories/ClipboardRepository.ts +++ b/src/content/repositories/ClipboardRepository.ts @@ -6,7 +6,7 @@ export default interface ClipboardRepository { export class ClipboardRepositoryImpl { read(): string { - let textarea = window.document.createElement('textarea'); + const textarea = window.document.createElement('textarea'); window.document.body.append(textarea); textarea.style.position = 'fixed'; @@ -14,8 +14,8 @@ export class ClipboardRepositoryImpl { textarea.contentEditable = 'true'; textarea.focus(); - let ok = window.document.execCommand('paste'); - let value = textarea.textContent!!; + const ok = window.document.execCommand('paste'); + const value = textarea.textContent!!; textarea.remove(); if (!ok) { @@ -26,7 +26,7 @@ export class ClipboardRepositoryImpl { } write(text: string): void { - let input = window.document.createElement('input'); + const input = window.document.createElement('input'); window.document.body.append(input); input.style.position = 'fixed'; @@ -34,7 +34,7 @@ export class ClipboardRepositoryImpl { input.value = text; input.select(); - let ok = window.document.execCommand('copy'); + const ok = window.document.execCommand('copy'); input.remove(); if (!ok) { diff --git a/src/content/repositories/MarkKeyRepository.ts b/src/content/repositories/MarkKeyRepository.ts index 0b24af2..18c3e23 100644 --- a/src/content/repositories/MarkKeyRepository.ts +++ b/src/content/repositories/MarkKeyRepository.ts @@ -17,7 +17,7 @@ interface Mode { jumpMode: boolean; } -let current: Mode = { +const current: Mode = { setMode: false, jumpMode: false, }; diff --git a/src/content/repositories/MarkRepository.ts b/src/content/repositories/MarkRepository.ts index 678abc4..afa980a 100644 --- a/src/content/repositories/MarkRepository.ts +++ b/src/content/repositories/MarkRepository.ts @@ -14,7 +14,7 @@ export class MarkRepositoryImpl implements MarkRepository { } get(key: string): Mark | null { - let v = saved[key]; + const v = saved[key]; if (!v) { return null; } diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts index 2d6fa11..608a401 100644 --- a/src/content/usecases/AddonEnabledUseCase.ts +++ b/src/content/usecases/AddonEnabledUseCase.ts @@ -23,7 +23,7 @@ export default class AddonEnabledUseCase { } async toggle(): Promise<void> { - let current = this.repository.get(); + const current = this.repository.get(); await this.setEnabled(!current); } diff --git a/src/content/usecases/ClipboardUseCase.ts b/src/content/usecases/ClipboardUseCase.ts index c8fe719..7f16f68 100644 --- a/src/content/usecases/ClipboardUseCase.ts +++ b/src/content/usecases/ClipboardUseCase.ts @@ -16,16 +16,16 @@ export default class ClipboardUseCase { } async yankCurrentURL(): Promise<string> { - let url = window.location.href; + const url = window.location.href; this.repository.write(url); await this.consoleClient.info('Yanked ' + url); return Promise.resolve(url); } async openOrSearch(newTab: boolean): Promise<void> { - let search = this.settingRepository.get().search; - let text = this.repository.read(); - let url = urls.searchUrl(text, search); + const search = this.settingRepository.get().search; + const text = this.repository.read(); + const url = urls.searchUrl(text, search); // TODO: Repeat pasting from clipboard instead of opening a certain url. // 'Repeat last' command is implemented in the background script and cannot diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts index 88b516c..c6a478f 100644 --- a/src/content/usecases/FindUseCase.ts +++ b/src/content/usecases/FindUseCase.ts @@ -19,7 +19,7 @@ export default class FindUseCase { if (keyword) { this.saveKeyword(keyword); } else { - let lastKeyword = await this.getKeyword(); + const lastKeyword = await this.getKeyword(); if (!lastKeyword) { return this.showNoLastKeywordError(); } @@ -39,11 +39,11 @@ export default class FindUseCase { private async findNextPrev( backwards: boolean, ): Promise<void> { - let keyword = await this.getKeyword(); + const keyword = await this.getKeyword(); if (!keyword) { return this.showNoLastKeywordError(); } - let found = this.presenter.find(keyword, backwards); + const found = this.presenter.find(keyword, backwards); if (found) { this.consoleClient.info('Pattern found: ' + keyword); } else { diff --git a/src/content/usecases/FollowMasterUseCase.ts b/src/content/usecases/FollowMasterUseCase.ts index 7d7e875..0e7f394 100644 --- a/src/content/usecases/FollowMasterUseCase.ts +++ b/src/content/usecases/FollowMasterUseCase.ts @@ -28,24 +28,24 @@ export default class FollowMasterUseCase { } startFollow(newTab: boolean, background: boolean): void { - let hintchars = this.settingRepository.get().properties.hintchars; + const hintchars = this.settingRepository.get().properties.hintchars; this.producer = new HintKeyProducer(hintchars); this.followKeyRepository.clearKeys(); this.followMasterRepository.setCurrentFollowMode(newTab, background); - let viewWidth = window.top.innerWidth; - let viewHeight = window.top.innerHeight; + const viewWidth = window.top.innerWidth; + const viewHeight = window.top.innerHeight; this.followSlaveClientFactory.create(window.top).requestHintCount( { width: viewWidth, height: viewHeight }, { x: 0, y: 0 }, ); - let frameElements = window.document.querySelectorAll('iframe'); + const frameElements = window.document.querySelectorAll('iframe'); for (let i = 0; i < frameElements.length; ++i) { - let ele = frameElements[i] as HTMLFrameElement | HTMLIFrameElement; - let { left: frameX, top: frameY } = ele.getBoundingClientRect(); - let client = this.followSlaveClientFactory.create(ele.contentWindow!!); + const ele = frameElements[i] as HTMLFrameElement | HTMLIFrameElement; + const { left: frameX, top: frameY } = ele.getBoundingClientRect(); + const client = this.followSlaveClientFactory.create(ele.contentWindow!!); client.requestHintCount( { width: viewWidth, height: viewHeight }, { x: frameX, y: frameY }, @@ -55,28 +55,28 @@ export default class FollowMasterUseCase { // eslint-disable-next-line max-statements createSlaveHints(count: number, sender: Window): void { - let produced = []; + const produced = []; for (let i = 0; i < count; ++i) { - let tag = this.producer!!.produce(); + const tag = this.producer!!.produce(); produced.push(tag); this.followMasterRepository.addTag(tag); } - let doc = window.document; - let viewWidth = window.innerWidth || doc.documentElement.clientWidth; - let viewHeight = window.innerHeight || doc.documentElement.clientHeight; + const doc = window.document; + const viewWidth = window.innerWidth || doc.documentElement.clientWidth; + const viewHeight = window.innerHeight || doc.documentElement.clientHeight; let pos = { x: 0, y: 0 }; if (sender !== window) { - let frameElements = window.document.querySelectorAll('iframe'); - let ele = Array.from(frameElements).find(e => e.contentWindow === sender); + const frameElements = window.document.querySelectorAll('iframe'); + const ele = Array.from(frameElements).find(e => e.contentWindow === sender); if (!ele) { // elements of the sender is gone return; } - let { left: frameX, top: frameY } = ele.getBoundingClientRect(); + const { left: frameX, top: frameY } = ele.getBoundingClientRect(); pos = { x: frameX, y: frameY }; } - let client = this.followSlaveClientFactory.create(sender); + const client = this.followSlaveClientFactory.create(sender); client.createHints( { width: viewWidth, height: viewHeight }, pos, @@ -100,8 +100,8 @@ export default class FollowMasterUseCase { activate(tag: string): void { this.followMasterRepository.clearTags(); - let newTab = this.followMasterRepository.getCurrentNewTabMode(); - let background = this.followMasterRepository.getCurrentBackgroundMode(); + const newTab = this.followMasterRepository.getCurrentNewTabMode(); + const background = this.followMasterRepository.getCurrentBackgroundMode(); this.broadcastToSlaves((client) => { client.activateIfExists(tag, newTab, background); client.clearHints(); @@ -125,8 +125,8 @@ export default class FollowMasterUseCase { this.followKeyRepository.pushKey(key); - let tag = this.getCurrentTag(); - let matched = this.followMasterRepository.getTagsByPrefix(tag); + const tag = this.getCurrentTag(); + const matched = this.followMasterRepository.getTagsByPrefix(tag); if (matched.length === 0) { this.cancelFollow(); } else if (matched.length === 1) { @@ -137,9 +137,9 @@ export default class FollowMasterUseCase { } private broadcastToSlaves(handler: (client: FollowSlaveClient) => void) { - let allFrames = [window.self].concat(Array.from(window.frames as any)); - let clients = allFrames.map(w => this.followSlaveClientFactory.create(w)); - for (let client of clients) { + const allFrames = [window.self].concat(Array.from(window.frames as any)); + const clients = allFrames.map(w => this.followSlaveClientFactory.create(w)); + for (const client of clients) { handler(client); } } diff --git a/src/content/usecases/FollowSlaveUseCase.ts b/src/content/usecases/FollowSlaveUseCase.ts index d471adb..fb805b9 100644 --- a/src/content/usecases/FollowSlaveUseCase.ts +++ b/src/content/usecases/FollowSlaveUseCase.ts @@ -34,7 +34,7 @@ export default class FollowSlaveUseCase { } countTargets(viewSize: Size, framePosition: Point): void { - let count = this.presenter.getTargetCount(viewSize, framePosition); + const count = this.presenter.getTargetCount(viewSize, framePosition); this.followMasterClient.responseHintCount(count); } @@ -56,13 +56,13 @@ export default class FollowSlaveUseCase { } async activate(tag: string, newTab: boolean, background: boolean) { - let hint = this.presenter.getHint(tag); + const hint = this.presenter.getHint(tag); if (!hint) { return; } if (hint instanceof LinkHint) { - let url = hint.getLink(); + const url = hint.getLink(); let openNewTab = newTab; // Open link by background script in order to prevent a popup block if (hint.getLinkTarget() === '_blank') { diff --git a/src/content/usecases/HintKeyProducer.ts b/src/content/usecases/HintKeyProducer.ts index 241cd56..68f3fbd 100644 --- a/src/content/usecases/HintKeyProducer.ts +++ b/src/content/usecases/HintKeyProducer.ts @@ -19,14 +19,14 @@ export default class HintKeyProducer { } private increment(): void { - let max = this.charset.length - 1; + const max = this.charset.length - 1; if (this.counter.every(x => x === max)) { this.counter = new Array(this.counter.length + 1).fill(0); return; } this.counter.reverse(); - let len = this.charset.length; + const len = this.charset.length; let num = this.counter.reduce((x, y, index) => x + y * len ** index) + 1; for (let i = 0; i < this.counter.length; ++i) { this.counter[i] = num % len; diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index a2e7cc3..074de72 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -37,17 +37,17 @@ export default class KeymapUseCase { // eslint-disable-next-line max-statements nextOps(key: Key): { repeat: number, op: operations.Operation } | null { - let sequence = this.repository.enqueueKey(key); - let baseSequence = sequence.trimNumericPrefix(); + const sequence = this.repository.enqueueKey(key); + const baseSequence = sequence.trimNumericPrefix(); if (baseSequence.length() === 1 && this.blacklistKey(key)) { // ignore if the input starts with black list keys this.repository.clear(); return null; } - let keymaps = this.keymapEntityMap(); - let matched = keymaps.filter(([seq]) => seq.startsWith(sequence)); - let baseMatched = keymaps.filter(([seq]) => seq.startsWith(baseSequence)); + const keymaps = this.keymapEntityMap(); + const matched = keymaps.filter(([seq]) => seq.startsWith(sequence)); + const baseMatched = keymaps.filter(([seq]) => seq.startsWith(baseSequence)); if (matched.length === 1 && sequence.length() === matched[0][0].length()) { @@ -71,7 +71,7 @@ export default class KeymapUseCase { } private keymapEntityMap(): [KeySequence, operations.Operation][] { - let keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); + const keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); let entries = keymaps.entries().map( ([keys, op]) => [KeySequence.fromMapKeys(keys), op] ) as [KeySequence, operations.Operation][]; @@ -86,8 +86,8 @@ export default class KeymapUseCase { } private blacklistKey(key: Key): boolean { - let url = this.addressRepository.getCurrentURL(); - let blacklist = this.settingRepository.get().blacklist; + const url = this.addressRepository.getCurrentURL(); + const blacklist = this.settingRepository.get().blacklist; return blacklist.includeKey(url, key); } } diff --git a/src/content/usecases/MarkUseCase.ts b/src/content/usecases/MarkUseCase.ts index a7d5ad8..8cd0c72 100644 --- a/src/content/usecases/MarkUseCase.ts +++ b/src/content/usecases/MarkUseCase.ts @@ -17,7 +17,7 @@ export default class MarkUseCase { } async set(key: string): Promise<void> { - let pos = this.scrollPresenter.getScroll(); + const pos = this.scrollPresenter.getScroll(); if (this.globalKey(key)) { this.client.setGloablMark(key, pos); await this.consoleClient.info(`Set global mark to '${key}'`); @@ -31,7 +31,7 @@ export default class MarkUseCase { if (this.globalKey(key)) { await this.client.jumpGlobalMark(key); } else { - let pos = this.repository.get(key); + const pos = this.repository.get(key); if (!pos) { throw new Error('Mark is not set'); } @@ -40,7 +40,7 @@ export default class MarkUseCase { } scroll(x: number, y: number): void { - let smooth = this.settingRepository.get().properties.smoothscroll; + const smooth = this.settingRepository.get().properties.smoothscroll; this.scrollPresenter.scrollTo(x, y, smooth); } diff --git a/src/content/usecases/ScrollUseCase.ts b/src/content/usecases/ScrollUseCase.ts index 32cbef1..c68c889 100644 --- a/src/content/usecases/ScrollUseCase.ts +++ b/src/content/usecases/ScrollUseCase.ts @@ -11,42 +11,42 @@ export default class ScrollUseCase { } scrollVertically(count: number): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollVertically(count, smooth); } scrollHorizonally(count: number): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollHorizonally(count, smooth); } scrollPages(count: number): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollPages(count, smooth); } scrollToTop(): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollToTop(smooth); } scrollToBottom(): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollToBottom(smooth); } scrollToHome(): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollToHome(smooth); } scrollToEnd(): void { - let smooth = this.getSmoothScroll(); + const smooth = this.getSmoothScroll(); this.presenter.scrollToEnd(smooth); } private getSmoothScroll(): boolean { - let settings = this.settingRepository.get(); + const settings = this.settingRepository.get(); return settings.properties.smoothscroll; } } diff --git a/src/content/usecases/SettingUseCase.ts b/src/content/usecases/SettingUseCase.ts index 4608039..67d1be6 100644 --- a/src/content/usecases/SettingUseCase.ts +++ b/src/content/usecases/SettingUseCase.ts @@ -12,7 +12,7 @@ export default class SettingUseCase { } async reload(): Promise<Settings> { - let settings = await this.client.load(); + const settings = await this.client.load(); this.repository.set(settings); return settings; } diff --git a/src/settings/actions/setting.ts b/src/settings/actions/setting.ts index 9404791..589ec36 100644 --- a/src/settings/actions/setting.ts +++ b/src/settings/actions/setting.ts @@ -5,7 +5,7 @@ import SettingData, { } from '../../shared/SettingData'; const load = async(): Promise<actions.SettingAction> => { - let data = await storages.load(); + const data = await storages.load(); return set(data); }; @@ -29,7 +29,7 @@ const save = async(data: SettingData): Promise<actions.SettingAction> => { const switchToForm = (json: JSONTextSettings): actions.SettingAction => { try { // toSettings exercise validation - let form = FormSettings.fromSettings(json.toSettings()); + const form = FormSettings.fromSettings(json.toSettings()); return { type: actions.SETTING_SWITCH_TO_FORM, form, @@ -44,7 +44,7 @@ const switchToForm = (json: JSONTextSettings): actions.SettingAction => { }; const switchToJson = (form: FormSettings): actions.SettingAction => { - let json = JSONTextSettings.fromSettings(form.toSettings()); + const json = JSONTextSettings.fromSettings(form.toSettings()); return { type: actions.SETTING_SWITCH_TO_JSON, json, @@ -52,7 +52,7 @@ const switchToJson = (form: FormSettings): actions.SettingAction => { }; const set = (data: SettingData): actions.SettingAction => { - let source = data.getSource(); + const source = data.getSource(); switch (source) { case SettingSource.JSON: return { diff --git a/src/settings/components/form/BlacklistForm.tsx b/src/settings/components/form/BlacklistForm.tsx index 4e96cbf..51c32f4 100644 --- a/src/settings/components/form/BlacklistForm.tsx +++ b/src/settings/components/form/BlacklistForm.tsx @@ -43,9 +43,9 @@ class BlacklistForm extends React.Component<Props> { } bindValue(e: any) { - let name = e.target.name; - let index = e.target.getAttribute('data-index'); - let items = this.props.value.items; + const name = e.target.name; + const index = e.target.getAttribute('data-index'); + const items = this.props.value.items; if (name === 'url') { items[index] = new BlacklistItem(e.target.value, false, []); diff --git a/src/settings/components/form/KeymapsForm.tsx b/src/settings/components/form/KeymapsForm.tsx index 94934ae..dc74de3 100644 --- a/src/settings/components/form/KeymapsForm.tsx +++ b/src/settings/components/form/KeymapsForm.tsx @@ -18,14 +18,14 @@ class KeymapsForm extends React.Component<Props> { }; render() { - let values = this.props.value.toJSON(); + const values = this.props.value.toJSON(); return <div className='form-keymaps-form'> { keymaps.fields.map((group, index) => { return <div key={index} className='form-keymaps-form-field-group'> { group.map(([name, label]) => { - let value = values[name] || ''; + const value = values[name] || ''; return <Input type='text' id={name} name={name} key={name} label={label} value={value} diff --git a/src/settings/components/form/PartialBlacklistForm.tsx b/src/settings/components/form/PartialBlacklistForm.tsx index 0702913..1807e28 100644 --- a/src/settings/components/form/PartialBlacklistForm.tsx +++ b/src/settings/components/form/PartialBlacklistForm.tsx @@ -52,15 +52,15 @@ class PartialBlacklistForm extends React.Component<Props> { } bindValue(e: any) { - let name = e.target.name; - let index = e.target.getAttribute('data-index'); - let items = this.props.value.items; + const name = e.target.name; + const index = e.target.getAttribute('data-index'); + const items = this.props.value.items; if (name === 'url') { - let current = items[index]; + const current = items[index]; items[index] = new BlacklistItem(e.target.value, true, current.keys); } else if (name === 'keys') { - let current = items[index]; + const current = items[index]; items[index] = new BlacklistItem( current.pattern, true, e.target.value.split(',')); } else if (name === 'add') { diff --git a/src/settings/components/form/PropertiesForm.tsx b/src/settings/components/form/PropertiesForm.tsx index db8c8e5..e648971 100644 --- a/src/settings/components/form/PropertiesForm.tsx +++ b/src/settings/components/form/PropertiesForm.tsx @@ -17,13 +17,13 @@ class PropertiesForm extends React.Component<Props> { }; render() { - let types = this.props.types; - let values = this.props.value; + const types = this.props.types; + const values = this.props.value; return <div className='form-properties-form'> { Object.keys(types).map((name) => { - let type = types[name]; + const type = types[name]; let inputType = ''; let onChange = this.bindValue.bind(this); if (type === 'string') { @@ -59,8 +59,8 @@ class PropertiesForm extends React.Component<Props> { } bindValue(e: React.ChangeEvent<HTMLInputElement>) { - let name = e.target.name; - let next = { ...this.props.value }; + const name = e.target.name; + const next = { ...this.props.value }; if (e.target.type.toLowerCase() === 'checkbox') { next[name] = e.target.checked; } else if (e.target.type.toLowerCase() === 'number') { diff --git a/src/settings/components/form/SearchForm.tsx b/src/settings/components/form/SearchForm.tsx index 0aaf6fd..5dc786b 100644 --- a/src/settings/components/form/SearchForm.tsx +++ b/src/settings/components/form/SearchForm.tsx @@ -18,7 +18,7 @@ class SearchForm extends React.Component<Props> { }; render() { - let value = this.props.value.toJSON(); + const value = this.props.value.toJSON(); return <div className='form-search-form'> <div className='form-search-form-header'> <div className='column-name'>Name</div> @@ -56,10 +56,10 @@ class SearchForm extends React.Component<Props> { // eslint-disable-next-line max-statements bindValue(e: any) { - let value = this.props.value.toJSON(); - let name = e.target.name; - let index = Number(e.target.getAttribute('data-index')); - let next: typeof value = { + const value = this.props.value.toJSON(); + const name = e.target.name; + const index = Number(e.target.getAttribute('data-index')); + const next: typeof value = { default: value.default, engines: value.engines.slice(), }; @@ -76,7 +76,7 @@ class SearchForm extends React.Component<Props> { } else if (name === 'delete' && value.engines.length > 1) { next.engines.splice(index, 1); if (value.engines[index][0] === value.default) { - let nextIndex = Math.min(index, next.engines.length - 1); + const nextIndex = Math.min(index, next.engines.length - 1); next.default = next.engines[nextIndex][0]; } } diff --git a/src/settings/components/index.tsx b/src/settings/components/index.tsx index 3eb2dbe..f4f0326 100644 --- a/src/settings/components/index.tsx +++ b/src/settings/components/index.tsx @@ -96,7 +96,7 @@ class SettingsComponent extends React.Component<Props> { render() { let fields = null; - let disabled = this.props.error.length > 0; + const disabled = this.props.error.length > 0; if (this.props.source === 'form') { fields = this.renderFormFields(this.props.form!!); } else if (this.props.source === 'json') { @@ -131,7 +131,7 @@ class SettingsComponent extends React.Component<Props> { } bindKeymapsForm(value: FormKeymaps) { - let data = new SettingData({ + const data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithKeymaps(value), }); @@ -139,7 +139,7 @@ class SettingsComponent extends React.Component<Props> { } bindSearchForm(value: any) { - let data = new SettingData({ + const data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithSearch( FormSearch.fromJSON(value)), @@ -148,7 +148,7 @@ class SettingsComponent extends React.Component<Props> { } bindBlacklistForm(blacklist: Blacklist) { - let data = new SettingData({ + const data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithBlacklist(blacklist), }); @@ -156,7 +156,7 @@ class SettingsComponent extends React.Component<Props> { } bindPropertiesForm(value: any) { - let data = new SettingData({ + const data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithProperties( Properties.fromJSON(value)) @@ -165,7 +165,7 @@ class SettingsComponent extends React.Component<Props> { } bindJson(_name: string, value: string) { - let data = new SettingData({ + const data = new SettingData({ source: this.props.source, json: JSONTextSettings.fromText(value), }); @@ -173,13 +173,13 @@ class SettingsComponent extends React.Component<Props> { } bindSource(_name: string, value: string) { - let from = this.props.source; + const from = this.props.source; if (from === 'form' && value === 'json') { this.props.dispatch(settingActions.switchToJson( this.props.form as FormSettings)); this.save(); } else if (from === 'json' && value === 'form') { - let b = window.confirm(DO_YOU_WANT_TO_CONTINUE); + const b = window.confirm(DO_YOU_WANT_TO_CONTINUE); if (!b) { this.forceUpdate(); return; @@ -191,7 +191,7 @@ class SettingsComponent extends React.Component<Props> { } save() { - let { source, json, form } = this.props.store.getState(); + const { source, json, form } = this.props.store.getState(); this.props.dispatch(settingActions.save( new SettingData({ source, json, form }), )); diff --git a/src/settings/components/ui/Input.tsx b/src/settings/components/ui/Input.tsx index b7593b9..69c14b3 100644 --- a/src/settings/components/ui/Input.tsx +++ b/src/settings/components/ui/Input.tsx @@ -13,8 +13,8 @@ interface Props extends React.AllHTMLAttributes<HTMLElement> { class Input extends React.Component<Props> { renderText(props: Props) { - let inputClassName = props.error ? 'input-error' : ''; - let pp = { ...props }; + const inputClassName = props.error ? 'input-error' : ''; + const pp = { ...props }; delete pp.onValueChange; return <div className='settings-ui-input'> <label htmlFor={props.id}>{ props.label }</label> @@ -26,8 +26,8 @@ class Input extends React.Component<Props> { } renderRadio(props: Props) { - let inputClassName = props.error ? 'input-error' : ''; - let pp = { ...props }; + const inputClassName = props.error ? 'input-error' : ''; + const pp = { ...props }; delete pp.onValueChange; return <div className='settings-ui-input'> <label> @@ -41,8 +41,8 @@ class Input extends React.Component<Props> { } renderTextArea(props: Props) { - let inputClassName = props.error ? 'input-error' : ''; - let pp = { ...props }; + const inputClassName = props.error ? 'input-error' : ''; + const pp = { ...props }; delete pp.onValueChange; return <div className='settings-ui-input'> <label @@ -57,7 +57,7 @@ class Input extends React.Component<Props> { } render() { - let { type } = this.props; + const { type } = this.props; switch (this.props.type) { case 'text': diff --git a/src/settings/index.tsx b/src/settings/index.tsx index 6aec7a0..cde4488 100644 --- a/src/settings/index.tsx +++ b/src/settings/index.tsx @@ -12,7 +12,7 @@ const store = createStore( ); document.addEventListener('DOMContentLoaded', () => { - let wrapper = document.getElementById('vimvixen-settings'); + const wrapper = document.getElementById('vimvixen-settings'); ReactDOM.render( <Provider store={store}> <SettingsComponent store={store} /> diff --git a/src/settings/storage.ts b/src/settings/storage.ts index 2a983df..f375e58 100644 --- a/src/settings/storage.ts +++ b/src/settings/storage.ts @@ -1,7 +1,7 @@ import SettingData, { DefaultSettingData } from '../shared/SettingData'; export const load = async(): Promise<SettingData> => { - let { settings } = await browser.storage.local.get('settings'); + const { settings } = await browser.storage.local.get('settings'); if (!settings) { return DefaultSettingData; } diff --git a/src/shared/SettingData.ts b/src/shared/SettingData.ts index 532570e..5ad360e 100644 --- a/src/shared/SettingData.ts +++ b/src/shared/SettingData.ts @@ -13,14 +13,14 @@ export class FormKeymaps { } toKeymaps(): Keymaps { - let keymaps: { [key: string]: operations.Operation } = {}; - for (let name of Object.keys(this.data)) { - let [type, argStr] = name.split('?'); + const keymaps: { [key: string]: operations.Operation } = {}; + for (const name of Object.keys(this.data)) { + const [type, argStr] = name.split('?'); let args = {}; if (argStr) { args = JSON.parse(argStr); } - let key = this.data[name]; + const key = this.data[name]; keymaps[key] = operations.valueOf({ type, ...args }); } return Keymaps.fromJSON(keymaps); @@ -31,7 +31,7 @@ export class FormKeymaps { } buildWithOverride(op: string, keys: string): FormKeymaps { - let newData = { + const newData = { ...this.data, [op]: keys, }; @@ -39,19 +39,19 @@ export class FormKeymaps { } static fromJSON(o: ReturnType<FormKeymaps['toJSON']>): FormKeymaps { - let data: {[op: string]: string} = {}; - for (let op of Object.keys(o)) { + const data: {[op: string]: string} = {}; + for (const op of Object.keys(o)) { data[op] = o[op] as string; } return new FormKeymaps(data); } static fromKeymaps(keymaps: Keymaps): FormKeymaps { - let json = keymaps.toJSON(); - let data: {[op: string]: string} = {}; - for (let key of Object.keys(json)) { - let op = json[key]; - let args = { ...op }; + const json = keymaps.toJSON(); + const data: {[op: string]: string} = {}; + for (const key of Object.keys(json)) { + const op = json[key]; + const args = { ...op }; delete args.type; let name = op.type; @@ -75,8 +75,8 @@ export class FormSearch { } toSearchSettings(): Search { - let engines: { [name: string]: string } = {}; - for (let entry of this.engines) { + const engines: { [name: string]: string } = {}; + for (const entry of this.engines) { engines[entry[0]] = entry[1]; } return new Search(this.default, engines); @@ -103,7 +103,7 @@ export class FormSearch { } static fromSearch(search: Search): FormSearch { - let engines = Object.entries(search.engines).reduce( + const engines = Object.entries(search.engines).reduce( (o: string[][], [name, url]) => { return o.concat([[name, url]]); }, []); @@ -130,7 +130,7 @@ export class JSONTextSettings { } static fromSettings(data: Settings): JSONTextSettings { - let json = { + const json = { keymaps: data.keymaps.toJSON(), search: data.search, properties: data.properties, @@ -221,7 +221,7 @@ export class FormSettings { } static fromJSON(o: ReturnType<FormSettings['toJSON']>): FormSettings { - for (let name of ['keymaps', 'search', 'properties', 'blacklist']) { + for (const name of ['keymaps', 'search', 'properties', 'blacklist']) { if (!Object.prototype.hasOwnProperty.call(o, name)) { throw new Error(`"${name}" field not set`); } diff --git a/src/shared/operations.ts b/src/shared/operations.ts index 67c5ca8..beca7b9 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -376,7 +376,7 @@ const assertOptionalBoolean = (obj: any, name: string) => { const assertOptionalString = (obj: any, name: string, values?: string[]) => { if (Object.prototype.hasOwnProperty.call(obj, name)) { - let value = obj[name]; + const value = obj[name]; if (typeof value !== 'string') { throw new TypeError( `Not a string parameter: '${name}' (${typeof value})`, diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts index 1903a78..6e6b51c 100644 --- a/src/shared/settings/Blacklist.ts +++ b/src/shared/settings/Blacklist.ts @@ -8,7 +8,7 @@ export type BlacklistItemJSON = string | { export type BlacklistJSON = BlacklistItemJSON[]; const regexFromWildcard = (pattern: string): RegExp => { - let regexStr = '^' + pattern.replace(/\*/g, '.*') + '$'; + const regexStr = '^' + pattern.replace(/\*/g, '.*') + '$'; return new RegExp(regexStr); }; @@ -72,7 +72,7 @@ export default class Blacklist { } static fromJSON(json: BlacklistJSON): Blacklist { - let items = json.map(o => BlacklistItem.fromJSON(o)); + const items = json.map(o => BlacklistItem.fromJSON(o)); return new Blacklist(items); } diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts index 3a3eb3b..cfe1e7e 100644 --- a/src/shared/settings/Key.ts +++ b/src/shared/settings/Key.ts @@ -33,8 +33,8 @@ export default class Key { static fromMapKey(str: string): Key { if (str.startsWith('<') && str.endsWith('>')) { - let inner = str.slice(1, -1); - let shift = inner.includes('S-'); + const inner = str.slice(1, -1); + const shift = inner.includes('S-'); let base = inner.slice(inner.lastIndexOf('-') + 1); if (shift && base.length === 1) { base = base.toUpperCase(); diff --git a/src/shared/settings/Keymaps.ts b/src/shared/settings/Keymaps.ts index 5870313..3880654 100644 --- a/src/shared/settings/Keymaps.ts +++ b/src/shared/settings/Keymaps.ts @@ -15,8 +15,8 @@ export default class Keymaps { } static fromJSON(json: KeymapsJSON): Keymaps { - let entries: { [key: string]: operations.Operation } = {}; - for (let key of Object.keys(json)) { + const entries: { [key: string]: operations.Operation } = {}; + for (const key of Object.keys(json)) { entries[key] = operations.valueOf(json[key]); } return new Keymaps(entries); diff --git a/src/shared/settings/Search.ts b/src/shared/settings/Search.ts index 7d7e555..7de03de 100644 --- a/src/shared/settings/Search.ts +++ b/src/shared/settings/Search.ts @@ -13,11 +13,11 @@ export default class Search { } static fromJSON(json: SearchJSON): Search { - for (let [name, url] of Object.entries(json.engines)) { + for (const [name, url] of Object.entries(json.engines)) { if (!(/^[a-zA-Z0-9]+$/).test(name)) { throw new TypeError('Search engine\'s name must be [a-zA-Z0-9]+'); } - let matches = url.match(/{}/g); + const matches = url.match(/{}/g); if (matches === null) { throw new TypeError(`No {}-placeholders in URL of "${name}"`); } else if (matches.length > 1) { diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts index 97dda7f..add5389 100644 --- a/src/shared/settings/Settings.ts +++ b/src/shared/settings/Settings.ts @@ -40,9 +40,9 @@ export default class Settings { } static fromJSON(json: unknown): Settings { - let valid = validate(json); + const valid = validate(json); if (!valid) { - let message = (validate as any).errors!! + const message = (validate as any).errors!! .map((err: Ajv.ErrorObject) => { return `'${err.dataPath}' ${err.message}`; }) @@ -50,8 +50,8 @@ export default class Settings { throw new TypeError(message); } - let obj = json as SettingsJSON; - let settings = { ...DefaultSetting }; + const obj = json as SettingsJSON; + const settings = { ...DefaultSetting }; if (obj.keymaps) { settings.keymaps = Keymaps.fromJSON(obj.keymaps); } diff --git a/src/shared/urls.ts b/src/shared/urls.ts index 9c76b97..bac929e 100644 --- a/src/shared/urls.ts +++ b/src/shared/urls.ts @@ -12,7 +12,7 @@ const isLocalhost = (url: string): boolean => { return true; } - let [host, port] = url.split(':', 2); + const [host, port] = url.split(':', 2); return host === 'localhost' && !isNaN(Number(port)); }; @@ -22,7 +22,7 @@ const isMissingHttp = (keywords: string): boolean => { } try { - let u = new URL('http://' + keywords); + const u = new URL('http://' + keywords); return isLocalhost(u.host); } catch (e) { // fallthrough @@ -32,7 +32,7 @@ const isMissingHttp = (keywords: string): boolean => { const searchUrl = (keywords: string, search: Search): string => { try { - let u = new URL(keywords); + const u = new URL(keywords); if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { return u.href; } @@ -47,7 +47,7 @@ const searchUrl = (keywords: string, search: Search): string => { let template = search.engines[search.defaultEngine]; let query = keywords; - let first = trimStart(keywords).split(' ')[0]; + const first = trimStart(keywords).split(' ')[0]; if (Object.keys(search.engines).includes(first)) { template = search.engines[first]; query = trimStart(trimStart(keywords).slice(first.length)); @@ -57,7 +57,7 @@ const searchUrl = (keywords: string, search: Search): string => { const normalizeUrl = (url: string): string => { try { - let u = new URL(url); + const u = new URL(url); if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { return u.href; } diff --git a/src/shared/utils/dom.ts b/src/shared/utils/dom.ts index c1f2190..a6186cb 100644 --- a/src/shared/utils/dom.ts +++ b/src/shared/utils/dom.ts @@ -1,5 +1,5 @@ const isContentEditable = (element: Element): boolean => { - let value = element.getAttribute('contenteditable'); + const value = element.getAttribute('contenteditable'); if (value === null) { return false; } @@ -14,12 +14,12 @@ interface Rect { } const rectangleCoordsRect = (coords: string): Rect => { - let [left, top, right, bottom] = coords.split(',').map(n => Number(n)); + const [left, top, right, bottom] = coords.split(',').map(n => Number(n)); return { left, top, right, bottom }; }; const circleCoordsRect = (coords: string): Rect => { - let [x, y, r] = coords.split(',').map(n => Number(n)); + const [x, y, r] = coords.split(',').map(n => Number(n)); return { left: x - r, top: y - r, @@ -29,14 +29,14 @@ const circleCoordsRect = (coords: string): Rect => { }; const polygonCoordsRect = (coords: string): Rect => { - let params = coords.split(','); + const params = coords.split(','); let minx = Number(params[0]), maxx = Number(params[0]), miny = Number(params[1]), maxy = Number(params[1]); - let len = Math.floor(params.length / 2); + const len = Math.floor(params.length / 2); for (let i = 2; i < len; i += 2) { - let x = Number(params[i]), + const x = Number(params[i]), y = Number(params[i + 1]); if (x < minx) { minx = x; @@ -59,15 +59,15 @@ const viewportRect = (e: Element): Rect => { return e.getBoundingClientRect(); } - let mapElement = e.parentNode as HTMLMapElement; - let imgElement = document.querySelector( + const mapElement = e.parentNode as HTMLMapElement; + const imgElement = document.querySelector( `img[usemap="#${mapElement.name}"]` ) as HTMLImageElement; - let { + const { left: mapLeft, top: mapTop } = imgElement.getBoundingClientRect(); - let coords = e.getAttribute('coords'); + const coords = e.getAttribute('coords'); if (!coords) { return e.getBoundingClientRect(); } @@ -96,8 +96,8 @@ const viewportRect = (e: Element): Rect => { }; const isVisible = (element: Element): boolean => { - let rect = element.getBoundingClientRect(); - let style = window.getComputedStyle(element); + const rect = element.getBoundingClientRect(); + const style = window.getComputedStyle(element); if (style.overflow !== 'visible' && (rect.width === 0 || rect.height === 0)) { return false; @@ -113,7 +113,7 @@ const isVisible = (element: Element): boolean => { return false; } - let { display, visibility } = window.getComputedStyle(element); + const { display, visibility } = window.getComputedStyle(element); if (display === 'none' || visibility === 'hidden') { return false; } |