diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-05-02 17:25:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-02 17:25:56 +0900 |
commit | 5df0537bcf65a341e79852b1b30379c73318529c (patch) | |
tree | aee5efe52412855f620cb514a13a2c14373f27b7 /src/content | |
parent | 685f2b7b69218b06b5bb676069e35f79c5048c9b (diff) | |
parent | 75abd90ecb8201ad845b266f96220d8adfe19b2d (diff) |
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'src/content')
60 files changed, 641 insertions, 635 deletions
diff --git a/src/content/Application.ts b/src/content/Application.ts index fbfeb6d..996bbbc 100644 --- a/src/content/Application.ts +++ b/src/content/Application.ts @@ -1,25 +1,24 @@ -import { injectable } from 'tsyringe'; -import MessageListener from './MessageListener'; -import FindController from './controllers/FindController'; -import MarkController from './controllers/MarkController'; -import FollowMasterController from './controllers/FollowMasterController'; -import FollowSlaveController from './controllers/FollowSlaveController'; -import FollowKeyController from './controllers/FollowKeyController'; -import InputDriver from './InputDriver'; -import KeymapController from './controllers/KeymapController'; -import AddonEnabledUseCase from './usecases/AddonEnabledUseCase'; -import MarkKeyController from './controllers/MarkKeyController'; -import AddonEnabledController from './controllers/AddonEnabledController'; -import SettingController from './controllers/SettingController'; -import ConsoleFrameController from './controllers/ConsoleFrameController'; -import NavigateController from './controllers/NavigateController'; -import * as messages from '../shared/messages'; +import { injectable } from "tsyringe"; +import MessageListener from "./MessageListener"; +import FindController from "./controllers/FindController"; +import MarkController from "./controllers/MarkController"; +import FollowMasterController from "./controllers/FollowMasterController"; +import FollowSlaveController from "./controllers/FollowSlaveController"; +import FollowKeyController from "./controllers/FollowKeyController"; +import InputDriver from "./InputDriver"; +import KeymapController from "./controllers/KeymapController"; +import AddonEnabledUseCase from "./usecases/AddonEnabledUseCase"; +import MarkKeyController from "./controllers/MarkKeyController"; +import AddonEnabledController from "./controllers/AddonEnabledController"; +import SettingController from "./controllers/SettingController"; +import ConsoleFrameController from "./controllers/ConsoleFrameController"; +import NavigateController from "./controllers/NavigateController"; +import * as messages from "../shared/messages"; type Message = messages.Message; @injectable() export default class Application { - // eslint-disable-next-line max-params constructor( private messageListener: MessageListener, @@ -34,9 +33,8 @@ export default class Application { private addonEnabledController: AddonEnabledController, private settingController: SettingController, private consoleFrameController: ConsoleFrameController, - private navigateController: NavigateController, - ) { - } + private navigateController: NavigateController + ) {} run() { this.routeCommonComponents(); @@ -49,30 +47,30 @@ export default class Application { private routeMasterComponents() { this.messageListener.onWebMessage((msg: Message, sender: Window) => { switch (msg.type) { - case messages.CONSOLE_ENTER_FIND: - return this.findController.start(msg); - case messages.FIND_NEXT: - return this.findController.next(msg); - case messages.FIND_PREV: - return this.findController.prev(msg); - case messages.CONSOLE_UNFOCUS: - return this.consoleFrameController.unfocus(msg); - case messages.FOLLOW_START: - return this.followMasterController.followStart(msg); - case messages.FOLLOW_RESPONSE_COUNT_TARGETS: - return this.followMasterController.responseCountTargets(msg, sender); - case messages.FOLLOW_KEY_PRESS: - return this.followMasterController.keyPress(msg); + case messages.CONSOLE_ENTER_FIND: + return this.findController.start(msg); + case messages.FIND_NEXT: + return this.findController.next(msg); + case messages.FIND_PREV: + return this.findController.prev(msg); + case messages.CONSOLE_UNFOCUS: + return this.consoleFrameController.unfocus(msg); + case messages.FOLLOW_START: + return this.followMasterController.followStart(msg); + case messages.FOLLOW_RESPONSE_COUNT_TARGETS: + return this.followMasterController.responseCountTargets(msg, sender); + case messages.FOLLOW_KEY_PRESS: + return this.followMasterController.keyPress(msg); } return undefined; }); this.messageListener.onBackgroundMessage((msg: Message) => { switch (msg.type) { - case messages.ADDON_ENABLED_QUERY: - return this.addonEnabledController.getAddonEnabled(msg); - case messages.TAB_SCROLL_TO: - return this.markController.scrollTo(msg); + case messages.ADDON_ENABLED_QUERY: + return this.addonEnabledController.getAddonEnabled(msg); + case messages.TAB_SCROLL_TO: + return this.markController.scrollTo(msg); } return undefined; }); @@ -81,47 +79,47 @@ export default class Application { private routeCommonComponents() { this.messageListener.onWebMessage((msg: Message) => { switch (msg.type) { - case messages.FOLLOW_REQUEST_COUNT_TARGETS: - return this.followSlaveController.countTargets(msg); - case messages.FOLLOW_CREATE_HINTS: - return this.followSlaveController.createHints(msg); - case messages.FOLLOW_SHOW_HINTS: - return this.followSlaveController.showHints(msg); - case messages.FOLLOW_ACTIVATE: - return this.followSlaveController.activate(msg); - case messages.FOLLOW_REMOVE_HINTS: - return this.followSlaveController.clear(msg); + case messages.FOLLOW_REQUEST_COUNT_TARGETS: + return this.followSlaveController.countTargets(msg); + case messages.FOLLOW_CREATE_HINTS: + return this.followSlaveController.createHints(msg); + case messages.FOLLOW_SHOW_HINTS: + return this.followSlaveController.showHints(msg); + case messages.FOLLOW_ACTIVATE: + return this.followSlaveController.activate(msg); + case messages.FOLLOW_REMOVE_HINTS: + return this.followSlaveController.clear(msg); } return undefined; }); this.messageListener.onBackgroundMessage((msg: Message): any => { switch (msg.type) { - case messages.SETTINGS_CHANGED: - return this.settingController.reloadSettings(msg); - case messages.ADDON_TOGGLE_ENABLED: - return this.addonEnabledUseCase.toggle(); - case messages.NAVIGATE_HISTORY_NEXT: - return this.navigateController.openHistoryNext(msg); - case messages.NAVIGATE_HISTORY_PREV: - return this.navigateController.openHistoryPrev(msg); - case messages.NAVIGATE_LINK_NEXT: - return this.navigateController.openLinkNext(msg); - case messages.NAVIGATE_LINK_PREV: - return this.navigateController.openLinkPrev(msg); + case messages.SETTINGS_CHANGED: + return this.settingController.reloadSettings(msg); + case messages.ADDON_TOGGLE_ENABLED: + return this.addonEnabledUseCase.toggle(); + case messages.NAVIGATE_HISTORY_NEXT: + return this.navigateController.openHistoryNext(msg); + case messages.NAVIGATE_HISTORY_PREV: + return this.navigateController.openHistoryPrev(msg); + case messages.NAVIGATE_LINK_NEXT: + return this.navigateController.openLinkNext(msg); + case messages.NAVIGATE_LINK_PREV: + return this.navigateController.openLinkPrev(msg); } }); 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)); + inputDriver.onKey((key) => this.followKeyController.press(key)); + inputDriver.onKey((key) => this.markKeyController.press(key)); + inputDriver.onKey((key) => this.keymapController.press(key)); this.settingController.initSettings(); } private routeFocusEvents() { - window.addEventListener('blur', () => { + window.addEventListener("blur", () => { this.keymapController.onBlurWindow(); }); } diff --git a/src/content/InputDriver.ts b/src/content/InputDriver.ts index cf28205..76c1fc9 100644 --- a/src/content/InputDriver.ts +++ b/src/content/InputDriver.ts @@ -1,24 +1,24 @@ -import * as dom from '../shared/utils/dom'; -import Key from '../shared/settings/Key'; +import * as dom from "../shared/utils/dom"; +import Key from "../shared/settings/Key"; const cancelKey = (e: KeyboardEvent): boolean => { - if (e.key === 'Escape') { + if (e.key === "Escape") { return true; } - if (e.key === '[' && e.ctrlKey) { + if (e.key === "[" && e.ctrlKey) { return true; } return false; }; const modifiedKeyName = (name: string): string => { - if (name === ' ') { - return 'Space'; + if (name === " ") { + return "Space"; } if (name.length === 1) { return name; - } else if (name === 'Escape') { - return 'Esc'; + } else if (name === "Escape") { + return "Esc"; } return name; }; @@ -44,7 +44,7 @@ export const keyFromKeyboardEvent = (e: KeyboardEvent): Key => { }; export default class InputDriver { - private pressed: {[key: string]: string} = {}; + private pressed: { [key: string]: string } = {}; private onKeyListeners: ((key: Key) => boolean)[] = []; @@ -52,9 +52,9 @@ export default class InputDriver { this.pressed = {}; this.onKeyListeners = []; - target.addEventListener('keypress', this.onKeyPress.bind(this)); - target.addEventListener('keydown', this.onKeyDown.bind(this)); - target.addEventListener('keyup', this.onKeyUp.bind(this)); + target.addEventListener("keypress", this.onKeyPress.bind(this)); + target.addEventListener("keydown", this.onKeyDown.bind(this)); + target.addEventListener("keyup", this.onKeyUp.bind(this)); } onKey(cb: (key: Key) => boolean) { @@ -62,18 +62,18 @@ export default class InputDriver { } private onKeyPress(e: KeyboardEvent) { - if (this.pressed[e.key] && this.pressed[e.key] !== 'keypress') { + if (this.pressed[e.key] && this.pressed[e.key] !== "keypress") { return; } - this.pressed[e.key] = 'keypress'; + this.pressed[e.key] = "keypress"; this.capture(e); } private onKeyDown(e: KeyboardEvent) { - if (this.pressed[e.key] && this.pressed[e.key] !== 'keydown') { + if (this.pressed[e.key] && this.pressed[e.key] !== "keydown") { return; } - this.pressed[e.key] = 'keydown'; + this.pressed[e.key] = "keydown"; this.capture(e); } @@ -93,7 +93,7 @@ export default class InputDriver { } return; } - if (['Shift', 'Control', 'Alt', 'OS'].includes(e.key)) { + if (["Shift", "Control", "Alt", "OS"].includes(e.key)) { // pressing only meta key is ignored return; } @@ -110,9 +110,11 @@ export default class InputDriver { } private fromInput(e: Element) { - return e instanceof HTMLInputElement || + return ( + e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement || - dom.isContentEditable(e); + dom.isContentEditable(e) + ); } } diff --git a/src/content/MessageListener.ts b/src/content/MessageListener.ts index e1f7c75..3fe1dcd 100644 --- a/src/content/MessageListener.ts +++ b/src/content/MessageListener.ts @@ -1,14 +1,12 @@ -import { injectable } from 'tsyringe'; -import { Message, valueOf } from '../shared/messages'; +import { injectable } from "tsyringe"; +import { Message, valueOf } from "../shared/messages"; export type WebExtMessageSender = browser.runtime.MessageSender; @injectable() export default class MessageListener { - onWebMessage( - listener: (msg: Message, sender: Window) => void, - ) { - window.addEventListener('message', (event: MessageEvent) => { + onWebMessage(listener: (msg: Message, sender: Window) => void) { + window.addEventListener("message", (event: MessageEvent) => { const sender = event.source; if (!(sender instanceof Window)) { return; @@ -25,12 +23,12 @@ export default class MessageListener { } onBackgroundMessage( - listener: (msg: Message, sender: WebExtMessageSender) => any, + listener: (msg: Message, sender: WebExtMessageSender) => any ) { browser.runtime.onMessage.addListener( (msg: any, sender: WebExtMessageSender) => { return listener(valueOf(msg), sender); - }, + } ); } } diff --git a/src/content/client/AddonIndicatorClient.ts b/src/content/client/AddonIndicatorClient.ts index b5f7e6a..861ef40 100644 --- a/src/content/client/AddonIndicatorClient.ts +++ b/src/content/client/AddonIndicatorClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; export default interface AddonIndicatorClient { setEnabled(enabled: boolean): Promise<void>; diff --git a/src/content/client/ConsoleClient.ts b/src/content/client/ConsoleClient.ts index b4fbb04..0aac8d0 100644 --- a/src/content/client/ConsoleClient.ts +++ b/src/content/client/ConsoleClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; export default interface ConsoleClient { info(text: string): Promise<void>; diff --git a/src/content/client/FindClient.ts b/src/content/client/FindClient.ts index 8b2aca4..7da5069 100644 --- a/src/content/client/FindClient.ts +++ b/src/content/client/FindClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; export default interface FindClient { getGlobalLastKeyword(): Promise<string | null>; diff --git a/src/content/client/FindMasterClient.ts b/src/content/client/FindMasterClient.ts index 9ed38dd..9c3f812 100644 --- a/src/content/client/FindMasterClient.ts +++ b/src/content/client/FindMasterClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; export default interface FindMasterClient { findNext(): void; @@ -8,14 +8,20 @@ export default interface FindMasterClient { export class FindMasterClientImpl implements FindMasterClient { findNext(): void { - window.top.postMessage(JSON.stringify({ - type: messages.FIND_NEXT, - }), '*'); + window.top.postMessage( + JSON.stringify({ + type: messages.FIND_NEXT, + }), + "*" + ); } findPrev(): void { - window.top.postMessage(JSON.stringify({ - type: messages.FIND_PREV, - }), '*'); + window.top.postMessage( + JSON.stringify({ + type: messages.FIND_PREV, + }), + "*" + ); } } diff --git a/src/content/client/FollowMasterClient.ts b/src/content/client/FollowMasterClient.ts index 6681e8a..f068683 100644 --- a/src/content/client/FollowMasterClient.ts +++ b/src/content/client/FollowMasterClient.ts @@ -1,5 +1,5 @@ -import * as messages from '../../shared/messages'; -import Key from '../../shared/settings/Key'; +import * as messages from "../../shared/messages"; +import Key from "../../shared/settings/Key"; export default interface FollowMasterClient { startFollow(newTab: boolean, background: boolean): void; @@ -40,6 +40,6 @@ export class FollowMasterClientImpl implements FollowMasterClient { } private postMessage(msg: messages.Message): void { - this.window.postMessage(JSON.stringify(msg), '*'); + this.window.postMessage(JSON.stringify(msg), "*"); } } diff --git a/src/content/client/FollowSlaveClient.ts b/src/content/client/FollowSlaveClient.ts index 4360200..eb9651a 100644 --- a/src/content/client/FollowSlaveClient.ts +++ b/src/content/client/FollowSlaveClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; interface Size { width: number; @@ -69,6 +69,6 @@ export class FollowSlaveClientImpl implements FollowSlaveClient { } private postMessage(msg: messages.Message): void { - this.target.postMessage(JSON.stringify(msg), '*'); + this.target.postMessage(JSON.stringify(msg), "*"); } } diff --git a/src/content/client/FollowSlaveClientFactory.ts b/src/content/client/FollowSlaveClientFactory.ts index 166dfca..beaa77a 100644 --- a/src/content/client/FollowSlaveClientFactory.ts +++ b/src/content/client/FollowSlaveClientFactory.ts @@ -1,4 +1,4 @@ -import FollowSlaveClient, { FollowSlaveClientImpl } from './FollowSlaveClient'; +import FollowSlaveClient, { FollowSlaveClientImpl } from "./FollowSlaveClient"; export default interface FollowSlaveClientFactory { create(window: Window): FollowSlaveClient; diff --git a/src/content/client/MarkClient.ts b/src/content/client/MarkClient.ts index c6295c0..d1f00ae 100644 --- a/src/content/client/MarkClient.ts +++ b/src/content/client/MarkClient.ts @@ -1,5 +1,5 @@ -import Mark from '../domains/Mark'; -import * as messages from '../../shared/messages'; +import Mark from "../domains/Mark"; +import * as messages from "../../shared/messages"; export default interface MarkClient { setGloablMark(key: string, mark: Mark): Promise<void>; diff --git a/src/content/client/OperationClient.ts b/src/content/client/OperationClient.ts index 9c72c75..2bc7aee 100644 --- a/src/content/client/OperationClient.ts +++ b/src/content/client/OperationClient.ts @@ -1,11 +1,13 @@ -import * as operations from '../../shared/operations'; -import * as messages from '../../shared/messages'; +import * as operations from "../../shared/operations"; +import * as messages from "../../shared/messages"; export default interface OperationClient { execBackgroundOp(repeat: number, op: operations.Operation): Promise<void>; internalOpenUrl( - url: string, newTab?: boolean, background?: boolean, + url: string, + newTab?: boolean, + background?: boolean ): Promise<void>; } @@ -19,7 +21,9 @@ export class OperationClientImpl implements OperationClient { } internalOpenUrl( - url: string, newTab?: boolean, background?: boolean, + url: string, + newTab?: boolean, + background?: boolean ): Promise<void> { return browser.runtime.sendMessage({ type: messages.BACKGROUND_OPERATION, diff --git a/src/content/client/SettingClient.ts b/src/content/client/SettingClient.ts index f89f3cd..11d7075 100644 --- a/src/content/client/SettingClient.ts +++ b/src/content/client/SettingClient.ts @@ -1,5 +1,5 @@ -import Settings from '../../shared/settings/Settings'; -import * as messages from '../../shared/messages'; +import Settings from "../../shared/settings/Settings"; +import * as messages from "../../shared/messages"; export default interface SettingClient { load(): Promise<Settings>; diff --git a/src/content/client/TabsClient.ts b/src/content/client/TabsClient.ts index 39348df..9169a3d 100644 --- a/src/content/client/TabsClient.ts +++ b/src/content/client/TabsClient.ts @@ -1,4 +1,4 @@ -import * as messages from '../../shared/messages'; +import * as messages from "../../shared/messages"; export default interface TabsClient { openUrl(url: string, newTab: boolean, background?: boolean): Promise<void>; @@ -8,7 +8,7 @@ export class TabsClientImpl implements TabsClient { async openUrl( url: string, newTab: boolean, - background?: boolean, + background?: boolean ): Promise<void> { await browser.runtime.sendMessage({ type: messages.OPEN_URL, diff --git a/src/content/controllers/AddonEnabledController.ts b/src/content/controllers/AddonEnabledController.ts index 59b45fa..9ef56a9 100644 --- a/src/content/controllers/AddonEnabledController.ts +++ b/src/content/controllers/AddonEnabledController.ts @@ -1,16 +1,13 @@ -import { injectable } from 'tsyringe'; -import * as messages from '../../shared/messages'; -import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; +import { injectable } from "tsyringe"; +import * as messages from "../../shared/messages"; +import AddonEnabledUseCase from "../usecases/AddonEnabledUseCase"; @injectable() export default class AddonEnabledController { - constructor( - private addonEnabledUseCase: AddonEnabledUseCase, - ) { - } + constructor(private addonEnabledUseCase: AddonEnabledUseCase) {} getAddonEnabled( - _message: messages.AddonEnabledQueryMessage, + _message: messages.AddonEnabledQueryMessage ): Promise<boolean> { const enabled = this.addonEnabledUseCase.getEnabled(); return Promise.resolve(enabled); diff --git a/src/content/controllers/ConsoleFrameController.ts b/src/content/controllers/ConsoleFrameController.ts index ae26b7c..84e0ce6 100644 --- a/src/content/controllers/ConsoleFrameController.ts +++ b/src/content/controllers/ConsoleFrameController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import ConsoleFrameUseCase from '../usecases/ConsoleFrameUseCase'; -import * as messages from '../../shared/messages'; +import { injectable } from "tsyringe"; +import ConsoleFrameUseCase from "../usecases/ConsoleFrameUseCase"; +import * as messages from "../../shared/messages"; @injectable() export default class ConsoleFrameController { - constructor( - private consoleFrameUseCase: ConsoleFrameUseCase, - ) { - } + constructor(private consoleFrameUseCase: ConsoleFrameUseCase) {} unfocus(_message: messages.Message) { this.consoleFrameUseCase.unfocus(); diff --git a/src/content/controllers/FindController.ts b/src/content/controllers/FindController.ts index 7735176..3087d5d 100644 --- a/src/content/controllers/FindController.ts +++ b/src/content/controllers/FindController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import * as messages from '../../shared/messages'; -import FindUseCase from '../usecases/FindUseCase'; +import { injectable } from "tsyringe"; +import * as messages from "../../shared/messages"; +import FindUseCase from "../usecases/FindUseCase"; @injectable() export default class FindController { - constructor( - private findUseCase: FindUseCase, - ) { - } + constructor(private findUseCase: FindUseCase) {} async start(m: messages.ConsoleEnterFindMessage): Promise<void> { await this.findUseCase.startFind(m.text); diff --git a/src/content/controllers/FollowKeyController.ts b/src/content/controllers/FollowKeyController.ts index 0fd94ff..45d202a 100644 --- a/src/content/controllers/FollowKeyController.ts +++ b/src/content/controllers/FollowKeyController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase'; -import Key from '../../shared/settings/Key'; +import { injectable } from "tsyringe"; +import FollowSlaveUseCase from "../usecases/FollowSlaveUseCase"; +import Key from "../../shared/settings/Key"; @injectable() export default class FollowKeyController { - constructor( - private followSlaveUseCase: FollowSlaveUseCase, - ) { - } + constructor(private followSlaveUseCase: FollowSlaveUseCase) {} press(key: Key): boolean { if (!this.followSlaveUseCase.isFollowMode()) { diff --git a/src/content/controllers/FollowMasterController.ts b/src/content/controllers/FollowMasterController.ts index fa99820..e7895fa 100644 --- a/src/content/controllers/FollowMasterController.ts +++ b/src/content/controllers/FollowMasterController.ts @@ -1,30 +1,27 @@ -import { injectable } from 'tsyringe'; -import FollowMasterUseCase from '../usecases/FollowMasterUseCase'; -import * as messages from '../../shared/messages'; +import { injectable } from "tsyringe"; +import FollowMasterUseCase from "../usecases/FollowMasterUseCase"; +import * as messages from "../../shared/messages"; @injectable() export default class FollowMasterController { - constructor( - private followMasterUseCase: FollowMasterUseCase, - ) { - } + constructor(private followMasterUseCase: FollowMasterUseCase) {} followStart(m: messages.FollowStartMessage): void { this.followMasterUseCase.startFollow(m.newTab, m.background); } responseCountTargets( - m: messages.FollowResponseCountTargetsMessage, sender: Window, + m: messages.FollowResponseCountTargetsMessage, + sender: Window ): void { this.followMasterUseCase.createSlaveHints(m.count, sender); } keyPress(message: messages.FollowKeyPressMessage): void { - if (message.key === '[' && message.ctrlKey) { + if (message.key === "[" && message.ctrlKey) { this.followMasterUseCase.cancelFollow(); } else { this.followMasterUseCase.enqueue(message.key); } } } - diff --git a/src/content/controllers/FollowSlaveController.ts b/src/content/controllers/FollowSlaveController.ts index 65ce477..25f0505 100644 --- a/src/content/controllers/FollowSlaveController.ts +++ b/src/content/controllers/FollowSlaveController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import * as messages from '../../shared/messages'; -import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase'; +import { injectable } from "tsyringe"; +import * as messages from "../../shared/messages"; +import FollowSlaveUseCase from "../usecases/FollowSlaveUseCase"; @injectable() export default class FollowSlaveController { - constructor( - private usecase: FollowSlaveUseCase, - ) { - } + constructor(private usecase: FollowSlaveUseCase) {} countTargets(m: messages.FollowRequestCountTargetsMessage): void { this.usecase.countTargets(m.viewSize, m.framePosition); diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts index 639b4a1..092e55c 100644 --- a/src/content/controllers/KeymapController.ts +++ b/src/content/controllers/KeymapController.ts @@ -1,15 +1,15 @@ -import { injectable, inject } from 'tsyringe'; -import * as operations from '../../shared/operations'; -import KeymapUseCase from '../usecases/KeymapUseCase'; -import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; -import FindSlaveUseCase from '../usecases/FindSlaveUseCase'; -import ScrollUseCase from '../usecases/ScrollUseCase'; -import FocusUseCase from '../usecases/FocusUseCase'; -import ClipboardUseCase from '../usecases/ClipboardUseCase'; -import OperationClient from '../client/OperationClient'; -import MarkKeyyUseCase from '../usecases/MarkKeyUseCase'; -import FollowMasterClient from '../client/FollowMasterClient'; -import Key from '../../shared/settings/Key'; +import { injectable, inject } from "tsyringe"; +import * as operations from "../../shared/operations"; +import KeymapUseCase from "../usecases/KeymapUseCase"; +import AddonEnabledUseCase from "../usecases/AddonEnabledUseCase"; +import FindSlaveUseCase from "../usecases/FindSlaveUseCase"; +import ScrollUseCase from "../usecases/ScrollUseCase"; +import FocusUseCase from "../usecases/FocusUseCase"; +import ClipboardUseCase from "../usecases/ClipboardUseCase"; +import OperationClient from "../client/OperationClient"; +import MarkKeyyUseCase from "../usecases/MarkKeyUseCase"; +import FollowMasterClient from "../client/FollowMasterClient"; +import Key from "../../shared/settings/Key"; @injectable() export default class KeymapController { @@ -22,13 +22,12 @@ export default class KeymapController { private clipbaordUseCase: ClipboardUseCase, private markKeyUseCase: MarkKeyyUseCase, - @inject('OperationClient') + @inject("OperationClient") private operationClient: OperationClient, - @inject('FollowMasterClient') - private followMasterClient: FollowMasterClient, - ) { - } + @inject("FollowMasterClient") + private followMasterClient: FollowMasterClient + ) {} // eslint-disable-next-line complexity, max-lines-per-function press(key: Key): boolean { @@ -43,47 +42,46 @@ export default class KeymapController { const doFunc = ((op: operations.Operation) => { switch (op.type) { - case operations.ADDON_ENABLE: - return () => this.addonEnabledUseCase.enable(); - case operations.ADDON_DISABLE: - return () => this.addonEnabledUseCase.disable(); - case operations.ADDON_TOGGLE_ENABLED: - return () => this.addonEnabledUseCase.toggle(); - case operations.FIND_NEXT: - return () => this.findSlaveUseCase.findNext(); - case operations.FIND_PREV: - return () => this.findSlaveUseCase.findPrev(); - case operations.SCROLL_VERTICALLY: - return () => this.scrollUseCase.scrollVertically(op.count); - case operations.SCROLL_HORIZONALLY: - return () => this.scrollUseCase.scrollHorizonally(op.count); - case operations.SCROLL_PAGES: - return () => this.scrollUseCase.scrollPages(op.count); - case operations.SCROLL_TOP: - return () => this.scrollUseCase.scrollToTop(); - case operations.SCROLL_BOTTOM: - return () => this.scrollUseCase.scrollToBottom(); - case operations.SCROLL_HOME: - return () => this.scrollUseCase.scrollToHome(); - case operations.SCROLL_END: - return () => this.scrollUseCase.scrollToEnd(); - case operations.FOLLOW_START: - return () => this.followMasterClient.startFollow( - op.newTab, op.background); - case operations.MARK_SET_PREFIX: - return () => this.markKeyUseCase.enableSetMode(); - case operations.MARK_JUMP_PREFIX: - return () => this.markKeyUseCase.enableJumpMode(); - case operations.FOCUS_INPUT: - return () => this.focusUseCase.focusFirstInput(); - case operations.URLS_YANK: - return () => this.clipbaordUseCase.yankCurrentURL(); - case operations.URLS_PASTE: - return () => this.clipbaordUseCase.openOrSearch( - op.newTab ? op.newTab : false, - ); - default: - return null; + case operations.ADDON_ENABLE: + return () => this.addonEnabledUseCase.enable(); + case operations.ADDON_DISABLE: + return () => this.addonEnabledUseCase.disable(); + case operations.ADDON_TOGGLE_ENABLED: + return () => this.addonEnabledUseCase.toggle(); + case operations.FIND_NEXT: + return () => this.findSlaveUseCase.findNext(); + case operations.FIND_PREV: + return () => this.findSlaveUseCase.findPrev(); + case operations.SCROLL_VERTICALLY: + return () => this.scrollUseCase.scrollVertically(op.count); + case operations.SCROLL_HORIZONALLY: + return () => this.scrollUseCase.scrollHorizonally(op.count); + case operations.SCROLL_PAGES: + return () => this.scrollUseCase.scrollPages(op.count); + case operations.SCROLL_TOP: + return () => this.scrollUseCase.scrollToTop(); + case operations.SCROLL_BOTTOM: + return () => this.scrollUseCase.scrollToBottom(); + case operations.SCROLL_HOME: + return () => this.scrollUseCase.scrollToHome(); + case operations.SCROLL_END: + return () => this.scrollUseCase.scrollToEnd(); + case operations.FOLLOW_START: + return () => + this.followMasterClient.startFollow(op.newTab, op.background); + case operations.MARK_SET_PREFIX: + return () => this.markKeyUseCase.enableSetMode(); + case operations.MARK_JUMP_PREFIX: + return () => this.markKeyUseCase.enableJumpMode(); + case operations.FOCUS_INPUT: + return () => this.focusUseCase.focusFirstInput(); + case operations.URLS_YANK: + return () => this.clipbaordUseCase.yankCurrentURL(); + case operations.URLS_PASTE: + return () => + this.clipbaordUseCase.openOrSearch(op.newTab ? op.newTab : false); + default: + return null; } })(nextOp.op); diff --git a/src/content/controllers/MarkController.ts b/src/content/controllers/MarkController.ts index 5eb898a..05a0c75 100644 --- a/src/content/controllers/MarkController.ts +++ b/src/content/controllers/MarkController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import * as messages from '../../shared/messages'; -import MarkUseCase from '../usecases/MarkUseCase'; +import { injectable } from "tsyringe"; +import * as messages from "../../shared/messages"; +import MarkUseCase from "../usecases/MarkUseCase"; @injectable() export default class MarkController { - constructor( - private markUseCase: MarkUseCase, - ) { - } + constructor(private markUseCase: MarkUseCase) {} scrollTo(message: messages.TabScrollToMessage) { this.markUseCase.scroll(message.x, message.y); diff --git a/src/content/controllers/MarkKeyController.ts b/src/content/controllers/MarkKeyController.ts index e7653ee..a011af1 100644 --- a/src/content/controllers/MarkKeyController.ts +++ b/src/content/controllers/MarkKeyController.ts @@ -1,15 +1,14 @@ -import { injectable } from 'tsyringe'; -import MarkUseCase from '../usecases/MarkUseCase'; -import MarkKeyyUseCase from '../usecases/MarkKeyUseCase'; -import Key from '../../shared/settings/Key'; +import { injectable } from "tsyringe"; +import MarkUseCase from "../usecases/MarkUseCase"; +import MarkKeyyUseCase from "../usecases/MarkKeyUseCase"; +import Key from "../../shared/settings/Key"; @injectable() export default class MarkKeyController { constructor( private markUseCase: MarkUseCase, - private markKeyUseCase: MarkKeyyUseCase, - ) { - } + private markKeyUseCase: MarkKeyyUseCase + ) {} press(key: Key): boolean { if (this.markKeyUseCase.isSetMode()) { diff --git a/src/content/controllers/NavigateController.ts b/src/content/controllers/NavigateController.ts index 3f2df7a..5b66a39 100644 --- a/src/content/controllers/NavigateController.ts +++ b/src/content/controllers/NavigateController.ts @@ -1,13 +1,10 @@ -import { injectable } from 'tsyringe'; -import { Message } from '../../shared/messages'; -import NavigateUseCase from '../usecases/NavigateUseCase'; +import { injectable } from "tsyringe"; +import { Message } from "../../shared/messages"; +import NavigateUseCase from "../usecases/NavigateUseCase"; @injectable() export default class NavigateController { - constructor( - private navigateUseCase: NavigateUseCase, - ) { - } + constructor(private navigateUseCase: NavigateUseCase) {} openHistoryNext(_m: Message): Promise<void> { this.navigateUseCase.openHistoryNext(); diff --git a/src/content/controllers/SettingController.ts b/src/content/controllers/SettingController.ts index 2d32c09..72d484c 100644 --- a/src/content/controllers/SettingController.ts +++ b/src/content/controllers/SettingController.ts @@ -1,16 +1,14 @@ -import { injectable } from 'tsyringe'; -import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; -import SettingUseCase from '../usecases/SettingUseCase'; -import * as messages from '../../shared/messages'; +import { injectable } from "tsyringe"; +import AddonEnabledUseCase from "../usecases/AddonEnabledUseCase"; +import SettingUseCase from "../usecases/SettingUseCase"; +import * as messages from "../../shared/messages"; @injectable() export default class SettingController { - constructor( private addonEnabledUseCase: AddonEnabledUseCase, - private settingUseCase: SettingUseCase, - ) { - } + private settingUseCase: SettingUseCase + ) {} async initSettings(): Promise<void> { try { diff --git a/src/content/di.ts b/src/content/di.ts index 63103a1..cc10c78 100644 --- a/src/content/di.ts +++ b/src/content/di.ts @@ -1,58 +1,78 @@ /* eslint-disable max-len */ -import { AddonEnabledRepositoryImpl } from './repositories/AddonEnabledRepository'; -import { AddonIndicatorClientImpl } from './client/AddonIndicatorClient'; -import { AddressRepositoryImpl } from './repositories/AddressRepository'; -import { ClipboardRepositoryImpl } from './repositories/ClipboardRepository'; -import { ConsoleClientImpl } from './client/ConsoleClient'; -import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter'; -import { FindClientImpl } from './client/FindClient'; -import { FindMasterClientImpl } from './client/FindMasterClient'; -import { FindPresenterImpl } from './presenters/FindPresenter'; -import { FindRepositoryImpl } from './repositories/FindRepository'; -import { FocusPresenterImpl } from './presenters/FocusPresenter'; -import { FollowKeyRepositoryImpl } from './repositories/FollowKeyRepository'; -import { FollowMasterClientImpl } from './client/FollowMasterClient'; -import { FollowMasterRepositoryImpl } from './repositories/FollowMasterRepository'; -import { FollowPresenterImpl } from './presenters/FollowPresenter'; -import { FollowSlaveClientFactoryImpl } from './client/FollowSlaveClientFactory'; -import { FollowSlaveRepositoryImpl } from './repositories/FollowSlaveRepository'; -import { KeymapRepositoryImpl } from './repositories/KeymapRepository'; -import { MarkClientImpl } from './client/MarkClient'; -import { MarkKeyRepositoryImpl } from './repositories/MarkKeyRepository'; -import { MarkRepositoryImpl } from './repositories/MarkRepository'; -import { NavigationPresenterImpl } from './presenters/NavigationPresenter'; -import { OperationClientImpl } from './client/OperationClient'; -import { ScrollPresenterImpl } from './presenters/ScrollPresenter'; -import { SettingClientImpl } from './client/SettingClient'; -import { SettingRepositoryImpl } from './repositories/SettingRepository'; -import { TabsClientImpl } from './client/TabsClient'; -import { container } from 'tsyringe'; +import { AddonEnabledRepositoryImpl } from "./repositories/AddonEnabledRepository"; +import { AddonIndicatorClientImpl } from "./client/AddonIndicatorClient"; +import { AddressRepositoryImpl } from "./repositories/AddressRepository"; +import { ClipboardRepositoryImpl } from "./repositories/ClipboardRepository"; +import { ConsoleClientImpl } from "./client/ConsoleClient"; +import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter"; +import { FindClientImpl } from "./client/FindClient"; +import { FindMasterClientImpl } from "./client/FindMasterClient"; +import { FindPresenterImpl } from "./presenters/FindPresenter"; +import { FindRepositoryImpl } from "./repositories/FindRepository"; +import { FocusPresenterImpl } from "./presenters/FocusPresenter"; +import { FollowKeyRepositoryImpl } from "./repositories/FollowKeyRepository"; +import { FollowMasterClientImpl } from "./client/FollowMasterClient"; +import { FollowMasterRepositoryImpl } from "./repositories/FollowMasterRepository"; +import { FollowPresenterImpl } from "./presenters/FollowPresenter"; +import { FollowSlaveClientFactoryImpl } from "./client/FollowSlaveClientFactory"; +import { FollowSlaveRepositoryImpl } from "./repositories/FollowSlaveRepository"; +import { KeymapRepositoryImpl } from "./repositories/KeymapRepository"; +import { MarkClientImpl } from "./client/MarkClient"; +import { MarkKeyRepositoryImpl } from "./repositories/MarkKeyRepository"; +import { MarkRepositoryImpl } from "./repositories/MarkRepository"; +import { NavigationPresenterImpl } from "./presenters/NavigationPresenter"; +import { OperationClientImpl } from "./client/OperationClient"; +import { ScrollPresenterImpl } from "./presenters/ScrollPresenter"; +import { SettingClientImpl } from "./client/SettingClient"; +import { SettingRepositoryImpl } from "./repositories/SettingRepository"; +import { TabsClientImpl } from "./client/TabsClient"; +import { container } from "tsyringe"; -container.register('FollowMasterClient', { useValue: new FollowMasterClientImpl(window.top) }); -container.register('AddonEnabledRepository', { useClass: AddonEnabledRepositoryImpl }); -container.register('AddonIndicatorClient', { useClass: AddonIndicatorClientImpl }); -container.register('AddressRepository', { useClass: AddressRepositoryImpl }); -container.register('ClipboardRepository', { useClass: ClipboardRepositoryImpl }); -container.register('ConsoleClient', { useClass: ConsoleClientImpl }); -container.register('ConsoleFramePresenter', { useClass: ConsoleFramePresenterImpl }); -container.register('FindClient', { useClass: FindClientImpl }); -container.register('FindMasterClient', { useClass: FindMasterClientImpl }); -container.register('FindPresenter', { useClass: FindPresenterImpl }); -container.register('FindRepository', { useClass: FindRepositoryImpl }); -container.register('FocusPresenter', { useClass: FocusPresenterImpl }); -container.register('FollowKeyRepository', { useClass: FollowKeyRepositoryImpl }); -container.register('FollowMasterRepository', { useClass: FollowMasterRepositoryImpl }); -container.register('FollowPresenter', { useClass: FollowPresenterImpl }); -container.register('FollowSlaveClientFactory', { useClass: FollowSlaveClientFactoryImpl }); -container.register('FollowSlaveRepository', { useClass: FollowSlaveRepositoryImpl }); -container.register('KeymapRepository', { useClass: KeymapRepositoryImpl }); -container.register('MarkClient', { useClass: MarkClientImpl }); -container.register('MarkKeyRepository', { useClass: MarkKeyRepositoryImpl }); -container.register('MarkRepository', { useClass: MarkRepositoryImpl }); -container.register('NavigationPresenter', { useClass: NavigationPresenterImpl }); -container.register('OperationClient', { useClass: OperationClientImpl }); -container.register('ScrollPresenter', { useClass: ScrollPresenterImpl }); -container.register('SettingClient', { useClass: SettingClientImpl }); -container.register('SettingRepository', { useClass: SettingRepositoryImpl }); -container.register('TabsClient', { useClass: TabsClientImpl }); +container.register("FollowMasterClient", { + useValue: new FollowMasterClientImpl(window.top), +}); +container.register("AddonEnabledRepository", { + useClass: AddonEnabledRepositoryImpl, +}); +container.register("AddonIndicatorClient", { + useClass: AddonIndicatorClientImpl, +}); +container.register("AddressRepository", { useClass: AddressRepositoryImpl }); +container.register("ClipboardRepository", { + useClass: ClipboardRepositoryImpl, +}); +container.register("ConsoleClient", { useClass: ConsoleClientImpl }); +container.register("ConsoleFramePresenter", { + useClass: ConsoleFramePresenterImpl, +}); +container.register("FindClient", { useClass: FindClientImpl }); +container.register("FindMasterClient", { useClass: FindMasterClientImpl }); +container.register("FindPresenter", { useClass: FindPresenterImpl }); +container.register("FindRepository", { useClass: FindRepositoryImpl }); +container.register("FocusPresenter", { useClass: FocusPresenterImpl }); +container.register("FollowKeyRepository", { + useClass: FollowKeyRepositoryImpl, +}); +container.register("FollowMasterRepository", { + useClass: FollowMasterRepositoryImpl, +}); +container.register("FollowPresenter", { useClass: FollowPresenterImpl }); +container.register("FollowSlaveClientFactory", { + useClass: FollowSlaveClientFactoryImpl, +}); +container.register("FollowSlaveRepository", { + useClass: FollowSlaveRepositoryImpl, +}); +container.register("KeymapRepository", { useClass: KeymapRepositoryImpl }); +container.register("MarkClient", { useClass: MarkClientImpl }); +container.register("MarkKeyRepository", { useClass: MarkKeyRepositoryImpl }); +container.register("MarkRepository", { useClass: MarkRepositoryImpl }); +container.register("NavigationPresenter", { + useClass: NavigationPresenterImpl, +}); +container.register("OperationClient", { useClass: OperationClientImpl }); +container.register("ScrollPresenter", { useClass: ScrollPresenterImpl }); +container.register("SettingClient", { useClass: SettingClientImpl }); +container.register("SettingRepository", { useClass: SettingRepositoryImpl }); +container.register("TabsClient", { useClass: TabsClientImpl }); diff --git a/src/content/domains/KeySequence.ts b/src/content/domains/KeySequence.ts index cf59125..5819fc5 100644 --- a/src/content/domains/KeySequence.ts +++ b/src/content/domains/KeySequence.ts @@ -1,10 +1,7 @@ -import Key from '../../shared/settings/Key'; +import Key from "../../shared/settings/Key"; export default class KeySequence { - constructor( - public readonly keys: Key[], - ) { - } + constructor(public readonly keys: Key[]) {} push(key: Key): number { return this.keys.push(key); @@ -27,25 +24,26 @@ export default class KeySequence { } isDigitOnly(): boolean { - return this.keys.every(key => key.isDigit()); + return this.keys.every((key) => key.isDigit()); } repeatCount(): number { - let nonDigitAt = this.keys.findIndex(key => !key.isDigit()); + let nonDigitAt = this.keys.findIndex((key) => !key.isDigit()); if (this.keys.length === 0 || nonDigitAt === 0) { return 1; } if (nonDigitAt === -1) { nonDigitAt = this.keys.length; } - const digits = this.keys.slice(0, nonDigitAt) - .map(key => key.key) - .join(''); + const digits = this.keys + .slice(0, nonDigitAt) + .map((key) => key.key) + .join(""); return Number(digits); } trimNumericPrefix(): KeySequence { - let nonDigitAt = this.keys.findIndex(key => !key.isDigit()); + let nonDigitAt = this.keys.findIndex((key) => !key.isDigit()); if (nonDigitAt === -1) { nonDigitAt = this.keys.length; } @@ -53,7 +51,7 @@ export default class KeySequence { } splitNumericPrefix(): [KeySequence, KeySequence] { - const nonDigitIndex = this.keys.findIndex(key => !key.isDigit()); + const nonDigitIndex = this.keys.findIndex((key) => !key.isDigit()); if (nonDigitIndex === -1) { return [this, new KeySequence([])]; } @@ -65,15 +63,16 @@ export default class KeySequence { static fromMapKeys(keys: string): KeySequence { const fromMapKeysRecursive = ( - remaining: string, mappedKeys: Key[], + remaining: string, + mappedKeys: Key[] ): Key[] => { if (remaining.length === 0) { return mappedKeys; } let nextPos = 1; - if (remaining.startsWith('<')) { - const ltPos = remaining.indexOf('>'); + if (remaining.startsWith("<")) { + const ltPos = remaining.indexOf(">"); if (ltPos > 0) { nextPos = ltPos + 1; } diff --git a/src/content/domains/Mark.ts b/src/content/domains/Mark.ts index 0c40988..68ed226 100644 --- a/src/content/domains/Mark.ts +++ b/src/content/domains/Mark.ts @@ -2,4 +2,3 @@ export default interface Mark { x: number; y: number; } - diff --git a/src/content/hint-key-producer.ts b/src/content/hint-key-producer.ts index 3c9482f..a5e2877 100644 --- a/src/content/hint-key-producer.ts +++ b/src/content/hint-key-producer.ts @@ -5,7 +5,7 @@ export default class HintKeyProducer { constructor(charset: string) { if (charset.length === 0) { - throw new TypeError('charset is empty'); + throw new TypeError("charset is empty"); } this.charset = charset; @@ -15,12 +15,12 @@ export default class HintKeyProducer { produce(): string { this.increment(); - return this.counter.map(x => this.charset[x]).join(''); + return this.counter.map((x) => this.charset[x]).join(""); } private increment(): void { const max = this.charset.length - 1; - if (this.counter.every(x => x === max)) { + if (this.counter.every((x) => x === max)) { this.counter = new Array(this.counter.length + 1).fill(0); return; } diff --git a/src/content/index.ts b/src/content/index.ts index 176a157..b575e0d 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -1,10 +1,10 @@ -import 'reflect-metadata'; +import "reflect-metadata"; -import Application from './Application'; -import consoleFrameStyle from './site-style'; -import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter'; -import { container } from 'tsyringe'; -import './di'; +import Application from "./Application"; +import consoleFrameStyle from "./site-style"; +import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter"; +import { container } from "tsyringe"; +import "./di"; if (window.self === window.top) { new ConsoleFramePresenterImpl().initialize(); @@ -13,8 +13,10 @@ if (window.self === window.top) { try { const app = container.resolve(Application); app.run(); -} catch (e) { console.error(e); } +} catch (e) { + console.error(e); +} -const 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 63c78fb..26522c4 100644 --- a/src/content/presenters/ConsoleFramePresenter.ts +++ b/src/content/presenters/ConsoleFramePresenter.ts @@ -6,17 +6,17 @@ export default interface ConsoleFramePresenter { export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { initialize(): void { - const iframe = document.createElement('iframe'); - iframe.src = browser.runtime.getURL('build/console.html'); - iframe.id = 'vimvixen-console-frame'; - iframe.className = 'vimvixen-console-frame'; + const iframe = document.createElement("iframe"); + iframe.src = browser.runtime.getURL("build/console.html"); + iframe.id = "vimvixen-console-frame"; + iframe.className = "vimvixen-console-frame"; document.body.append(iframe); } blur(): void { - const ele = document.getElementById('vimvixen-console-frame'); + const ele = document.getElementById("vimvixen-console-frame"); if (!ele) { - throw new Error('console frame not created'); + throw new Error("console frame not created"); } ele.blur(); } diff --git a/src/content/presenters/FindPresenter.ts b/src/content/presenters/FindPresenter.ts index 98d8088..117142c 100644 --- a/src/content/presenters/FindPresenter.ts +++ b/src/content/presenters/FindPresenter.ts @@ -1,4 +1,3 @@ - export default interface FindPresenter { find(keyword: string, backwards: boolean): boolean; @@ -18,7 +17,8 @@ interface MyWindow extends Window { aWrapAround?: boolean, aWholeWord?: boolean, aSearchInFrames?: boolean, - aShowDialog?: boolean): boolean; + aShowDialog?: boolean + ): boolean; } // eslint-disable-next-line no-var, vars-on-top, init-declarations @@ -29,7 +29,6 @@ export class FindPresenterImpl implements FindPresenter { const caseSensitive = false; const wrapScan = true; - // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work // because of same origin policy const found = window.find(keyword, caseSensitive, backwards, wrapScan); diff --git a/src/content/presenters/FocusPresenter.ts b/src/content/presenters/FocusPresenter.ts index 842c41e..4d70a6e 100644 --- a/src/content/presenters/FocusPresenter.ts +++ b/src/content/presenters/FocusPresenter.ts @@ -1,4 +1,4 @@ -import * as doms from '../../shared/utils/dom'; +import * as doms from "../../shared/utils/dom"; export default interface FocusPresenter { focusFirstElement(): boolean; @@ -6,9 +6,13 @@ export default interface FocusPresenter { export class FocusPresenterImpl implements FocusPresenter { focusFirstElement(): boolean { - 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 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(); @@ -20,4 +24,3 @@ export class FocusPresenterImpl implements FocusPresenter { return false; } } - diff --git a/src/content/presenters/FollowPresenter.ts b/src/content/presenters/FollowPresenter.ts index fef8140..8aef819 100644 --- a/src/content/presenters/FollowPresenter.ts +++ b/src/content/presenters/FollowPresenter.ts @@ -1,11 +1,18 @@ -import Hint, { InputHint, LinkHint } from './Hint'; -import * as doms from '../../shared/utils/dom'; +import Hint, { InputHint, LinkHint } from "./Hint"; +import * as doms from "../../shared/utils/dom"; const TARGET_SELECTOR = [ - 'a', 'button', 'input', 'textarea', 'area', - '[contenteditable=true]', '[contenteditable=""]', '[tabindex]', - '[role="button"]', 'summary' -].join(','); + "a", + "button", + "input", + "textarea", + "area", + "[contenteditable=true]", + '[contenteditable=""]', + "[tabindex]", + '[role="button"]', + "summary", +].join(","); interface Size { width: number; @@ -21,11 +28,9 @@ const inViewport = ( win: Window, element: Element, viewSize: Size, - framePosition: Point, + framePosition: Point ): boolean => { - const { - top, left, bottom, right - } = doms.viewportRect(element); + const { top, left, bottom, right } = doms.viewportRect(element); const doc = win.document; const frameWidth = doc.documentElement.clientWidth; const frameHeight = doc.documentElement.clientHeight; @@ -34,9 +39,12 @@ const inViewport = ( // out of frame return false; } - if (right + framePosition.x < 0 || bottom + framePosition.y < 0 || - left + framePosition.x > viewSize.width || - top + framePosition.y > viewSize.height) { + if ( + right + framePosition.x < 0 || + bottom + framePosition.y < 0 || + left + framePosition.x > viewSize.width || + top + framePosition.y > viewSize.height + ) { // out of viewport return false; } @@ -47,11 +55,11 @@ const isAriaHiddenOrAriaDisabled = (win: Window, element: Element): boolean => { if (!element || win.document.documentElement === element) { return false; } - for (const attr of ['aria-hidden', 'aria-disabled']) { + for (const attr of ["aria-hidden", "aria-disabled"]) { const value = element.getAttribute(attr); if (value !== null) { const hidden = value.toLowerCase(); - if (hidden === '' || hidden === 'true') { + if (hidden === "" || hidden === "true") { return true; } } @@ -88,8 +96,10 @@ export class FollowPresenterImpl implements FollowPresenter { const min = Math.min(targets.length, tags.length); for (let i = 0; i < min; ++i) { const target = targets[i]; - if (target instanceof HTMLAnchorElement || - target instanceof HTMLAreaElement) { + if ( + target instanceof HTMLAnchorElement || + target instanceof HTMLAreaElement + ) { this.hints.push(new LinkHint(target, tags[i])); } else { this.hints.push(new InputHint(target, tags[i])); @@ -98,35 +108,40 @@ export class FollowPresenterImpl implements FollowPresenter { } filterHints(prefix: string): void { - const shown = this.hints.filter(h => h.getTag().startsWith(prefix)); - const 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()); + shown.forEach((h) => h.show()); + hidden.forEach((h) => h.hide()); } clearHints(): void { - this.hints.forEach(h => h.remove()); + this.hints.forEach((h) => h.remove()); this.hints = []; } getHint(tag: string): Hint | undefined { - return this.hints.find(h => h.getTag() === tag); + return this.hints.find((h) => h.getTag() === tag); } private getTargets(viewSize: Size, framePosition: Point): HTMLElement[] { 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') && - style.visibility !== 'hidden' && - (element as HTMLInputElement).type !== 'hidden' && - element.offsetHeight > 0 && - !isAriaHiddenOrAriaDisabled(window, element) && - inViewport(window, element, viewSize, framePosition); - }); + 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") && + style.visibility !== "hidden" && + (element as HTMLInputElement).type !== "hidden" && + element.offsetHeight > 0 && + !isAriaHiddenOrAriaDisabled(window, element) && + inViewport(window, element, viewSize, framePosition) + ); + } + ); return filtered; } } diff --git a/src/content/presenters/Hint.ts b/src/content/presenters/Hint.ts index 44b8185..3f39060 100644 --- a/src/content/presenters/Hint.ts +++ b/src/content/presenters/Hint.ts @@ -1,4 +1,4 @@ -import * as doms from '../../shared/utils/dom'; +import * as doms from "../../shared/utils/dom"; interface Point { x: number; @@ -8,7 +8,7 @@ interface Point { const hintPosition = (element: Element): Point => { const { left, top, right, bottom } = doms.viewportRect(element); - if (element.tagName !== 'AREA') { + if (element.tagName !== "AREA") { return { x: left, y: top }; } @@ -28,17 +28,17 @@ export default abstract class Hint { const doc = target.ownerDocument; if (doc === null) { - throw new TypeError('ownerDocument is null'); + throw new TypeError("ownerDocument is null"); } const { x, y } = hintPosition(target); const { scrollX, scrollY } = window; - const hint = doc.createElement('span'); - hint.className = 'vimvixen-hint'; + const hint = doc.createElement("span"); + hint.className = "vimvixen-hint"; hint.textContent = tag; - hint.style.left = x + scrollX + 'px'; - hint.style.top = y + scrollY + 'px'; + hint.style.left = x + scrollX + "px"; + hint.style.top = y + scrollY + "px"; doc.body.append(hint); @@ -47,11 +47,11 @@ export default abstract class Hint { } show(): void { - this.hint.style.display = 'inline'; + this.hint.style.display = "inline"; } hide(): void { - this.hint.style.display = 'none'; + this.hint.style.display = "none"; } remove(): void { @@ -77,7 +77,7 @@ export class LinkHint extends Hint { } getLinkTarget(): string | null { - return this.target.getAttribute('target'); + return this.target.getAttribute("target"); } click(): void { @@ -97,31 +97,31 @@ export class InputHint extends Hint { activate(): void { const target = this.target; switch (target.tagName.toLowerCase()) { - case 'input': - switch ((target as HTMLInputElement).type) { - case 'file': - case 'checkbox': - case 'radio': - case 'submit': - case 'reset': - case 'button': - case 'image': - case 'color': - return target.click(); - default: + case "input": + switch ((target as HTMLInputElement).type) { + case "file": + case "checkbox": + case "radio": + case "submit": + case "reset": + case "button": + case "image": + case "color": + return target.click(); + default: + return target.focus(); + } + case "textarea": return target.focus(); - } - case 'textarea': - return target.focus(); - case 'button': - case 'summary': - return target.click(); - default: - if (doms.isContentEditable(target)) { - return target.focus(); - } else if (target.hasAttribute('tabindex')) { + case "button": + case "summary": return target.click(); - } + default: + if (doms.isContentEditable(target)) { + return target.focus(); + } else if (target.hasAttribute("tabindex")) { + return target.click(); + } } } } diff --git a/src/content/presenters/NavigationPresenter.ts b/src/content/presenters/NavigationPresenter.ts index 951e62a..3edcd12 100644 --- a/src/content/presenters/NavigationPresenter.ts +++ b/src/content/presenters/NavigationPresenter.ts @@ -8,7 +8,7 @@ export default interface NavigationPresenter { openLinkNext(): void; } -const REL_PATTERN: {[key: string]: RegExp} = { +const REL_PATTERN: { [key: string]: RegExp } = { prev: /^(?:prev(?:ious)?|older)\b|\u2039|\u2190|\xab|\u226a|<</i, next: /^(?:next|newer)\b|\u203a|\u2192|\xbb|\u226b|>>/i, }; @@ -18,7 +18,7 @@ const REL_PATTERN: {[key: string]: RegExp} = { // eslint-disable-next-line func-style function selectLast<E extends Element>( selector: string, - filter?: (e: E) => boolean, + filter?: (e: E) => boolean ): E | null { let nodes = Array.from( window.document.querySelectorAll(selector) as NodeListOf<E> @@ -40,15 +40,15 @@ export class NavigationPresenterImpl implements NavigationPresenter { } openLinkPrev(): void { - this.linkRel('prev'); + this.linkRel("prev"); } openLinkNext(): void { - this.linkRel('next'); + this.linkRel("next"); } // Code common to linkPrev and linkNext which navigates to the specified page. - private linkRel(rel: 'prev' | 'next'): void { + private linkRel(rel: "prev" | "next"): void { const link = selectLast<HTMLLinkElement>(`link[rel~=${rel}][href]`); if (link) { window.location.href = link.href; @@ -57,10 +57,11 @@ export class NavigationPresenterImpl implements NavigationPresenter { const pattern = REL_PATTERN[rel]; - 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)); + 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)); if (a) { a.click(); diff --git a/src/content/presenters/ScrollPresenter.ts b/src/content/presenters/ScrollPresenter.ts index 387ab62..f1a6402 100644 --- a/src/content/presenters/ScrollPresenter.ts +++ b/src/content/presenters/ScrollPresenter.ts @@ -1,4 +1,4 @@ -import * as doms from '../../shared/utils/dom'; +import * as doms from "../../shared/utils/dom"; const SCROLL_DELTA_X = 64; const SCROLL_DELTA_Y = 64; @@ -9,13 +9,19 @@ let lastTimeoutId: number | null = null; const isScrollableStyle = (element: Element): boolean => { const { overflowX, overflowY } = window.getComputedStyle(element); - return !(overflowX !== 'scroll' && overflowX !== 'auto' && - overflowY !== 'scroll' && overflowY !== 'auto'); + return !( + overflowX !== "scroll" && + overflowX !== "auto" && + overflowY !== "scroll" && + overflowY !== "auto" + ); }; const isOverflowed = (element: Element): boolean => { - return element.scrollWidth > element.clientWidth || - element.scrollHeight > element.clientHeight; + return ( + element.scrollWidth > element.clientWidth || + element.scrollHeight > element.clientHeight + ); }; // Find a visiable and scrollable element by depth-first search. Currently @@ -73,7 +79,7 @@ class Scroller { this.element.scrollTo({ left: x, top: y, - behavior: 'smooth', + behavior: "smooth", }); this.prepareReset(); } @@ -94,7 +100,7 @@ class Scroller { } } -export type Point = { x: number, y: number }; +export type Point = { x: number; y: number }; export default interface ScrollPresenter { getScroll(): Point; diff --git a/src/content/repositories/AddressRepository.ts b/src/content/repositories/AddressRepository.ts index 6f9487b..f200bf2 100644 --- a/src/content/repositories/AddressRepository.ts +++ b/src/content/repositories/AddressRepository.ts @@ -1,5 +1,5 @@ export default interface AddressRepository { - getCurrentURL(): URL + getCurrentURL(): URL; } export class AddressRepositoryImpl implements AddressRepository { diff --git a/src/content/repositories/ClipboardRepository.ts b/src/content/repositories/ClipboardRepository.ts index 8219835..a700543 100644 --- a/src/content/repositories/ClipboardRepository.ts +++ b/src/content/repositories/ClipboardRepository.ts @@ -6,39 +6,39 @@ export default interface ClipboardRepository { export class ClipboardRepositoryImpl { read(): string { - const textarea = window.document.createElement('textarea'); + const textarea = window.document.createElement("textarea"); window.document.body.append(textarea); - textarea.style.position = 'fixed'; - textarea.style.top = '-100px'; - textarea.contentEditable = 'true'; + textarea.style.position = "fixed"; + textarea.style.top = "-100px"; + textarea.contentEditable = "true"; textarea.focus(); - const ok = window.document.execCommand('paste'); + const ok = window.document.execCommand("paste"); const value = textarea.textContent!!; textarea.remove(); if (!ok) { - throw new Error('failed to access clipbaord'); + throw new Error("failed to access clipbaord"); } return value; } write(text: string): void { - const input = window.document.createElement('input'); + const input = window.document.createElement("input"); window.document.body.append(input); - input.style.position = 'fixed'; - input.style.top = '-100px'; + input.style.position = "fixed"; + input.style.top = "-100px"; input.value = text; input.select(); - const ok = window.document.execCommand('copy'); + const ok = window.document.execCommand("copy"); input.remove(); if (!ok) { - throw new Error('failed to access clipbaord'); + throw new Error("failed to access clipbaord"); } } } diff --git a/src/content/repositories/FollowMasterRepository.ts b/src/content/repositories/FollowMasterRepository.ts index da2402c..cc49e5f 100644 --- a/src/content/repositories/FollowMasterRepository.ts +++ b/src/content/repositories/FollowMasterRepository.ts @@ -35,7 +35,7 @@ export class FollowMasterRepositoryImpl implements FollowMasterRepository { } getTagsByPrefix(prefix: string): string[] { - return current.tags.filter(t => t.startsWith(prefix)); + return current.tags.filter((t) => t.startsWith(prefix)); } addTag(tag: string): void { @@ -54,4 +54,3 @@ export class FollowMasterRepositoryImpl implements FollowMasterRepository { return current.background; } } - diff --git a/src/content/repositories/FollowSlaveRepository.ts b/src/content/repositories/FollowSlaveRepository.ts index 42a0710..0dc9e89 100644 --- a/src/content/repositories/FollowSlaveRepository.ts +++ b/src/content/repositories/FollowSlaveRepository.ts @@ -25,5 +25,3 @@ export class FollowSlaveRepositoryImpl implements FollowSlaveRepository { return current.enabled; } } - - diff --git a/src/content/repositories/KeymapRepository.ts b/src/content/repositories/KeymapRepository.ts index 2944723..6a7d656 100644 --- a/src/content/repositories/KeymapRepository.ts +++ b/src/content/repositories/KeymapRepository.ts @@ -1,5 +1,5 @@ -import Key from '../../shared/settings/Key'; -import KeySequence from '../domains/KeySequence'; +import Key from "../../shared/settings/Key"; +import KeySequence from "../domains/KeySequence"; export default interface KeymapRepository { enqueueKey(key: Key): KeySequence; @@ -10,7 +10,6 @@ export default interface KeymapRepository { let current: KeySequence = new KeySequence([]); export class KeymapRepositoryImpl { - enqueueKey(key: Key): KeySequence { current.push(key); return current; diff --git a/src/content/repositories/MarkKeyRepository.ts b/src/content/repositories/MarkKeyRepository.ts index 18c3e23..c351c13 100644 --- a/src/content/repositories/MarkKeyRepository.ts +++ b/src/content/repositories/MarkKeyRepository.ts @@ -23,7 +23,6 @@ const current: Mode = { }; export class MarkKeyRepositoryImpl implements MarkKeyRepository { - isSetMode(): boolean { return current.setMode; } diff --git a/src/content/repositories/MarkRepository.ts b/src/content/repositories/MarkRepository.ts index afa980a..e48db25 100644 --- a/src/content/repositories/MarkRepository.ts +++ b/src/content/repositories/MarkRepository.ts @@ -1,4 +1,4 @@ -import Mark from '../domains/Mark'; +import Mark from "../domains/Mark"; export default interface MarkRepository { set(key: string, mark: Mark): void; @@ -6,7 +6,7 @@ export default interface MarkRepository { get(key: string): Mark | null; } -const saved: {[key: string]: Mark} = {}; +const saved: { [key: string]: Mark } = {}; export class MarkRepositoryImpl implements MarkRepository { set(key: string, mark: Mark): void { diff --git a/src/content/repositories/SettingRepository.ts b/src/content/repositories/SettingRepository.ts index 4ba26e0..1e393cd 100644 --- a/src/content/repositories/SettingRepository.ts +++ b/src/content/repositories/SettingRepository.ts @@ -1,4 +1,4 @@ -import Settings, { DefaultSetting } from '../../shared/settings/Settings'; +import Settings, { DefaultSetting } from "../../shared/settings/Settings"; let current: Settings = DefaultSetting; diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts index 608a401..f7e78c5 100644 --- a/src/content/usecases/AddonEnabledUseCase.ts +++ b/src/content/usecases/AddonEnabledUseCase.ts @@ -1,18 +1,16 @@ -import { injectable, inject } from 'tsyringe'; -import AddonIndicatorClient from '../client/AddonIndicatorClient'; -import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; +import { injectable, inject } from "tsyringe"; +import AddonIndicatorClient from "../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../repositories/AddonEnabledRepository"; @injectable() export default class AddonEnabledUseCase { - constructor( - @inject('AddonIndicatorClient') + @inject("AddonIndicatorClient") private indicator: AddonIndicatorClient, - @inject('AddonEnabledRepository') - private repository: AddonEnabledRepository, - ) { - } + @inject("AddonEnabledRepository") + private repository: AddonEnabledRepository + ) {} async enable(): Promise<void> { await this.setEnabled(true); diff --git a/src/content/usecases/ClipboardUseCase.ts b/src/content/usecases/ClipboardUseCase.ts index 7f16f68..875fc11 100644 --- a/src/content/usecases/ClipboardUseCase.ts +++ b/src/content/usecases/ClipboardUseCase.ts @@ -1,24 +1,23 @@ -import { injectable, inject } from 'tsyringe'; -import * as urls from '../../shared/urls'; -import ClipboardRepository from '../repositories/ClipboardRepository'; -import SettingRepository from '../repositories/SettingRepository'; -import ConsoleClient from '../client/ConsoleClient'; -import OperationClient from '../client/OperationClient'; +import { injectable, inject } from "tsyringe"; +import * as urls from "../../shared/urls"; +import ClipboardRepository from "../repositories/ClipboardRepository"; +import SettingRepository from "../repositories/SettingRepository"; +import ConsoleClient from "../client/ConsoleClient"; +import OperationClient from "../client/OperationClient"; @injectable() export default class ClipboardUseCase { constructor( - @inject('ClipboardRepository') private repository: ClipboardRepository, - @inject('SettingRepository') private settingRepository: SettingRepository, - @inject('ConsoleClient') private consoleClient: ConsoleClient, - @inject('OperationClient') private operationClinet: OperationClient, - ) { - } + @inject("ClipboardRepository") private repository: ClipboardRepository, + @inject("SettingRepository") private settingRepository: SettingRepository, + @inject("ConsoleClient") private consoleClient: ConsoleClient, + @inject("OperationClient") private operationClinet: OperationClient + ) {} async yankCurrentURL(): Promise<string> { const url = window.location.href; this.repository.write(url); - await this.consoleClient.info('Yanked ' + url); + await this.consoleClient.info("Yanked " + url); return Promise.resolve(url); } diff --git a/src/content/usecases/ConsoleFrameUseCase.ts b/src/content/usecases/ConsoleFrameUseCase.ts index 3c4b0a1..b118c7f 100644 --- a/src/content/usecases/ConsoleFrameUseCase.ts +++ b/src/content/usecases/ConsoleFrameUseCase.ts @@ -1,13 +1,12 @@ -import { injectable, inject } from 'tsyringe'; -import ConsoleFramePresenter from '../presenters/ConsoleFramePresenter'; +import { injectable, inject } from "tsyringe"; +import ConsoleFramePresenter from "../presenters/ConsoleFramePresenter"; @injectable() export default class ConsoleFrameUseCase { constructor( - @inject('ConsoleFramePresenter') - private consoleFramePresenter: ConsoleFramePresenter, - ) { - } + @inject("ConsoleFramePresenter") + private consoleFramePresenter: ConsoleFramePresenter + ) {} unfocus() { window.focus(); diff --git a/src/content/usecases/FindSlaveUseCase.ts b/src/content/usecases/FindSlaveUseCase.ts index 0a5c2ce..3b8c4b4 100644 --- a/src/content/usecases/FindSlaveUseCase.ts +++ b/src/content/usecases/FindSlaveUseCase.ts @@ -1,12 +1,11 @@ -import { injectable, inject } from 'tsyringe'; -import FindMasterClient from '../client/FindMasterClient'; +import { injectable, inject } from "tsyringe"; +import FindMasterClient from "../client/FindMasterClient"; @injectable() export default class FindSlaveUseCase { constructor( - @inject('FindMasterClient') private findMasterClient: FindMasterClient, - ) { - } + @inject("FindMasterClient") private findMasterClient: FindMasterClient + ) {} findNext() { this.findMasterClient.findNext(); diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts index c6a478f..bff0eee 100644 --- a/src/content/usecases/FindUseCase.ts +++ b/src/content/usecases/FindUseCase.ts @@ -1,18 +1,17 @@ -import { injectable, inject } from 'tsyringe'; -import FindPresenter from '../presenters/FindPresenter'; -import FindRepository from '../repositories/FindRepository'; -import FindClient from '../client/FindClient'; -import ConsoleClient from '../client/ConsoleClient'; +import { injectable, inject } from "tsyringe"; +import FindPresenter from "../presenters/FindPresenter"; +import FindRepository from "../repositories/FindRepository"; +import FindClient from "../client/FindClient"; +import ConsoleClient from "../client/ConsoleClient"; @injectable() export default class FindUseCase { constructor( - @inject('FindPresenter') private presenter: FindPresenter, - @inject('FindRepository') private repository: FindRepository, - @inject('FindClient') private client: FindClient, - @inject('ConsoleClient') private consoleClient: ConsoleClient, - ) { - } + @inject("FindPresenter") private presenter: FindPresenter, + @inject("FindRepository") private repository: FindRepository, + @inject("FindClient") private client: FindClient, + @inject("ConsoleClient") private consoleClient: ConsoleClient + ) {} async startFind(keyword?: string): Promise<void> { this.presenter.clearSelection(); @@ -36,18 +35,16 @@ export default class FindUseCase { return this.findNextPrev(true); } - private async findNextPrev( - backwards: boolean, - ): Promise<void> { + private async findNextPrev(backwards: boolean): Promise<void> { const keyword = await this.getKeyword(); if (!keyword) { return this.showNoLastKeywordError(); } const found = this.presenter.find(keyword, backwards); if (found) { - this.consoleClient.info('Pattern found: ' + keyword); + this.consoleClient.info("Pattern found: " + keyword); } else { - this.consoleClient.error('Pattern not found: ' + keyword); + this.consoleClient.error("Pattern not found: " + keyword); } } @@ -65,6 +62,6 @@ export default class FindUseCase { } private async showNoLastKeywordError(): Promise<void> { - await this.consoleClient.error('No previous search keywords'); + await this.consoleClient.error("No previous search keywords"); } } diff --git a/src/content/usecases/FocusUseCase.ts b/src/content/usecases/FocusUseCase.ts index 0158672..8c62003 100644 --- a/src/content/usecases/FocusUseCase.ts +++ b/src/content/usecases/FocusUseCase.ts @@ -1,12 +1,9 @@ -import { injectable, inject } from 'tsyringe'; -import FocusPresenter from '../presenters/FocusPresenter'; +import { injectable, inject } from "tsyringe"; +import FocusPresenter from "../presenters/FocusPresenter"; @injectable() export default class FocusUseCases { - constructor( - @inject('FocusPresenter') private presenter: FocusPresenter, - ) { - } + constructor(@inject("FocusPresenter") private presenter: FocusPresenter) {} focusFirstInput() { this.presenter.focusFirstElement(); diff --git a/src/content/usecases/FollowMasterUseCase.ts b/src/content/usecases/FollowMasterUseCase.ts index 0e7f394..329f05a 100644 --- a/src/content/usecases/FollowMasterUseCase.ts +++ b/src/content/usecases/FollowMasterUseCase.ts @@ -1,10 +1,10 @@ -import { injectable, inject } from 'tsyringe'; -import FollowKeyRepository from '../repositories/FollowKeyRepository'; -import FollowMasterRepository from '../repositories/FollowMasterRepository'; -import FollowSlaveClient from '../client/FollowSlaveClient'; -import FollowSlaveClientFactory from '../client/FollowSlaveClientFactory'; -import SettingRepository from '../repositories/SettingRepository'; -import HintKeyProducer from './HintKeyProducer'; +import { injectable, inject } from "tsyringe"; +import FollowKeyRepository from "../repositories/FollowKeyRepository"; +import FollowMasterRepository from "../repositories/FollowMasterRepository"; +import FollowSlaveClient from "../client/FollowSlaveClient"; +import FollowSlaveClientFactory from "../client/FollowSlaveClientFactory"; +import SettingRepository from "../repositories/SettingRepository"; +import HintKeyProducer from "./HintKeyProducer"; @injectable() export default class FollowMasterUseCase { @@ -12,17 +12,17 @@ export default class FollowMasterUseCase { private producer: HintKeyProducer | null; constructor( - @inject('FollowKeyRepository') + @inject("FollowKeyRepository") private followKeyRepository: FollowKeyRepository, - @inject('FollowMasterRepository') + @inject("FollowMasterRepository") private followMasterRepository: FollowMasterRepository, - @inject('SettingRepository') + @inject("SettingRepository") private settingRepository: SettingRepository, - @inject('FollowSlaveClientFactory') - private followSlaveClientFactory: FollowSlaveClientFactory, + @inject("FollowSlaveClientFactory") + private followSlaveClientFactory: FollowSlaveClientFactory ) { this.producer = null; } @@ -36,19 +36,21 @@ export default class FollowMasterUseCase { const viewWidth = window.top.innerWidth; const viewHeight = window.top.innerHeight; - this.followSlaveClientFactory.create(window.top).requestHintCount( - { width: viewWidth, height: viewHeight }, - { x: 0, y: 0 }, - ); + this.followSlaveClientFactory + .create(window.top) + .requestHintCount( + { width: viewWidth, height: viewHeight }, + { x: 0, y: 0 } + ); - const frameElements = window.document.querySelectorAll('iframe'); + const frameElements = window.document.querySelectorAll("iframe"); for (let i = 0; i < frameElements.length; ++i) { 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 }, + { x: frameX, y: frameY } ); } } @@ -67,8 +69,10 @@ export default class FollowMasterUseCase { const viewHeight = window.innerHeight || doc.documentElement.clientHeight; let pos = { x: 0, y: 0 }; if (sender !== window) { - const frameElements = window.document.querySelectorAll('iframe'); - const 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; @@ -77,11 +81,7 @@ export default class FollowMasterUseCase { pos = { x: frameX, y: frameY }; } const client = this.followSlaveClientFactory.create(sender); - client.createHints( - { width: viewWidth, height: viewHeight }, - pos, - produced, - ); + client.createHints({ width: viewWidth, height: viewHeight }, pos, produced); } cancelFollow(): void { @@ -110,17 +110,17 @@ export default class FollowMasterUseCase { enqueue(key: string): void { switch (key) { - case 'Enter': - this.activate(this.getCurrentTag()); - return; - case 'Esc': - this.cancelFollow(); - return; - case 'Backspace': - case 'Delete': - this.followKeyRepository.popKey(); - this.filter(this.getCurrentTag()); - return; + case "Enter": + this.activate(this.getCurrentTag()); + return; + case "Esc": + this.cancelFollow(); + return; + case "Backspace": + case "Delete": + this.followKeyRepository.popKey(); + this.filter(this.getCurrentTag()); + return; } this.followKeyRepository.pushKey(key); @@ -138,13 +138,15 @@ export default class FollowMasterUseCase { private broadcastToSlaves(handler: (client: FollowSlaveClient) => void) { const allFrames = [window.self].concat(Array.from(window.frames as any)); - const clients = allFrames.map(w => this.followSlaveClientFactory.create(w)); + const clients = allFrames.map((w) => + this.followSlaveClientFactory.create(w) + ); for (const client of clients) { handler(client); } } private getCurrentTag(): string { - return this.followKeyRepository.getKeys().join(''); + return this.followKeyRepository.getKeys().join(""); } } diff --git a/src/content/usecases/FollowSlaveUseCase.ts b/src/content/usecases/FollowSlaveUseCase.ts index fb805b9..971ecee 100644 --- a/src/content/usecases/FollowSlaveUseCase.ts +++ b/src/content/usecases/FollowSlaveUseCase.ts @@ -1,10 +1,10 @@ -import { injectable, inject } from 'tsyringe'; -import FollowSlaveRepository from '../repositories/FollowSlaveRepository'; -import FollowPresenter from '../presenters/FollowPresenter'; -import TabsClient from '../client/TabsClient'; -import FollowMasterClient from '../client/FollowMasterClient'; -import { LinkHint, InputHint } from '../presenters/Hint'; -import Key from '../../shared/settings/Key'; +import { injectable, inject } from "tsyringe"; +import FollowSlaveRepository from "../repositories/FollowSlaveRepository"; +import FollowPresenter from "../presenters/FollowPresenter"; +import TabsClient from "../client/TabsClient"; +import FollowMasterClient from "../client/FollowMasterClient"; +import { LinkHint, InputHint } from "../presenters/Hint"; +import Key from "../../shared/settings/Key"; interface Size { width: number; @@ -19,19 +19,18 @@ interface Point { @injectable() export default class FollowSlaveUseCase { constructor( - @inject('FollowPresenter') + @inject("FollowPresenter") private presenter: FollowPresenter, - @inject('TabsClient') + @inject("TabsClient") private tabsClient: TabsClient, - @inject('FollowMasterClient') + @inject("FollowMasterClient") private followMasterClient: FollowMasterClient, - @inject('FollowSlaveRepository') - private followSlaveRepository: FollowSlaveRepository, - ) { - } + @inject("FollowSlaveRepository") + private followSlaveRepository: FollowSlaveRepository + ) {} countTargets(viewSize: Size, framePosition: Point): void { const count = this.presenter.getTargetCount(viewSize, framePosition); @@ -65,11 +64,11 @@ export default class FollowSlaveUseCase { const url = hint.getLink(); let openNewTab = newTab; // Open link by background script in order to prevent a popup block - if (hint.getLinkTarget() === '_blank') { + if (hint.getLinkTarget() === "_blank") { openNewTab = true; } // eslint-disable-next-line no-script-url - if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) { + if (!url || url === "#" || url.toLowerCase().startsWith("javascript:")) { return; } await this.tabsClient.openUrl(url, openNewTab, background); diff --git a/src/content/usecases/HintKeyProducer.ts b/src/content/usecases/HintKeyProducer.ts index 68f3fbd..a5e2877 100644 --- a/src/content/usecases/HintKeyProducer.ts +++ b/src/content/usecases/HintKeyProducer.ts @@ -5,7 +5,7 @@ export default class HintKeyProducer { constructor(charset: string) { if (charset.length === 0) { - throw new TypeError('charset is empty'); + throw new TypeError("charset is empty"); } this.charset = charset; @@ -15,12 +15,12 @@ export default class HintKeyProducer { produce(): string { this.increment(); - return this.counter.map(x => this.charset[x]).join(''); + return this.counter.map((x) => this.charset[x]).join(""); } private increment(): void { const max = this.charset.length - 1; - if (this.counter.every(x => x === max)) { + if (this.counter.every((x) => x === max)) { this.counter = new Array(this.counter.length + 1).fill(0); return; } @@ -35,4 +35,3 @@ export default class HintKeyProducer { this.counter.reverse(); } } - diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index e02bc48..3cbadcb 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -1,16 +1,16 @@ -import { injectable, inject } from 'tsyringe'; -import KeymapRepository from '../repositories/KeymapRepository'; -import SettingRepository from '../repositories/SettingRepository'; -import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; -import * as operations from '../../shared/operations'; -import Keymaps from '../../shared/settings/Keymaps'; -import Key from '../../shared/settings/Key'; -import KeySequence from '../domains/KeySequence'; -import AddressRepository from '../repositories/AddressRepository'; +import { injectable, inject } from "tsyringe"; +import KeymapRepository from "../repositories/KeymapRepository"; +import SettingRepository from "../repositories/SettingRepository"; +import AddonEnabledRepository from "../repositories/AddonEnabledRepository"; +import * as operations from "../../shared/operations"; +import Keymaps from "../../shared/settings/Keymaps"; +import Key from "../../shared/settings/Key"; +import KeySequence from "../domains/KeySequence"; +import AddressRepository from "../repositories/AddressRepository"; const reservedKeymaps = Keymaps.fromJSON({ - '<Esc>': { type: operations.CANCEL }, - '<C-[>': { type: operations.CANCEL }, + "<Esc>": { type: operations.CANCEL }, + "<C-[>": { type: operations.CANCEL }, }); const enableAddonOps = [ @@ -21,22 +21,21 @@ const enableAddonOps = [ @injectable() export default class KeymapUseCase { constructor( - @inject('KeymapRepository') + @inject("KeymapRepository") private repository: KeymapRepository, - @inject('SettingRepository') + @inject("SettingRepository") private settingRepository: SettingRepository, - @inject('AddonEnabledRepository') + @inject("AddonEnabledRepository") private addonEnabledRepository: AddonEnabledRepository, - @inject('AddressRepository') - private addressRepository: AddressRepository, - ) { - } + @inject("AddressRepository") + private addressRepository: AddressRepository + ) {} // eslint-disable-next-line max-statements - nextOps(key: Key): { repeat: number, op: operations.Operation } | null { + nextOps(key: Key): { repeat: number; op: operations.Operation } | null { const sequence = this.repository.enqueueKey(key); const baseSequence = sequence.trimNumericPrefix(); const keymaps = this.keymapEntityMap(); @@ -49,14 +48,14 @@ export default class KeymapUseCase { return null; } - if (matched.length === 1 && - sequence.length() === matched[0][0].length()) { + if (matched.length === 1 && sequence.length() === matched[0][0].length()) { // keys are matched with an operation this.repository.clear(); return { repeat: 1, op: matched[0][1] }; } else if ( baseMatched.length === 1 && - baseSequence.length() === baseMatched[0][0].length()) { + baseSequence.length() === baseMatched[0][0].length() + ) { // keys are matched with an operation with a numeric prefix this.repository.clear(); return { repeat: sequence.repeatCount(), op: baseMatched[0][1] }; @@ -75,15 +74,20 @@ export default class KeymapUseCase { } private keymapEntityMap(): [KeySequence, operations.Operation][] { - const keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); - let entries = keymaps.entries().map( - ([keys, op]) => [KeySequence.fromMapKeys(keys), op] - ) as [KeySequence, operations.Operation][]; + const keymaps = this.settingRepository + .get() + .keymaps.combine(reservedKeymaps); + let entries = keymaps + .entries() + .map(([keys, op]) => [KeySequence.fromMapKeys(keys), op]) as [ + KeySequence, + operations.Operation + ][]; if (!this.addonEnabledRepository.get()) { // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if // the addon disabled - entries = entries.filter( - ([_seq, { type }]) => enableAddonOps.includes(type) + entries = entries.filter(([_seq, { type }]) => + enableAddonOps.includes(type) ); } return entries; diff --git a/src/content/usecases/MarkKeyUseCase.ts b/src/content/usecases/MarkKeyUseCase.ts index 6cef6f2..b807c74 100644 --- a/src/content/usecases/MarkKeyUseCase.ts +++ b/src/content/usecases/MarkKeyUseCase.ts @@ -1,12 +1,11 @@ -import { injectable, inject } from 'tsyringe'; -import MarkKeyRepository from '../repositories/MarkKeyRepository'; +import { injectable, inject } from "tsyringe"; +import MarkKeyRepository from "../repositories/MarkKeyRepository"; @injectable() export default class MarkKeyUseCase { constructor( - @inject('MarkKeyRepository') private repository: MarkKeyRepository, - ) { - } + @inject("MarkKeyRepository") private repository: MarkKeyRepository + ) {} isSetMode(): boolean { return this.repository.isSetMode(); diff --git a/src/content/usecases/MarkUseCase.ts b/src/content/usecases/MarkUseCase.ts index 8cd0c72..002fdee 100644 --- a/src/content/usecases/MarkUseCase.ts +++ b/src/content/usecases/MarkUseCase.ts @@ -1,20 +1,19 @@ -import { injectable, inject } from 'tsyringe'; -import ScrollPresenter from '../presenters/ScrollPresenter'; -import MarkClient from '../client/MarkClient'; -import MarkRepository from '../repositories/MarkRepository'; -import SettingRepository from '../repositories/SettingRepository'; -import ConsoleClient from '../client/ConsoleClient'; +import { injectable, inject } from "tsyringe"; +import ScrollPresenter from "../presenters/ScrollPresenter"; +import MarkClient from "../client/MarkClient"; +import MarkRepository from "../repositories/MarkRepository"; +import SettingRepository from "../repositories/SettingRepository"; +import ConsoleClient from "../client/ConsoleClient"; @injectable() export default class MarkUseCase { constructor( - @inject('ScrollPresenter') private scrollPresenter: ScrollPresenter, - @inject('MarkClient') private client: MarkClient, - @inject('MarkRepository') private repository: MarkRepository, - @inject('SettingRepository') private settingRepository: SettingRepository, - @inject('ConsoleClient') private consoleClient: ConsoleClient, - ) { - } + @inject("ScrollPresenter") private scrollPresenter: ScrollPresenter, + @inject("MarkClient") private client: MarkClient, + @inject("MarkRepository") private repository: MarkRepository, + @inject("SettingRepository") private settingRepository: SettingRepository, + @inject("ConsoleClient") private consoleClient: ConsoleClient + ) {} async set(key: string): Promise<void> { const pos = this.scrollPresenter.getScroll(); @@ -33,7 +32,7 @@ export default class MarkUseCase { } else { const pos = this.repository.get(key); if (!pos) { - throw new Error('Mark is not set'); + throw new Error("Mark is not set"); } this.scroll(pos.x, pos.y); } @@ -45,6 +44,6 @@ export default class MarkUseCase { } private globalKey(key: string) { - return (/^[A-Z0-9]$/).test(key); + return /^[A-Z0-9]$/.test(key); } } diff --git a/src/content/usecases/NavigateUseCase.ts b/src/content/usecases/NavigateUseCase.ts index 7adccfd..c704980 100644 --- a/src/content/usecases/NavigateUseCase.ts +++ b/src/content/usecases/NavigateUseCase.ts @@ -1,13 +1,12 @@ -import { injectable, inject } from 'tsyringe'; -import NavigationPresenter from '../presenters/NavigationPresenter'; +import { injectable, inject } from "tsyringe"; +import NavigationPresenter from "../presenters/NavigationPresenter"; @injectable() export default class NavigateUseCase { constructor( - @inject('NavigationPresenter') - private navigationPresenter: NavigationPresenter, - ) { - } + @inject("NavigationPresenter") + private navigationPresenter: NavigationPresenter + ) {} openHistoryPrev(): void { this.navigationPresenter.openHistoryPrev(); diff --git a/src/content/usecases/ScrollUseCase.ts b/src/content/usecases/ScrollUseCase.ts index c68c889..319c8b4 100644 --- a/src/content/usecases/ScrollUseCase.ts +++ b/src/content/usecases/ScrollUseCase.ts @@ -1,14 +1,13 @@ -import { injectable, inject } from 'tsyringe'; -import ScrollPresenter from '../presenters/ScrollPresenter'; -import SettingRepository from '../repositories/SettingRepository'; +import { injectable, inject } from "tsyringe"; +import ScrollPresenter from "../presenters/ScrollPresenter"; +import SettingRepository from "../repositories/SettingRepository"; @injectable() export default class ScrollUseCase { constructor( - @inject('ScrollPresenter') private presenter: ScrollPresenter, - @inject('SettingRepository') private settingRepository: SettingRepository, - ) { - } + @inject("ScrollPresenter") private presenter: ScrollPresenter, + @inject("SettingRepository") private settingRepository: SettingRepository + ) {} scrollVertically(count: number): void { const smooth = this.getSmoothScroll(); diff --git a/src/content/usecases/SettingUseCase.ts b/src/content/usecases/SettingUseCase.ts index 67d1be6..b2b24aa 100644 --- a/src/content/usecases/SettingUseCase.ts +++ b/src/content/usecases/SettingUseCase.ts @@ -1,15 +1,14 @@ -import { injectable, inject } from 'tsyringe'; -import SettingRepository from '../repositories/SettingRepository'; -import SettingClient from '../client/SettingClient'; -import Settings from '../../shared/settings/Settings'; +import { injectable, inject } from "tsyringe"; +import SettingRepository from "../repositories/SettingRepository"; +import SettingClient from "../client/SettingClient"; +import Settings from "../../shared/settings/Settings"; @injectable() export default class SettingUseCase { constructor( - @inject('SettingRepository') private repository: SettingRepository, - @inject('SettingClient') private client: SettingClient, - ) { - } + @inject("SettingRepository") private repository: SettingRepository, + @inject("SettingClient") private client: SettingClient + ) {} async reload(): Promise<Settings> { const settings = await this.client.load(); |