From 510061c1e0dc4dae651ab0ce1c09dcd94d7b6f61 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Mon, 8 Feb 2021 13:37:34 +0100 Subject: [PATCH 1/6] #144 working prototype --- src/html/settings.html | 3 ++ src/javascript/app.ts | 2 + src/javascript/configuration/configuration.ts | 1 + src/javascript/enhancements/anilyr.ts | 6 +-- .../enhancements/watch2getherHide.ts | 37 +++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/javascript/enhancements/watch2getherHide.ts diff --git a/src/html/settings.html b/src/html/settings.html index ff1ea70..b774d21 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -48,6 +48,9 @@
+ +
+

diff --git a/src/javascript/app.ts b/src/javascript/app.ts index 0e714aa..9dae219 100644 --- a/src/javascript/app.ts +++ b/src/javascript/app.ts @@ -11,6 +11,7 @@ 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/watch2getherChat'; +import { init as watch2getherAutotoggleHide } from './enhancements/watch2getherHide'; // css import { init as cssEnhancements } from './enhancements/cssEnhancements'; @@ -29,6 +30,7 @@ notifications(); quickSearch(); timeConversion(); watch2getherChat(); +watch2getherAutotoggleHide(); // css cssEnhancements(); \ No newline at end of file diff --git a/src/javascript/configuration/configuration.ts b/src/javascript/configuration/configuration.ts index 64207c6..8607d71 100644 --- a/src/javascript/configuration/configuration.ts +++ b/src/javascript/configuration/configuration.ts @@ -16,6 +16,7 @@ export const SETTINGS_requestBeautifyPage = 'requestBeautifyPage'; export const SETTINGS_playerAutoplayAfterScreenshot = 'playerAutoplayAfterScreenshot'; // w2g export const SETTINGS_w2gDisplayCharacterCounter = 'w2gDisplayCharacterCounter'; +export const SETTINGS_w2gAutotoggleHide = 'w2gAutotoggleHide'; class Configuration { settingsCache: Map; diff --git a/src/javascript/enhancements/anilyr.ts b/src/javascript/enhancements/anilyr.ts index 7e32362..91268af 100644 --- a/src/javascript/enhancements/anilyr.ts +++ b/src/javascript/enhancements/anilyr.ts @@ -23,7 +23,7 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void { mutations.forEach(mutation => { // Switched to invisible if (!mutation.oldValue.includes('display: none') && helper.isHtmlElement(mutation.target) && (mutation.target as HTMLElement).style.display == 'none') { - let playerElement = findPlayerElement(); + let playerElement = findPlayerElement(PLAYER_ID); if (helper.assigned(playerElement)) { resumePlayer(playerElement); } @@ -38,8 +38,8 @@ function observeScreenshotTooltip(tooltip: HTMLElement): void { }); } -function findPlayerElement(): HTMLVideoElement { - let playerCandidate = document.getElementById(PLAYER_ID); +export function findPlayerElement(id: string): HTMLVideoElement { + let playerCandidate = document.getElementById(id); if (playerCandidate instanceof HTMLVideoElement) { return playerCandidate; } diff --git a/src/javascript/enhancements/watch2getherHide.ts b/src/javascript/enhancements/watch2getherHide.ts new file mode 100644 index 0000000..c48afe6 --- /dev/null +++ b/src/javascript/enhancements/watch2getherHide.ts @@ -0,0 +1,37 @@ +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.runAfterLocationChange(() => { + 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; + } + }) + } + }, "^/watch2gether/.*$"); + } + }); +} \ No newline at end of file From d58a4094f35d77bbe505ff7753a3b839bbdbaa9d Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 13 Feb 2021 19:12:42 +0100 Subject: [PATCH 2/6] moved the listener etc to their own function, furthermore running it afterLocationChange and afterLoad --- .../enhancements/watch2getherHide.ts | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/javascript/enhancements/watch2getherHide.ts b/src/javascript/enhancements/watch2getherHide.ts index c48afe6..baa6056 100644 --- a/src/javascript/enhancements/watch2getherHide.ts +++ b/src/javascript/enhancements/watch2getherHide.ts @@ -9,29 +9,36 @@ let hidden: boolean; export function init(): void { getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => { if (value) { + core.runAfterLoad(() => { + addAutohideListener(); + }, "^/watch2gether/.*$"); core.runAfterLocationChange(() => { - 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; - } - }) - } + addAutohideListener(); }, "^/watch2gether/.*$"); } }); -} \ No newline at end of file +} + +function addAutohideListener() { + 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; + } + }) + } +} From c9fdbdebbcb973e03373f82bb3247d1fa4aff535 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 13 Feb 2021 19:16:37 +0100 Subject: [PATCH 3/6] fixed the settings description --- src/html/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/html/settings.html b/src/html/settings.html index b774d21..0a8aee4 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -49,7 +49,7 @@
-
+


From 7783ddf0b243bd60f31e13164ab9fc0ea40a1cc0 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 13 Feb 2021 19:29:09 +0100 Subject: [PATCH 4/6] renamed watch2getherChat.ts to watch2gether.ts --- src/javascript/app.ts | 2 +- .../enhancements/{watch2getherChat.ts => watch2gether.ts} | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) rename src/javascript/enhancements/{watch2getherChat.ts => watch2gether.ts} (95%) diff --git a/src/javascript/app.ts b/src/javascript/app.ts index 9dae219..611738e 100644 --- a/src/javascript/app.ts +++ b/src/javascript/app.ts @@ -10,7 +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/watch2getherChat'; +import { init as watch2getherChat } from './enhancements/watch2gether'; import { init as watch2getherAutotoggleHide } from './enhancements/watch2getherHide'; // css import { init as cssEnhancements } from './enhancements/cssEnhancements'; diff --git a/src/javascript/enhancements/watch2getherChat.ts b/src/javascript/enhancements/watch2gether.ts similarity index 95% rename from src/javascript/enhancements/watch2getherChat.ts rename to src/javascript/enhancements/watch2gether.ts index 8ca0526..6a94bd4 100644 --- a/src/javascript/enhancements/watch2getherChat.ts +++ b/src/javascript/enhancements/watch2gether.ts @@ -6,6 +6,9 @@ import { assigned } from '../utils/helpers'; export function init(): void { getGlobalConfiguration().getProperty(SETTINGS_w2gDisplayCharacterCounter, value => { if (value) { + core.runAfterLoad(() => { + manipulateChatInput(); + }, "^/watch2gether/.*$"); core.runAfterLocationChange(() => { manipulateChatInput(); }, "^/watch2gether/.*$"); From 53fbd797fecdf6eb76e2df2e23509bc1158007d4 Mon Sep 17 00:00:00 2001 From: kaffem <29717789+kaffem@users.noreply.github.com> Date: Sat, 13 Feb 2021 19:29:33 +0100 Subject: [PATCH 5/6] added function return type --- src/javascript/enhancements/watch2getherHide.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/enhancements/watch2getherHide.ts b/src/javascript/enhancements/watch2getherHide.ts index baa6056..77a53ff 100644 --- a/src/javascript/enhancements/watch2getherHide.ts +++ b/src/javascript/enhancements/watch2getherHide.ts @@ -19,7 +19,7 @@ export function init(): void { }); } -function addAutohideListener() { +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)) { 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 6/6] 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; - } - }) - } -}