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