diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-11-29 09:31:45 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-12-09 23:09:34 +0900 |
commit | 36c28a538955c0cd9d94c210372337d7a5c2a01b (patch) | |
tree | be12ff6abed9443cfedcb3ab1564ee8562e33858 /src | |
parent | 809bdb11f3d213254c098411755631b1264c52f0 (diff) |
extract independent classes
Diffstat (limited to 'src')
28 files changed, 403 insertions, 323 deletions
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/addons.ts b/src/content/operators/impls/AddonOperatorFactoryChain.ts index 959da43..54880c4 100644 --- a/src/content/operators/impls/addons.ts +++ b/src/content/operators/impls/AddonOperatorFactoryChain.ts @@ -1,49 +1,15 @@ 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<void> { - 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<void> { - 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<void> { - const current = this.repository.get(); - this.repository.set(!current); - await this.indicator.setEnabled(!current); - } -} +import Operator from "../Operator"; +import EnableAddonOperator from "./EnableAddonOperator"; +import DisableAddonOperator from "./DisableAddonOperator"; +import ToggleAddonOperator from "./ToggleAddonOperator"; @injectable() -export class AddonOperatorFactoryChain implements OperatorFactoryChain { +export default class AddonOperatorFactoryChain implements OperatorFactoryChain { constructor( @inject("AddonIndicatorClient") private readonly addonIndicatorClient: AddonIndicatorClient, diff --git a/src/content/operators/impls/clipboard.ts b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts index 26bdba0..fb12ae8 100644 --- a/src/content/operators/impls/clipboard.ts +++ b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts @@ -1,48 +1,17 @@ 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 SettingRepository from "../../repositories/SettingRepository"; import ConsoleClient from "../../client/ConsoleClient"; import OperationClient from "../../client/OperationClient"; -import * as urls from "../../../shared/urls"; +import SettingRepository from "../../repositories/SettingRepository"; import * as operations from "../../../shared/operations"; -export class YankURLOperator implements Operator { - constructor( - private readonly repository: ClipboardRepository, - private readonly consoleClient: ConsoleClient - ) {} - - async run(): Promise<void> { - 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<void> { - 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 { +export default class ClipboardOperatorFactoryChain + implements OperatorFactoryChain { constructor( @inject("ClipboardRepository") private readonly clipboardRepository: ClipboardRepository, 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + this.findMasterClient.findNext(); + } +} diff --git a/src/content/operators/impls/find.ts b/src/content/operators/impls/FindOperatorFactoryChain.ts index 82310bc..ef1c754 100644 --- a/src/content/operators/impls/find.ts +++ b/src/content/operators/impls/FindOperatorFactoryChain.ts @@ -1,32 +1,19 @@ import { inject, injectable } from "tsyringe"; -import RepeatOperator from "./RepeatOperator"; 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"; -export class FindNextOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} - - async run(): Promise<void> { - this.findMasterClient.findNext(); - } -} - -export class FindPrevOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} - - async run(): Promise<void> { - this.findMasterClient.findPrev(); - } -} - @injectable() -export class FindOperatorFactoryChain implements OperatorFactoryChain { +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: 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<void> { + 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<void> { + this.presenter.focusFirstElement(); + } +} diff --git a/src/content/operators/impls/focus.ts b/src/content/operators/impls/FocusOperatorFactoryChain.ts index ea8e27d..c89c1e5 100644 --- a/src/content/operators/impls/focus.ts +++ b/src/content/operators/impls/FocusOperatorFactoryChain.ts @@ -1,19 +1,12 @@ import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; import OperatorFactoryChain from "../OperatorFactoryChain"; +import Operator from "../Operator"; +import FocusOperator from "./FocusOperator"; import FocusPresenter from "../../presenters/FocusPresenter"; import * as operations from "../../../shared/operations"; -export class FocusOperator implements Operator { - constructor(private readonly presenter: FocusPresenter) {} - - async run(): Promise<void> { - this.presenter.focusFirstElement(); - } -} - @injectable() -export class FocusOperatorFactoryChain implements OperatorFactoryChain { +export default class FocusOperatorFactoryChain implements OperatorFactoryChain { constructor( @inject("FocusPresenter") private readonly focusPresenter: FocusPresenter diff --git a/src/content/operators/impls/follow.ts b/src/content/operators/impls/FollowOperatorFactoryChain.ts index 6d3fadc..588e1a4 100644 --- a/src/content/operators/impls/follow.ts +++ b/src/content/operators/impls/FollowOperatorFactoryChain.ts @@ -1,23 +1,13 @@ 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"; -export class StartFollowOperator implements Operator { - constructor( - private readonly followMasterClient: FollowMasterClient, - private readonly newTab: boolean, - private readonly background: boolean - ) {} - - async run(): Promise<void> { - this.followMasterClient.startFollow(this.newTab, this.background); - } -} - @injectable() -export class FollowOperatorFactoryChain implements OperatorFactoryChain { +export default class FollowOperatorFactoryChain + implements OperatorFactoryChain { constructor( @inject("FollowMasterClient") private followMasterClient: FollowMasterClient 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<void> { + const smooth = this.getSmoothScroll(); + this.presenter.scrollHorizonally(this.count, smooth); + } +} diff --git a/src/content/operators/impls/mark.ts b/src/content/operators/impls/MarkOperatorFactoryChain.ts index d90aba9..7e6c513 100644 --- a/src/content/operators/impls/mark.ts +++ b/src/content/operators/impls/MarkOperatorFactoryChain.ts @@ -1,27 +1,13 @@ 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"; -export class EnableSetMarkOperator implements Operator { - constructor(private readonly repository: MarkKeyRepository) {} - - async run(): Promise<void> { - this.repository.enableSetMode(); - } -} - -export class EnableJumpMarkOperator implements Operator { - constructor(private readonly repository: MarkKeyRepository) {} - - async run(): Promise<void> { - this.repository.enableJumpMode(); - } -} - @injectable() -export class MarkOperatorFactoryChain implements OperatorFactoryChain { +export default class MarkOperatorFactoryChain implements OperatorFactoryChain { constructor( @inject("MarkKeyRepository") private readonly markKeyRepository: MarkKeyRepository 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + 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<void> { + const url = window.location.href; + this.repository.write(url); + await this.consoleClient.info("Yanked " + url); + } +} 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<void> { - 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<void> { - 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<void> { - 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<void> { - 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<void> { - 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<void> { - 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<void> { - 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; - } -} |