Преглед изворни кода

Fix time breakage from skipIntroPlugin. (#387)

Ian Walton пре 1 година
родитељ
комит
b963836c18
1 измењених фајлова са 24 додато и 21 уклоњено
  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);