diff options
Diffstat (limited to 'src/content/operators/impls')
7 files changed, 35 insertions, 31 deletions
diff --git a/src/content/operators/impls/ClipboardOperatorFactoryChain.ts b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts index fb12ae8..454aea1 100644 --- a/src/content/operators/impls/ClipboardOperatorFactoryChain.ts +++ b/src/content/operators/impls/ClipboardOperatorFactoryChain.ts @@ -8,6 +8,7 @@ import ConsoleClient from "../../client/ConsoleClient"; import OperationClient from "../../client/OperationClient"; import SettingRepository from "../../repositories/SettingRepository"; import * as operations from "../../../shared/operations"; +import URLRepository from "./URLRepository"; @injectable() export default class ClipboardOperatorFactoryChain @@ -20,7 +21,9 @@ export default class ClipboardOperatorFactoryChain @inject("OperationClient") private readonly operationClinet: OperationClient, @inject("SettingRepository") - private readonly settingRepository: SettingRepository + private readonly settingRepository: SettingRepository, + @inject("URLRepository") + private readonly urlRepository: URLRepository ) {} create(op: operations.Operation, _repeat: number): Operator | null { @@ -28,7 +31,8 @@ export default class ClipboardOperatorFactoryChain case operations.URLS_YANK: return new YankURLOperator( this.clipboardRepository, - this.consoleClient + this.consoleClient, + this.urlRepository ); case operations.URLS_PASTE: return new PasteOperator( diff --git a/src/content/operators/impls/FindNextOperator.ts b/src/content/operators/impls/FindNextOperator.ts index 723db3d..c67f6d9 100644 --- a/src/content/operators/impls/FindNextOperator.ts +++ b/src/content/operators/impls/FindNextOperator.ts @@ -2,9 +2,14 @@ import Operator from "../Operator"; import FindMasterClient from "../../client/FindMasterClient"; export default class FindNextOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} + constructor( + private readonly findMasterClient: FindMasterClient, + private readonly repeat: number + ) {} async run(): Promise<void> { - this.findMasterClient.findNext(); + for (let i = 0; i < this.repeat; ++i) { + this.findMasterClient.findNext(); + } } } diff --git a/src/content/operators/impls/FindOperatorFactoryChain.ts b/src/content/operators/impls/FindOperatorFactoryChain.ts index ef1c754..b3524c1 100644 --- a/src/content/operators/impls/FindOperatorFactoryChain.ts +++ b/src/content/operators/impls/FindOperatorFactoryChain.ts @@ -1,7 +1,6 @@ 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"; @@ -17,15 +16,9 @@ export default class FindOperatorFactoryChain implements OperatorFactoryChain { create(op: operations.Operation, repeat: number): Operator | null { switch (op.type) { case operations.FIND_NEXT: - return new RepeatOperator( - new FindNextOperator(this.findMasterClient), - repeat - ); + return new FindNextOperator(this.findMasterClient, repeat); case operations.FIND_PREV: - return new RepeatOperator( - new FindPrevOperator(this.findMasterClient), - repeat - ); + return new FindPrevOperator(this.findMasterClient, repeat); } return null; } diff --git a/src/content/operators/impls/FindPrevOperator.ts b/src/content/operators/impls/FindPrevOperator.ts index be6a01e..f73e605 100644 --- a/src/content/operators/impls/FindPrevOperator.ts +++ b/src/content/operators/impls/FindPrevOperator.ts @@ -2,9 +2,14 @@ import Operator from "../Operator"; import FindMasterClient from "../../client/FindMasterClient"; export default class FindPrevOperator implements Operator { - constructor(private readonly findMasterClient: FindMasterClient) {} + constructor( + private readonly findMasterClient: FindMasterClient, + private readonly repeat: number + ) {} async run(): Promise<void> { - this.findMasterClient.findPrev(); + for (let i = 0; i < this.repeat; ++i) { + this.findMasterClient.findPrev(); + } } } diff --git a/src/content/operators/impls/RepeatOperator.ts b/src/content/operators/impls/RepeatOperator.ts deleted file mode 100644 index efe2faf..0000000 --- a/src/content/operators/impls/RepeatOperator.ts +++ /dev/null @@ -1,14 +0,0 @@ -import Operator from "../Operator"; - -export default class RepeatOperator implements Operator { - constructor( - private readonly operator: Operator, - private readonly repeat: number - ) {} - - async run(): Promise<void> { - for (let i = 0; i < this.repeat; ++i) { - this.operator.run(); - } - } -} diff --git a/src/content/operators/impls/URLRepository.ts b/src/content/operators/impls/URLRepository.ts new file mode 100644 index 0000000..a1efc2e --- /dev/null +++ b/src/content/operators/impls/URLRepository.ts @@ -0,0 +1,9 @@ +export default interface URLRepository { + getCurrentURL(): string; +} + +export class URLRepositoryImpl implements URLRepository { + getCurrentURL(): string { + return window.location.href; + } +} diff --git a/src/content/operators/impls/YankURLOperator.ts b/src/content/operators/impls/YankURLOperator.ts index 5e2ac60..2e774eb 100644 --- a/src/content/operators/impls/YankURLOperator.ts +++ b/src/content/operators/impls/YankURLOperator.ts @@ -1,15 +1,17 @@ import Operator from "../Operator"; import ClipboardRepository from "../../repositories/ClipboardRepository"; import ConsoleClient from "../../client/ConsoleClient"; +import URLRepository from "./URLRepository"; export default class YankURLOperator implements Operator { constructor( private readonly repository: ClipboardRepository, - private readonly consoleClient: ConsoleClient + private readonly consoleClient: ConsoleClient, + private readonly urlRepository: URLRepository ) {} async run(): Promise<void> { - const url = window.location.href; + const url = this.urlRepository.getCurrentURL(); this.repository.write(url); await this.consoleClient.info("Yanked " + url); } |