Bladeren bron

Fix time breakage from skipIntroPlugin. (#387)

Ian Walton 1 jaar geleden
bovenliggende
commit
b963836c18
1 gewijzigde bestanden met toevoegingen van 24 en 21 verwijderingen
  1. 24 21
      native/skipIntroPlugin.js

+ 24 - 21
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);