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/background | |
parent | 0881f92d20cb7b4f5a75671df739c3eaa3cd0ff0 (diff) |
npm run lint:fix
Diffstat (limited to 'src/background')
29 files changed, 171 insertions, 171 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); } |