From 36c28a538955c0cd9d94c210372337d7a5c2a01b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 29 Nov 2020 09:31:45 +0900 Subject: extract independent classes --- .../operators/impls/AbstractScrollOperator.ts | 10 ++ .../operators/impls/AddonOperatorFactoryChain.ts | 40 +++++ .../impls/ClipboardOperatorFactoryChain.ts | 43 +++++ .../operators/impls/DisableAddonOperator.ts | 15 ++ src/content/operators/impls/EnableAddonOperator.ts | 15 ++ .../operators/impls/EnableJumpMarkOperator.ts | 10 ++ .../operators/impls/EnableSetMarkOperator.ts | 10 ++ src/content/operators/impls/FindNextOperator.ts | 10 ++ .../operators/impls/FindOperatorFactoryChain.ts | 32 ++++ src/content/operators/impls/FindPrevOperator.ts | 10 ++ src/content/operators/impls/FocusOperator.ts | 10 ++ .../operators/impls/FocusOperatorFactoryChain.ts | 22 +++ .../operators/impls/FollowOperatorFactoryChain.ts | 27 +++ .../operators/impls/HorizontalScrollOperator.ts | 21 +++ .../operators/impls/MarkOperatorFactoryChain.ts | 25 +++ src/content/operators/impls/OperatorFactoryImpl.ts | 14 +- src/content/operators/impls/PageScrollOperator.ts | 21 +++ src/content/operators/impls/PasteOperator.ts | 25 +++ .../operators/impls/ScrollOperatorFactoryChain.ts | 68 ++++++++ .../operators/impls/ScrollToBottomOperator.ts | 20 +++ src/content/operators/impls/ScrollToEndOperator.ts | 20 +++ .../operators/impls/ScrollToHomeOperator.ts | 20 +++ src/content/operators/impls/ScrollToTopOperator.ts | 20 +++ src/content/operators/impls/StartFollowOperator.ts | 14 ++ src/content/operators/impls/ToggleAddonOperator.ts | 16 ++ .../operators/impls/VerticalScrollOperator.ts | 21 +++ src/content/operators/impls/YankURLOperator.ts | 16 ++ src/content/operators/impls/addons.ts | 74 --------- src/content/operators/impls/clipboard.ts | 74 --------- src/content/operators/impls/find.ts | 45 ----- src/content/operators/impls/focus.ts | 29 ---- src/content/operators/impls/follow.ts | 37 ----- src/content/operators/impls/mark.ts | 39 ----- src/content/operators/impls/scroll.ts | 183 --------------------- 34 files changed, 568 insertions(+), 488 deletions(-) create mode 100644 src/content/operators/impls/AbstractScrollOperator.ts create mode 100644 src/content/operators/impls/AddonOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/ClipboardOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/DisableAddonOperator.ts create mode 100644 src/content/operators/impls/EnableAddonOperator.ts create mode 100644 src/content/operators/impls/EnableJumpMarkOperator.ts create mode 100644 src/content/operators/impls/EnableSetMarkOperator.ts create mode 100644 src/content/operators/impls/FindNextOperator.ts create mode 100644 src/content/operators/impls/FindOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/FindPrevOperator.ts create mode 100644 src/content/operators/impls/FocusOperator.ts create mode 100644 src/content/operators/impls/FocusOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/FollowOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/HorizontalScrollOperator.ts create mode 100644 src/content/operators/impls/MarkOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/PageScrollOperator.ts create mode 100644 src/content/operators/impls/PasteOperator.ts create mode 100644 src/content/operators/impls/ScrollOperatorFactoryChain.ts create mode 100644 src/content/operators/impls/ScrollToBottomOperator.ts create mode 100644 src/content/operators/impls/ScrollToEndOperator.ts create mode 100644 src/content/operators/impls/ScrollToHomeOperator.ts create mode 100644 src/content/operators/impls/ScrollToTopOperator.ts create mode 100644 src/content/operators/impls/StartFollowOperator.ts create mode 100644 src/content/operators/impls/ToggleAddonOperator.ts create mode 100644 src/content/operators/impls/VerticalScrollOperator.ts create mode 100644 src/content/operators/impls/YankURLOperator.ts delete mode 100644 src/content/operators/impls/addons.ts delete mode 100644 src/content/operators/impls/clipboard.ts delete mode 100644 src/content/operators/impls/find.ts delete mode 100644 src/content/operators/impls/focus.ts delete mode 100644 src/content/operators/impls/follow.ts delete mode 100644 src/content/operators/impls/mark.ts delete mode 100644 src/content/operators/impls/scroll.ts (limited to 'src') diff --git a/src/content/operators/impls/AbstractScrollOperator.ts b/src/content/operators/impls/AbstractScrollOperator.ts new file mode 100644 index 0000000..f8d9f70 --- /dev/null +++ b/src/content/operators/impls/AbstractScrollOperator.ts @@ -0,0 +1,10 @@ +import SettingRepository from "../../repositories/SettingRepository"; + +export default class AbstractScrollOperator { + constructor(private readonly settingRepository: SettingRepository) {} + + protected getSmoothScroll(): boolean { + const settings = this.settingRepository.get(); + return settings.properties.smoothscroll; + } +} diff --git a/src/content/operators/impls/AddonOperatorFactoryChain.ts b/src/content/operators/impls/AddonOperatorFactoryChain.ts new file mode 100644 index 0000000..54880c4 --- /dev/null +++ b/src/content/operators/impls/AddonOperatorFactoryChain.ts @@ -0,0 +1,40 @@ +import { inject, injectable } from "tsyringe"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import AddonIndicatorClient from "../../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; +import * as operations from "../../../shared/operations"; +import Operator from "../Operator"; +import EnableAddonOperator from "./EnableAddonOperator"; +import DisableAddonOperator from "./DisableAddonOperator"; +import ToggleAddonOperator from "./ToggleAddonOperator"; + +@injectable() +export default class AddonOperatorFactoryChain implements OperatorFactoryChain { + constructor( + @inject("AddonIndicatorClient") + private readonly addonIndicatorClient: AddonIndicatorClient, + @inject("AddonEnabledRepository") + private readonly addonEnabledRepository: AddonEnabledRepository + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.ADDON_ENABLE: + return new EnableAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + case operations.ADDON_DISABLE: + return new DisableAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + case operations.ADDON_TOGGLE_ENABLED: + return new ToggleAddonOperator( + this.addonIndicatorClient, + this.addonEnabledRepository + ); + } + return null; + } +} diff --git a/src/content/operators/impls/ClipboardOperatorFactoryChain.ts b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts new file mode 100644 index 0000000..fb12ae8 --- /dev/null +++ b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts @@ -0,0 +1,43 @@ +import { inject, injectable } from "tsyringe"; +import YankURLOperator from "./YankURLOperator"; +import PasteOperator from "./PasteOperator"; +import Operator from "../Operator"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import ClipboardRepository from "../../repositories/ClipboardRepository"; +import ConsoleClient from "../../client/ConsoleClient"; +import OperationClient from "../../client/OperationClient"; +import SettingRepository from "../../repositories/SettingRepository"; +import * as operations from "../../../shared/operations"; + +@injectable() +export default class ClipboardOperatorFactoryChain + implements OperatorFactoryChain { + constructor( + @inject("ClipboardRepository") + private readonly clipboardRepository: ClipboardRepository, + @inject("ConsoleClient") + private readonly consoleClient: ConsoleClient, + @inject("OperationClient") + private readonly operationClinet: OperationClient, + @inject("SettingRepository") + private readonly settingRepository: SettingRepository + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.URLS_YANK: + return new YankURLOperator( + this.clipboardRepository, + this.consoleClient + ); + case operations.URLS_PASTE: + return new PasteOperator( + this.clipboardRepository, + this.settingRepository, + this.operationClinet, + op.newTab + ); + } + return null; + } +} diff --git a/src/content/operators/impls/DisableAddonOperator.ts b/src/content/operators/impls/DisableAddonOperator.ts new file mode 100644 index 0000000..28811fe --- /dev/null +++ b/src/content/operators/impls/DisableAddonOperator.ts @@ -0,0 +1,15 @@ +import Operator from "../Operator"; +import AddonIndicatorClient from "../../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; + +export default class DisableAddonOperator implements Operator { + constructor( + private readonly indicator: AddonIndicatorClient, + private readonly repository: AddonEnabledRepository + ) {} + + async run(): Promise { + this.repository.set(false); + await this.indicator.setEnabled(false); + } +} diff --git a/src/content/operators/impls/EnableAddonOperator.ts b/src/content/operators/impls/EnableAddonOperator.ts new file mode 100644 index 0000000..b5b1d79 --- /dev/null +++ b/src/content/operators/impls/EnableAddonOperator.ts @@ -0,0 +1,15 @@ +import Operator from "../Operator"; +import AddonIndicatorClient from "../../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; + +export default class EnableAddonOperator implements Operator { + constructor( + private readonly indicator: AddonIndicatorClient, + private readonly repository: AddonEnabledRepository + ) {} + + async run(): Promise { + this.repository.set(true); + await this.indicator.setEnabled(true); + } +} diff --git a/src/content/operators/impls/EnableJumpMarkOperator.ts b/src/content/operators/impls/EnableJumpMarkOperator.ts new file mode 100644 index 0000000..42ca8ee --- /dev/null +++ b/src/content/operators/impls/EnableJumpMarkOperator.ts @@ -0,0 +1,10 @@ +import Operator from "../Operator"; +import MarkKeyRepository from "../../repositories/MarkKeyRepository"; + +export default class EnableJumpMarkOperator implements Operator { + constructor(private readonly repository: MarkKeyRepository) {} + + async run(): Promise { + this.repository.enableJumpMode(); + } +} diff --git a/src/content/operators/impls/EnableSetMarkOperator.ts b/src/content/operators/impls/EnableSetMarkOperator.ts new file mode 100644 index 0000000..3d0daf4 --- /dev/null +++ b/src/content/operators/impls/EnableSetMarkOperator.ts @@ -0,0 +1,10 @@ +import Operator from "../Operator"; +import MarkKeyRepository from "../../repositories/MarkKeyRepository"; + +export default class EnableSetMarkOperator implements Operator { + constructor(private readonly repository: MarkKeyRepository) {} + + async run(): Promise { + this.repository.enableSetMode(); + } +} diff --git a/src/content/operators/impls/FindNextOperator.ts b/src/content/operators/impls/FindNextOperator.ts new file mode 100644 index 0000000..723db3d --- /dev/null +++ b/src/content/operators/impls/FindNextOperator.ts @@ -0,0 +1,10 @@ +import Operator from "../Operator"; +import FindMasterClient from "../../client/FindMasterClient"; + +export default class FindNextOperator implements Operator { + constructor(private readonly findMasterClient: FindMasterClient) {} + + async run(): Promise { + this.findMasterClient.findNext(); + } +} diff --git a/src/content/operators/impls/FindOperatorFactoryChain.ts b/src/content/operators/impls/FindOperatorFactoryChain.ts new file mode 100644 index 0000000..ef1c754 --- /dev/null +++ b/src/content/operators/impls/FindOperatorFactoryChain.ts @@ -0,0 +1,32 @@ +import { inject, injectable } from "tsyringe"; +import Operator from "../Operator"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import RepeatOperator from "./RepeatOperator"; +import FindNextOperator from "./FindNextOperator"; +import FindPrevOperator from "./FindPrevOperator"; +import FindMasterClient from "../../client/FindMasterClient"; +import * as operations from "../../../shared/operations"; + +@injectable() +export default class FindOperatorFactoryChain implements OperatorFactoryChain { + constructor( + @inject("FindMasterClient") + private readonly findMasterClient: FindMasterClient + ) {} + + create(op: operations.Operation, repeat: number): Operator | null { + switch (op.type) { + case operations.FIND_NEXT: + return new RepeatOperator( + new FindNextOperator(this.findMasterClient), + repeat + ); + case operations.FIND_PREV: + return new RepeatOperator( + new FindPrevOperator(this.findMasterClient), + repeat + ); + } + return null; + } +} diff --git a/src/content/operators/impls/FindPrevOperator.ts b/src/content/operators/impls/FindPrevOperator.ts new file mode 100644 index 0000000..be6a01e --- /dev/null +++ b/src/content/operators/impls/FindPrevOperator.ts @@ -0,0 +1,10 @@ +import Operator from "../Operator"; +import FindMasterClient from "../../client/FindMasterClient"; + +export default class FindPrevOperator implements Operator { + constructor(private readonly findMasterClient: FindMasterClient) {} + + async run(): Promise { + this.findMasterClient.findPrev(); + } +} diff --git a/src/content/operators/impls/FocusOperator.ts b/src/content/operators/impls/FocusOperator.ts new file mode 100644 index 0000000..51d6fec --- /dev/null +++ b/src/content/operators/impls/FocusOperator.ts @@ -0,0 +1,10 @@ +import Operator from "../Operator"; +import FocusPresenter from "../../presenters/FocusPresenter"; + +export default class FocusOperator implements Operator { + constructor(private readonly presenter: FocusPresenter) {} + + async run(): Promise { + this.presenter.focusFirstElement(); + } +} diff --git a/src/content/operators/impls/FocusOperatorFactoryChain.ts b/src/content/operators/impls/FocusOperatorFactoryChain.ts new file mode 100644 index 0000000..c89c1e5 --- /dev/null +++ b/src/content/operators/impls/FocusOperatorFactoryChain.ts @@ -0,0 +1,22 @@ +import { inject, injectable } from "tsyringe"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import Operator from "../Operator"; +import FocusOperator from "./FocusOperator"; +import FocusPresenter from "../../presenters/FocusPresenter"; +import * as operations from "../../../shared/operations"; + +@injectable() +export default class FocusOperatorFactoryChain implements OperatorFactoryChain { + constructor( + @inject("FocusPresenter") + private readonly focusPresenter: FocusPresenter + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.FOCUS_INPUT: + return new FocusOperator(this.focusPresenter); + } + return null; + } +} diff --git a/src/content/operators/impls/FollowOperatorFactoryChain.ts b/src/content/operators/impls/FollowOperatorFactoryChain.ts new file mode 100644 index 0000000..588e1a4 --- /dev/null +++ b/src/content/operators/impls/FollowOperatorFactoryChain.ts @@ -0,0 +1,27 @@ +import { inject, injectable } from "tsyringe"; +import StartFollowOperator from "./StartFollowOperator"; +import Operator from "../Operator"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import FollowMasterClient from "../../client/FollowMasterClient"; +import * as operations from "../../../shared/operations"; + +@injectable() +export default class FollowOperatorFactoryChain + implements OperatorFactoryChain { + constructor( + @inject("FollowMasterClient") + private followMasterClient: FollowMasterClient + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.FOLLOW_START: + return new StartFollowOperator( + this.followMasterClient, + op.newTab, + op.background + ); + } + return null; + } +} diff --git a/src/content/operators/impls/HorizontalScrollOperator.ts b/src/content/operators/impls/HorizontalScrollOperator.ts new file mode 100644 index 0000000..f813f85 --- /dev/null +++ b/src/content/operators/impls/HorizontalScrollOperator.ts @@ -0,0 +1,21 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class HorizontalScrollOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository, + private readonly count: number + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollHorizonally(this.count, smooth); + } +} diff --git a/src/content/operators/impls/MarkOperatorFactoryChain.ts b/src/content/operators/impls/MarkOperatorFactoryChain.ts new file mode 100644 index 0000000..7e6c513 --- /dev/null +++ b/src/content/operators/impls/MarkOperatorFactoryChain.ts @@ -0,0 +1,25 @@ +import { inject, injectable } from "tsyringe"; +import EnableSetMarkOperator from "./EnableSetMarkOperator"; +import EnableJumpMarkOperator from "./EnableJumpMarkOperator"; +import Operator from "../Operator"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import MarkKeyRepository from "../../repositories/MarkKeyRepository"; +import * as operations from "../../../shared/operations"; + +@injectable() +export default class MarkOperatorFactoryChain implements OperatorFactoryChain { + constructor( + @inject("MarkKeyRepository") + private readonly markKeyRepository: MarkKeyRepository + ) {} + + create(op: operations.Operation, _repeat: number): Operator | null { + switch (op.type) { + case operations.MARK_SET_PREFIX: + return new EnableSetMarkOperator(this.markKeyRepository); + case operations.MARK_JUMP_PREFIX: + return new EnableJumpMarkOperator(this.markKeyRepository); + } + return null; + } +} diff --git a/src/content/operators/impls/OperatorFactoryImpl.ts b/src/content/operators/impls/OperatorFactoryImpl.ts index f1aa3bc..22b35c8 100644 --- a/src/content/operators/impls/OperatorFactoryImpl.ts +++ b/src/content/operators/impls/OperatorFactoryImpl.ts @@ -1,17 +1,17 @@ import { inject, injectable } from "tsyringe"; import OperatorFactory from "../OperatorFactory"; -import { AddonOperatorFactoryChain } from "./addons"; -import { ClipboardOperatorFactoryChain } from "./clipboard"; -import { FindOperatorFactoryChain } from "./find"; -import { FocusOperatorFactoryChain } from "./focus"; -import { MarkOperatorFactoryChain } from "./mark"; -import { ScrollOperatorFactoryChain } from "./scroll"; -import { FollowOperatorFactoryChain } from "./follow"; import BackgroundOperationOperator from "./BackgroundOperationOperator"; import Operator from "../Operator"; import OperatorFactoryChain from "../OperatorFactoryChain"; import { Operation } from "../../../shared/operations"; import OperationClient from "../../client/OperationClient"; +import AddonOperatorFactoryChain from "./AddonOperatorFactoryChain"; +import ClipboardOperatorFactoryChain from "./ClipboardOperatorFactoryChain"; +import FindOperatorFactoryChain from "./FindOperatorFactoryChain"; +import FocusOperatorFactoryChain from "./FocusOperatorFactoryChain"; +import FollowOperatorFactoryChain from "./FollowOperatorFactoryChain"; +import MarkOperatorFactoryChain from "./MarkOperatorFactoryChain"; +import ScrollOperatorFactoryChain from "./ScrollOperatorFactoryChain"; @injectable() export default class OperatorFactoryImpl implements OperatorFactory { diff --git a/src/content/operators/impls/PageScrollOperator.ts b/src/content/operators/impls/PageScrollOperator.ts new file mode 100644 index 0000000..377bf92 --- /dev/null +++ b/src/content/operators/impls/PageScrollOperator.ts @@ -0,0 +1,21 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class PageScrollOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository, + private readonly count: number + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollPages(this.count, smooth); + } +} diff --git a/src/content/operators/impls/PasteOperator.ts b/src/content/operators/impls/PasteOperator.ts new file mode 100644 index 0000000..592da66 --- /dev/null +++ b/src/content/operators/impls/PasteOperator.ts @@ -0,0 +1,25 @@ +import Operator from "../Operator"; +import ClipboardRepository from "../../repositories/ClipboardRepository"; +import SettingRepository from "../../repositories/SettingRepository"; +import OperationClient from "../../client/OperationClient"; +import * as urls from "../../../shared/urls"; + +export default class PasteOperator implements Operator { + constructor( + private readonly repository: ClipboardRepository, + private readonly settingRepository: SettingRepository, + private readonly operationClient: OperationClient, + private readonly newTab: boolean + ) {} + + async run(): Promise { + const search = this.settingRepository.get().search; + const text = this.repository.read(); + const url = urls.searchUrl(text, search); + + // NOTE: Repeat pasting from clipboard instead of opening a certain url. + // 'Repeat last' command is implemented in the background script and cannot + // access to clipboard until Firefox 63. + await this.operationClient.internalOpenUrl(url, this.newTab); + } +} diff --git a/src/content/operators/impls/ScrollOperatorFactoryChain.ts b/src/content/operators/impls/ScrollOperatorFactoryChain.ts new file mode 100644 index 0000000..6847aea --- /dev/null +++ b/src/content/operators/impls/ScrollOperatorFactoryChain.ts @@ -0,0 +1,68 @@ +import { inject, injectable } from "tsyringe"; +import OperatorFactoryChain from "../OperatorFactoryChain"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; +import * as operations from "../../../shared/operations"; +import Operator from "../Operator"; +import VerticalScrollOperator from "./VerticalScrollOperator"; +import HorizontalScrollOperator from "./HorizontalScrollOperator"; +import PageScrollOperator from "./PageScrollOperator"; +import ScrollToTopOperator from "./ScrollToTopOperator"; +import ScrollToBottomOperator from "./ScrollToBottomOperator"; +import ScrollToHomeOperator from "./ScrollToHomeOperator"; +import ScrollToEndOperator from "./ScrollToEndOperator"; + +@injectable() +export default class ScrollOperatorFactoryChain + implements OperatorFactoryChain { + constructor( + @inject("ScrollPresenter") + private readonly scrollPresenter: ScrollPresenter, + @inject("SettingRepository") + private readonly settingRepository: SettingRepository + ) {} + + create(op: operations.Operation, repeat: number): Operator | null { + switch (op.type) { + case operations.SCROLL_VERTICALLY: + return new VerticalScrollOperator( + this.scrollPresenter, + this.settingRepository, + op.count * repeat + ); + case operations.SCROLL_HORIZONALLY: + return new HorizontalScrollOperator( + this.scrollPresenter, + this.settingRepository, + op.count * repeat + ); + case operations.SCROLL_PAGES: + return new PageScrollOperator( + this.scrollPresenter, + this.settingRepository, + op.count * repeat + ); + case operations.SCROLL_TOP: + return new ScrollToTopOperator( + this.scrollPresenter, + this.settingRepository + ); + case operations.SCROLL_BOTTOM: + return new ScrollToBottomOperator( + this.scrollPresenter, + this.settingRepository + ); + case operations.SCROLL_HOME: + return new ScrollToHomeOperator( + this.scrollPresenter, + this.settingRepository + ); + case operations.SCROLL_END: + return new ScrollToEndOperator( + this.scrollPresenter, + this.settingRepository + ); + } + return null; + } +} diff --git a/src/content/operators/impls/ScrollToBottomOperator.ts b/src/content/operators/impls/ScrollToBottomOperator.ts new file mode 100644 index 0000000..4db521b --- /dev/null +++ b/src/content/operators/impls/ScrollToBottomOperator.ts @@ -0,0 +1,20 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class ScrollToBottomOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollToBottom(smooth); + } +} diff --git a/src/content/operators/impls/ScrollToEndOperator.ts b/src/content/operators/impls/ScrollToEndOperator.ts new file mode 100644 index 0000000..8217e15 --- /dev/null +++ b/src/content/operators/impls/ScrollToEndOperator.ts @@ -0,0 +1,20 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class ScrollToEndOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollToEnd(smooth); + } +} diff --git a/src/content/operators/impls/ScrollToHomeOperator.ts b/src/content/operators/impls/ScrollToHomeOperator.ts new file mode 100644 index 0000000..a0d7701 --- /dev/null +++ b/src/content/operators/impls/ScrollToHomeOperator.ts @@ -0,0 +1,20 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class ScrollToHomeOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollToHome(smooth); + } +} diff --git a/src/content/operators/impls/ScrollToTopOperator.ts b/src/content/operators/impls/ScrollToTopOperator.ts new file mode 100644 index 0000000..6075758 --- /dev/null +++ b/src/content/operators/impls/ScrollToTopOperator.ts @@ -0,0 +1,20 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class ScrollToTopOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollToTop(smooth); + } +} diff --git a/src/content/operators/impls/StartFollowOperator.ts b/src/content/operators/impls/StartFollowOperator.ts new file mode 100644 index 0000000..6f30058 --- /dev/null +++ b/src/content/operators/impls/StartFollowOperator.ts @@ -0,0 +1,14 @@ +import Operator from "../Operator"; +import FollowMasterClient from "../../client/FollowMasterClient"; + +export default class StartFollowOperator implements Operator { + constructor( + private readonly followMasterClient: FollowMasterClient, + private readonly newTab: boolean, + private readonly background: boolean + ) {} + + async run(): Promise { + this.followMasterClient.startFollow(this.newTab, this.background); + } +} diff --git a/src/content/operators/impls/ToggleAddonOperator.ts b/src/content/operators/impls/ToggleAddonOperator.ts new file mode 100644 index 0000000..2a249d6 --- /dev/null +++ b/src/content/operators/impls/ToggleAddonOperator.ts @@ -0,0 +1,16 @@ +import Operator from "../Operator"; +import AddonIndicatorClient from "../../client/AddonIndicatorClient"; +import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; + +export default class ToggleAddonOperator implements Operator { + constructor( + private readonly indicator: AddonIndicatorClient, + private readonly repository: AddonEnabledRepository + ) {} + + async run(): Promise { + const current = this.repository.get(); + this.repository.set(!current); + await this.indicator.setEnabled(!current); + } +} diff --git a/src/content/operators/impls/VerticalScrollOperator.ts b/src/content/operators/impls/VerticalScrollOperator.ts new file mode 100644 index 0000000..4ab336c --- /dev/null +++ b/src/content/operators/impls/VerticalScrollOperator.ts @@ -0,0 +1,21 @@ +import AbstractScrollOperator from "./AbstractScrollOperator"; +import Operator from "../Operator"; +import ScrollPresenter from "../../presenters/ScrollPresenter"; +import SettingRepository from "../../repositories/SettingRepository"; + +export default class VerticalScrollOperator + extends AbstractScrollOperator + implements Operator { + constructor( + private readonly presenter: ScrollPresenter, + settingRepository: SettingRepository, + private readonly count: number + ) { + super(settingRepository); + } + + async run(): Promise { + const smooth = this.getSmoothScroll(); + this.presenter.scrollVertically(this.count, smooth); + } +} diff --git a/src/content/operators/impls/YankURLOperator.ts b/src/content/operators/impls/YankURLOperator.ts new file mode 100644 index 0000000..5e2ac60 --- /dev/null +++ b/src/content/operators/impls/YankURLOperator.ts @@ -0,0 +1,16 @@ +import Operator from "../Operator"; +import ClipboardRepository from "../../repositories/ClipboardRepository"; +import ConsoleClient from "../../client/ConsoleClient"; + +export default class YankURLOperator implements Operator { + constructor( + private readonly repository: ClipboardRepository, + private readonly consoleClient: ConsoleClient + ) {} + + async run(): Promise { + const url = window.location.href; + this.repository.write(url); + await this.consoleClient.info("Yanked " + url); + } +} diff --git a/src/content/operators/impls/addons.ts b/src/content/operators/impls/addons.ts deleted file mode 100644 index 959da43..0000000 --- a/src/content/operators/impls/addons.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import AddonIndicatorClient from "../../client/AddonIndicatorClient"; -import AddonEnabledRepository from "../../repositories/AddonEnabledRepository"; -import * as operations from "../../../shared/operations"; - -export class EnableAddonOperator implements Operator { - constructor( - private readonly indicator: AddonIndicatorClient, - private readonly repository: AddonEnabledRepository - ) {} - - async run(): Promise { - this.repository.set(true); - await this.indicator.setEnabled(true); - } -} - -export class DisableAddonOperator implements Operator { - constructor( - private readonly indicator: AddonIndicatorClient, - private readonly repository: AddonEnabledRepository - ) {} - - async run(): Promise { - this.repository.set(false); - await this.indicator.setEnabled(false); - } -} - -export class ToggleAddonOperator implements Operator { - constructor( - private readonly indicator: AddonIndicatorClient, - private readonly repository: AddonEnabledRepository - ) {} - - async run(): Promise { - const current = this.repository.get(); - this.repository.set(!current); - await this.indicator.setEnabled(!current); - } -} - -@injectable() -export class AddonOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("AddonIndicatorClient") - private readonly addonIndicatorClient: AddonIndicatorClient, - @inject("AddonEnabledRepository") - private readonly addonEnabledRepository: AddonEnabledRepository - ) {} - - create(op: operations.Operation, _repeat: number): Operator | null { - switch (op.type) { - case operations.ADDON_ENABLE: - return new EnableAddonOperator( - this.addonIndicatorClient, - this.addonEnabledRepository - ); - case operations.ADDON_DISABLE: - return new DisableAddonOperator( - this.addonIndicatorClient, - this.addonEnabledRepository - ); - case operations.ADDON_TOGGLE_ENABLED: - return new ToggleAddonOperator( - this.addonIndicatorClient, - this.addonEnabledRepository - ); - } - return null; - } -} diff --git a/src/content/operators/impls/clipboard.ts b/src/content/operators/impls/clipboard.ts deleted file mode 100644 index 26bdba0..0000000 --- a/src/content/operators/impls/clipboard.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import ClipboardRepository from "../../repositories/ClipboardRepository"; -import SettingRepository from "../../repositories/SettingRepository"; -import ConsoleClient from "../../client/ConsoleClient"; -import OperationClient from "../../client/OperationClient"; -import * as urls from "../../../shared/urls"; -import * as operations from "../../../shared/operations"; - -export class YankURLOperator implements Operator { - constructor( - private readonly repository: ClipboardRepository, - private readonly consoleClient: ConsoleClient - ) {} - - async run(): Promise { - const url = window.location.href; - this.repository.write(url); - await this.consoleClient.info("Yanked " + url); - } -} - -export class PasteOperator implements Operator { - constructor( - private readonly repository: ClipboardRepository, - private readonly settingRepository: SettingRepository, - private readonly operationClient: OperationClient, - private readonly newTab: boolean - ) {} - - async run(): Promise { - const search = this.settingRepository.get().search; - const text = this.repository.read(); - const url = urls.searchUrl(text, search); - - // NOTE: Repeat pasting from clipboard instead of opening a certain url. - // 'Repeat last' command is implemented in the background script and cannot - // access to clipboard until Firefox 63. - await this.operationClient.internalOpenUrl(url, this.newTab); - } -} - -@injectable() -export class ClipboardOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("ClipboardRepository") - private readonly clipboardRepository: ClipboardRepository, - @inject("ConsoleClient") - private readonly consoleClient: ConsoleClient, - @inject("OperationClient") - private readonly operationClinet: OperationClient, - @inject("SettingRepository") - private readonly settingRepository: SettingRepository - ) {} - - create(op: operations.Operation, _repeat: number): Operator | null { - switch (op.type) { - case operations.URLS_YANK: - return new YankURLOperator( - this.clipboardRepository, - this.consoleClient - ); - case operations.URLS_PASTE: - return new PasteOperator( - this.clipboardRepository, - this.settingRepository, - this.operationClinet, - op.newTab - ); - } - return null; - } -} diff --git a/src/content/operators/impls/find.ts b/src/content/operators/impls/find.ts deleted file mode 100644 index 82310bc..0000000 --- a/src/content/operators/impls/find.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import RepeatOperator from "./RepeatOperator"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import FindMasterClient from "../../client/FindMasterClient"; -import * as operations from "../../../shared/operations"; - -export class FindNextOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} - - async run(): Promise { - this.findMasterClient.findNext(); - } -} - -export class FindPrevOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} - - async run(): Promise { - this.findMasterClient.findPrev(); - } -} - -@injectable() -export class FindOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("FindMasterClient") - private readonly findMasterClient: FindMasterClient - ) {} - create(op: operations.Operation, repeat: number): Operator | null { - switch (op.type) { - case operations.FIND_NEXT: - return new RepeatOperator( - new FindNextOperator(this.findMasterClient), - repeat - ); - case operations.FIND_PREV: - return new RepeatOperator( - new FindPrevOperator(this.findMasterClient), - repeat - ); - } - return null; - } -} diff --git a/src/content/operators/impls/focus.ts b/src/content/operators/impls/focus.ts deleted file mode 100644 index ea8e27d..0000000 --- a/src/content/operators/impls/focus.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import FocusPresenter from "../../presenters/FocusPresenter"; -import * as operations from "../../../shared/operations"; - -export class FocusOperator implements Operator { - constructor(private readonly presenter: FocusPresenter) {} - - async run(): Promise { - this.presenter.focusFirstElement(); - } -} - -@injectable() -export class FocusOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("FocusPresenter") - private readonly focusPresenter: FocusPresenter - ) {} - - create(op: operations.Operation, _repeat: number): Operator | null { - switch (op.type) { - case operations.FOCUS_INPUT: - return new FocusOperator(this.focusPresenter); - } - return null; - } -} diff --git a/src/content/operators/impls/follow.ts b/src/content/operators/impls/follow.ts deleted file mode 100644 index 6d3fadc..0000000 --- a/src/content/operators/impls/follow.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import FollowMasterClient from "../../client/FollowMasterClient"; -import * as operations from "../../../shared/operations"; - -export class StartFollowOperator implements Operator { - constructor( - private readonly followMasterClient: FollowMasterClient, - private readonly newTab: boolean, - private readonly background: boolean - ) {} - - async run(): Promise { - this.followMasterClient.startFollow(this.newTab, this.background); - } -} - -@injectable() -export class FollowOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("FollowMasterClient") - private followMasterClient: FollowMasterClient - ) {} - - create(op: operations.Operation, _repeat: number): Operator | null { - switch (op.type) { - case operations.FOLLOW_START: - return new StartFollowOperator( - this.followMasterClient, - op.newTab, - op.background - ); - } - return null; - } -} diff --git a/src/content/operators/impls/mark.ts b/src/content/operators/impls/mark.ts deleted file mode 100644 index d90aba9..0000000 --- a/src/content/operators/impls/mark.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import MarkKeyRepository from "../../repositories/MarkKeyRepository"; -import * as operations from "../../../shared/operations"; - -export class EnableSetMarkOperator implements Operator { - constructor(private readonly repository: MarkKeyRepository) {} - - async run(): Promise { - this.repository.enableSetMode(); - } -} - -export class EnableJumpMarkOperator implements Operator { - constructor(private readonly repository: MarkKeyRepository) {} - - async run(): Promise { - this.repository.enableJumpMode(); - } -} - -@injectable() -export class MarkOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("MarkKeyRepository") - private readonly markKeyRepository: MarkKeyRepository - ) {} - - create(op: operations.Operation, _repeat: number): Operator | null { - switch (op.type) { - case operations.MARK_SET_PREFIX: - return new EnableSetMarkOperator(this.markKeyRepository); - case operations.MARK_JUMP_PREFIX: - return new EnableJumpMarkOperator(this.markKeyRepository); - } - return null; - } -} diff --git a/src/content/operators/impls/scroll.ts b/src/content/operators/impls/scroll.ts deleted file mode 100644 index 96963be..0000000 --- a/src/content/operators/impls/scroll.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import ScrollPresenter from "../../presenters/ScrollPresenter"; -import SettingRepository from "../../repositories/SettingRepository"; -import * as operations from "../../../shared/operations"; - -class AbstractScrollOperator { - constructor(private readonly settingRepository: SettingRepository) {} - - protected getSmoothScroll(): boolean { - const settings = this.settingRepository.get(); - return settings.properties.smoothscroll; - } -} - -export class VerticalScrollOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository, - private readonly count: number - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollVertically(this.count, smooth); - } -} - -export class HorizonalScrollOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository, - private readonly count: number - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollHorizonally(this.count, smooth); - } -} - -export class PageScrollOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository, - private readonly count: number - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollPages(this.count, smooth); - } -} - -export class ScrollToTopOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollToTop(smooth); - } -} - -export class ScrollToBottomOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollToBottom(smooth); - } -} - -export class ScrollToHomeOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollToHome(smooth); - } -} - -export class ScrollToEndOperator - extends AbstractScrollOperator - implements Operator { - constructor( - private readonly presenter: ScrollPresenter, - settingRepository: SettingRepository - ) { - super(settingRepository); - } - - async run(): Promise { - const smooth = this.getSmoothScroll(); - this.presenter.scrollToEnd(smooth); - } -} - -@injectable() -export class ScrollOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("ScrollPresenter") - private readonly scrollPresenter: ScrollPresenter, - @inject("SettingRepository") - private readonly settingRepository: SettingRepository - ) {} - create(op: operations.Operation, repeat: number): Operator | null { - switch (op.type) { - case operations.SCROLL_VERTICALLY: - return new VerticalScrollOperator( - this.scrollPresenter, - this.settingRepository, - op.count * repeat - ); - case operations.SCROLL_HORIZONALLY: - return new HorizonalScrollOperator( - this.scrollPresenter, - this.settingRepository, - op.count * repeat - ); - case operations.SCROLL_PAGES: - return new PageScrollOperator( - this.scrollPresenter, - this.settingRepository, - op.count * repeat - ); - case operations.SCROLL_TOP: - return new ScrollToTopOperator( - this.scrollPresenter, - this.settingRepository - ); - case operations.SCROLL_BOTTOM: - return new ScrollToBottomOperator( - this.scrollPresenter, - this.settingRepository - ); - case operations.SCROLL_HOME: - return new ScrollToHomeOperator( - this.scrollPresenter, - this.settingRepository - ); - case operations.SCROLL_END: - return new ScrollToEndOperator( - this.scrollPresenter, - this.settingRepository - ); - } - return null; - } -} -- cgit v1.2.3