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] 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; + } + }) + } +}