aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/components/common')
-rw-r--r--src/content/components/common/follow.ts104
-rw-r--r--src/content/components/common/index.ts59
-rw-r--r--src/content/components/common/mark.ts44
3 files changed, 0 insertions, 207 deletions
diff --git a/src/content/components/common/follow.ts b/src/content/components/common/follow.ts
deleted file mode 100644
index 413244e..0000000
--- a/src/content/components/common/follow.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-import MessageListener from '../../MessageListener';
-import { LinkHint, InputHint } from '../../presenters/Hint';
-import * as messages from '../../../shared/messages';
-import Key from '../../domains/Key';
-import TabsClient, { TabsClientImpl } from '../../client/TabsClient';
-import FollowMasterClient, { FollowMasterClientImpl }
- from '../../client/FollowMasterClient';
-import FollowPresenter, { FollowPresenterImpl }
- from '../../presenters/FollowPresenter';
-
-let tabsClient: TabsClient = new TabsClientImpl();
-let followMasterClient: FollowMasterClient =
- new FollowMasterClientImpl(window.top);
-let followPresenter: FollowPresenter =
- new FollowPresenterImpl();
-
-interface Size {
- width: number;
- height: number;
-}
-
-interface Point {
- x: number;
- y: number;
-}
-
-export default class Follow {
- private enabled: boolean;
-
- constructor() {
- this.enabled = false;
-
- new MessageListener().onWebMessage(this.onMessage.bind(this));
- }
-
- key(key: Key): boolean {
- if (!this.enabled) {
- return false;
- }
- followMasterClient.sendKey(key);
- return true;
- }
-
- countHints(viewSize: Size, framePosition: Point) {
- let count = followPresenter.getTargetCount(viewSize, framePosition);
- followMasterClient.responseHintCount(count);
- }
-
- createHints(viewSize: Size, framePosition: Point, tags: string[]) {
- this.enabled = true;
- followPresenter.createHints(viewSize, framePosition, tags);
- }
-
- showHints(prefix: string) {
- followPresenter.filterHints(prefix);
- }
-
- removeHints() {
- followPresenter.clearHints();
- this.enabled = false;
- }
-
- async activateHints(
- tag: string, newTab: boolean, background: boolean,
- ): Promise<void> {
- let hint = followPresenter.getHint(tag);
- if (!hint) {
- return;
- }
-
- if (hint instanceof LinkHint) {
- let url = hint.getLink();
- // ignore taget='_blank'
- if (!newTab && hint.getLinkTarget() !== '_blank') {
- hint.click();
- return;
- }
- // eslint-disable-next-line no-script-url
- if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) {
- return;
- }
- await tabsClient.openUrl(url, newTab, background);
- } else if (hint instanceof InputHint) {
- hint.activate();
- }
- }
-
- onMessage(message: messages.Message, _sender: Window) {
- switch (message.type) {
- case messages.FOLLOW_REQUEST_COUNT_TARGETS:
- return this.countHints(message.viewSize, message.framePosition);
- case messages.FOLLOW_CREATE_HINTS:
- return this.createHints(
- message.viewSize, message.framePosition, message.tags);
- case messages.FOLLOW_SHOW_HINTS:
- return this.showHints(message.prefix);
- case messages.FOLLOW_ACTIVATE:
- return this.activateHints(
- message.tag, message.newTab, message.background);
- case messages.FOLLOW_REMOVE_HINTS:
- return this.removeHints();
- }
- }
-}
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts
deleted file mode 100644
index 1aacf51..0000000
--- a/src/content/components/common/index.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import InputDriver from './../../InputDriver';
-import FollowComponent from './follow';
-import MarkComponent from './mark';
-// import KeymapperComponent from './keymapper';
-import * as messages from '../../../shared/messages';
-import MessageListener from '../../MessageListener';
-import * as blacklists from '../../../shared/blacklists';
-import Key from '../../domains/Key';
-
-import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
-import SettingUseCase from '../../usecases/SettingUseCase';
-
-let addonEnabledUseCase = new AddonEnabledUseCase();
-let settingUseCase = new SettingUseCase();
-
-export default class Common {
- constructor(win: Window, store: any) {
- const input = new InputDriver(win.document.body);
- const follow = new FollowComponent();
- const mark = new MarkComponent(store);
- // const keymapper = new KeymapperComponent(store);
-
- input.onKey((key: Key) => follow.key(key));
- input.onKey((key: Key) => mark.key(key));
- // input.onKey((key: Key) => keymapper.key(key));
-
- this.reloadSettings();
-
- new MessageListener().onBackgroundMessage(this.onMessage.bind(this));
- }
-
- onMessage(message: messages.Message) {
- switch (message.type) {
- case messages.SETTINGS_CHANGED:
- return this.reloadSettings();
- case messages.ADDON_TOGGLE_ENABLED:
- return addonEnabledUseCase.toggle();
- }
- return undefined;
- }
-
- async reloadSettings() {
- try {
- let current = await settingUseCase.reload();
- let disabled = blacklists.includes(
- current.blacklist, window.location.href,
- );
- if (disabled) {
- addonEnabledUseCase.disable();
- } else {
- addonEnabledUseCase.enable();
- }
- } catch (e) {
- // Sometime sendMessage fails when background script is not ready.
- console.warn(e);
- setTimeout(() => this.reloadSettings(), 500);
- }
- }
-}
diff --git a/src/content/components/common/mark.ts b/src/content/components/common/mark.ts
deleted file mode 100644
index 058b873..0000000
--- a/src/content/components/common/mark.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import * as markActions from '../../actions/mark';
-import * as consoleFrames from '../..//console-frames';
-import Key from '../../domains/Key';
-
-import MarkUseCase from '../../usecases/MarkUseCase';
-
-let markUseCase = new MarkUseCase();
-
-const cancelKey = (key: Key): boolean => {
- return key.key === 'Esc' || key.key === '[' && Boolean(key.ctrlKey);
-};
-
-export default class MarkComponent {
- private store: any;
-
- constructor(store: any) {
- this.store = store;
- }
-
- // eslint-disable-next-line max-statements
- key(key: Key) {
- let { mark: markState } = this.store.getState();
-
- if (!markState.setMode && !markState.jumpMode) {
- return false;
- }
-
- if (cancelKey(key)) {
- this.store.dispatch(markActions.cancel());
- return true;
- }
-
- if (key.ctrlKey || key.metaKey || key.altKey) {
- consoleFrames.postError('Unknown mark');
- } else if (markState.setMode) {
- markUseCase.set(key.key);
- } else if (markState.jumpMode) {
- markUseCase.jump(key.key);
- }
-
- this.store.dispatch(markActions.cancel());
- return true;
- }
-}