From b963836c18cf6d440979319bdb50d301158829ae Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Fri, 3 Mar 2023 23:04:49 -0500 Subject: [PATCH] Fix time breakage from skipIntroPlugin. (#387) --- native/skipIntroPlugin.js | 45 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/native/skipIntroPlugin.js b/native/skipIntroPlugin.js index f1e6785c..ff5307ad 100644 --- a/native/skipIntroPlugin.js +++ b/native/skipIntroPlugin.js @@ -107,35 +107,38 @@ class skipIntroPlugin { } - async function onPlayback(e, player, state) { + function onPlayback(e, player, state) { if (state.NowPlayingItem) { - await injectSkipIntroHtml(); getIntroTimestamps(state.NowPlayingItem); - } - const onTimeUpdate = () => { - // Check if an introduction sequence was detected for this item. - if (!tvIntro?.Valid) { - return; - } + const onTimeUpdate = async () => { + // Check if an introduction sequence was detected for this item. + if (!tvIntro?.Valid) { + return; + } - const seconds = playbackManager.currentTime(player) / 1000; - const skipIntro = document.querySelector(".skipIntro"); + const seconds = playbackManager.currentTime(player) / 1000; - // If the skip prompt should be shown, show it. - if (seconds >= tvIntro.ShowSkipPromptAt && seconds < tvIntro.HideSkipPromptAt) { - skipIntro.classList.remove("hide"); - return; - } + await injectSkipIntroHtml(); // I have trust issues + const skipIntro = document.querySelector(".skipIntro"); + + // If the skip prompt should be shown, show it. + if (seconds >= tvIntro.ShowSkipPromptAt && seconds < tvIntro.HideSkipPromptAt) { + skipIntro.classList.remove("hide"); + return; + } - skipIntro.classList.add("hide"); - }; + skipIntro.classList.add("hide"); + }; - events.on(player, 'timeupdate', onTimeUpdate); + events.on(player, 'timeupdate', onTimeUpdate); - events.on(player, 'playbackstop', () => { - events.off(player, 'timeupdate', onTimeUpdate); - }); + const onPlaybackStop = () => { + events.off(player, 'timeupdate', onTimeUpdate); + events.off(player, 'playbackstop', onPlaybackStop); + }; + events.on(player, 'playbackstop', onPlaybackStop); + } }; events.on(playbackManager, 'playbackstart', onPlayback);