diff --git a/script.js b/script.js index 9093fa1..9cd6933 100644 --- a/script.js +++ b/script.js @@ -372,12 +372,12 @@ const createSlideElement = (movie, hasVideo = false) => { if (logo) logo.style.left = 'calc(50% - 17vw)'; videoContainer.style.width = '34.4vw'; - /*} else if (player.getPlayerState() === YT.PlayerState.CUED) { - console.log('Video cued - attempting restart'); - player.playVideo(); - } else if (player.getPlayerState() === -1) { - console.log('Video unstarted - attempting restart'); - player.playVideo();*/ + /*} else if (player.getPlayerState() === YT.PlayerState.CUED) { + console.log('Video cued - attempting restart'); + player.playVideo(); + } else if (player.getPlayerState() === -1) { + console.log('Video unstarted - attempting restart'); + player.playVideo();*/ } else if (player.getPlayerState() === YT.PlayerState.ENDED) { clearMonitorOutroInterval(); setTimeout(fetchRandomMovie, 20); @@ -665,21 +665,25 @@ const checkNavigation = () => { // Check if parent is available and if the iframe is in an embedded environment if (!showOnOtherPages && window.parent && window.parent !== window) { - const homeTab = window.parent.document.getElementById('homeTab'); - const isHomeTabActive = homeTab && homeTab.classList.contains('is-active'); + const isHomePage = url => url.includes('/home') || url.endsWith('/web/') || url.endsWith('/web/index.html'); + if (isHomePage(newLocation)) { + const homeTab = window.parent.document.getElementById('homeTab'); + const isHomeTabActive = homeTab && homeTab.classList.contains('is-active'); - // Check if the user is switching tabs while on the homepage to eg. favorites or requests, if so, stop the slideshow - if (isHomeTabActive && !isHomePageActive) { - console.log("HomeTab is active, reactivating slideshow"); - isHomePageActive = true; - window.parent.document.querySelector('.featurediframe').style.display = 'block'; - cleanup(); - fetchRandomMovie(); - } else if (!isHomeTabActive && isHomePageActive) { - console.log("Leaving HomeTab, cleaning up slideshow"); - isHomePageActive = false; - window.parent.document.querySelector('.featurediframe').style.display = 'none'; - cleanup(); + // Check if the user is switching tabs while on the homepage to eg. favorites or requests, if so, stop the slideshow + if (isHomeTabActive && !isHomePageActive) { + console.log("HomeTab is active, reactivating slideshow"); + isHomePageActive = true; + window.parent.document.querySelector('.featurediframe').style.display = 'block'; + //cleanup(); + fetchRandomMovie(); + } else if (!isHomeTabActive && isHomePageActive) { + console.log("Leaving HomeTab, cleaning up slideshow"); + isHomePageActive = false; + window.parent.document.querySelector('.featurediframe').style.display = 'none'; + stopBackgroundVideo(); + cleanup(); + } } } else { console.error("Spotlight iframe is not in an embedded environment, has a different domain or showOnOtherPages is set to true"); @@ -701,6 +705,7 @@ document.addEventListener('DOMContentLoaded', () => { const isHomePage = url => url.includes('/home') || url.endsWith('/web/') || url.endsWith('/web/index.html'); if (isHomePage(window.top.location.href)) { isHomePageActive = true; + console.log("Homepage detected, starting slideshow"); readCustomList().then(list => { if (list) { movieList = list; currentMovieIndex = 0; } fetchRandomMovie();