moved the listener etc to their own function, furthermore running it afterLocationChange and afterLoad

This commit is contained in:
kaffem 2021-02-13 19:12:42 +01:00
parent 510061c1e0
commit d58a4094f3

View file

@ -9,7 +9,17 @@ let hidden: boolean;
export function init(): void { export function init(): void {
getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => { getGlobalConfiguration().getProperty(SETTINGS_w2gAutotoggleHide, value => {
if (value) { if (value) {
core.runAfterLoad(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
core.runAfterLocationChange(() => { core.runAfterLocationChange(() => {
addAutohideListener();
}, "^/watch2gether/.*$");
}
});
}
function addAutohideListener() {
let playerElement = findPlayerElement(PLAYER_ID); 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; 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 (helper.assigned(playerElement) && helper.assigned(hideButton)) {
@ -31,7 +41,4 @@ export function init(): void {
} }
}) })
} }
}, "^/watch2gether/.*$");
}
});
} }