From 8091d987992ab9d5f0cb6d275b8d673e10b7e129 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 13 Feb 2021 19:37:37 +0100 Subject: [PATCH] merged watch2getherHide.ts into watch2gether.ts --- src/javascript/app.ts | 6 +-- src/javascript/enhancements/watch2gether.ts | 42 +++++++++++++++++- .../enhancements/watch2getherHide.ts | 44 ------------------- 3 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 src/javascript/enhancements/watch2getherHide.ts diff --git a/src/javascript/app.ts b/src/javascript/app.ts index 611738e..0725fe3 100644 --- a/src/javascript/app.ts +++ b/src/javascript/app.ts @@ -10,8 +10,7 @@ import { init as languageDisplay } from './enhancements/languageDisplay'; import { init as notifications } from './enhancements/notifications'; import { init as quickSearch } from './enhancements/quickSearch'; import { init as timeConversion } from './enhancements/timeConversion'; -import { init as watch2getherChat } from './enhancements/watch2gether'; -import { init as watch2getherAutotoggleHide } from './enhancements/watch2getherHide'; +import { init as watch2gether } from './enhancements/watch2gether'; // css import { init as cssEnhancements } from './enhancements/cssEnhancements'; @@ -29,8 +28,7 @@ languageDisplay(); notifications(); quickSearch(); timeConversion(); -watch2getherChat(); -watch2getherAutotoggleHide(); +watch2gether(); // css cssEnhancements(); \ No newline at end of file diff --git a/src/javascript/enhancements/watch2gether.ts b/src/javascript/enhancements/watch2gether.ts index 6a94bd4..b4e9590 100644 --- a/src/javascript/enhancements/watch2gether.ts +++ b/src/javascript/enhancements/watch2gether.ts @@ -1,7 +1,11 @@ import * as core from '../utils/aniwatchCore'; import { v4 as uuidv4 } from 'uuid'; -import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter } from '../configuration/configuration'; +import { getGlobalConfiguration, SETTINGS_w2gDisplayCharacterCounter, SETTINGS_w2gAutotoggleHide } from '../configuration/configuration'; import { assigned } from '../utils/helpers'; +import { findPlayerElement } from "../enhancements/anilyr"; + +const PLAYER_ID = 'wPlayer'; +let hidden: boolean; export function init(): void { getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => { @@ -14,6 +18,16 @@ export function init(): void { }, "^/watch2gether/.*$"); } }); + getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => { + if (value) { + core.runAfterLoad(() => { + addAutohideListener(); + }, "^/watch2gether/.*$"); + core.runAfterLocationChange(() => { + addAutohideListener(); + }, "^/watch2gether/.*$"); + } + }); } function manipulateChatInput(): void { @@ -65,4 +79,28 @@ function updateCharCounter(textarea: HTMLTextAreaElement, charCounterSpan: HTMLS charCounterSpan.classList.remove(SHAKE_CLASS); }, 200); } -} \ No newline at end of file +} + +function addAutohideListener(): void { + let playerElement = findPlayerElement(PLAYER_ID); + let hideButton: HTMLButtonElement = document.getElementsByClassName('no-margin md-button md-ink-ripple layout-align-center-center layout-row')[0] as HTMLButtonElement; + if (assigned(playerElement) && assigned(hideButton)) { + if (hideButton.textContent.includes('HIDE')) { + hidden = false; + } else if (hideButton.textContent.includes('SHOW')) { + hidden = true; + } + playerElement.addEventListener('play', fn => { + if (!hidden) { + hideButton.click(); + hidden = !hidden; + } + }) + playerElement.addEventListener('pause', fn => { + if (hidden) { + hideButton.click(); + hidden = !hidden; + } + }) + } +} diff --git a/src/javascript/enhancements/watch2getherHide.ts b/src/javascript/enhancements/watch2getherHide.ts deleted file mode 100644 index 77a53ff..0000000 --- a/src/javascript/enhancements/watch2getherHide.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as core from '../utils/aniwatchCore'; -import * as helper from '../utils/helpers'; -import { getGlobalConfiguration, SETTINGS_w2gAutotoggleHide } from '../configuration/configuration'; -import { findPlayerElement } from "../enhancements/anilyr"; - -const PLAYER_ID = 'wPlayer'; -let hidden: boolean; - -export function init(): void { - getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => { - if (value) { - core.runAfterLoad(() => { - addAutohideListener(); - }, "^/watch2gether/.*$"); - core.runAfterLocationChange(() => { - addAutohideListener(); - }, "^/watch2gether/.*$"); - } - }); -} - -function addAutohideListener(): void { - let playerElement = findPlayerElement(PLAYER_ID); - let hideButton: HTMLButtonElement = document.getElementsByClassName('no-margin md-button md-ink-ripple layout-align-center-center layout-row')[0] as HTMLButtonElement; - if (helper.assigned(playerElement) && helper.assigned(hideButton)) { - if (hideButton.textContent.includes('HIDE')) { - hidden = false; - } else if (hideButton.textContent.includes('SHOW')) { - hidden = true; - } - playerElement.addEventListener('play', fn => { - if (!hidden) { - hideButton.click(); - hidden = !hidden; - } - }) - playerElement.addEventListener('pause', fn => { - if (hidden) { - hideButton.click(); - hidden = !hidden; - } - }) - } -}