mod1
This commit is contained in:
48
script.js
48
script.js
@@ -27,17 +27,17 @@ let forwardMovies = [];
|
||||
let monitorOutroInterval = null; // Global interval variable to monitor the outro segment of the trailer
|
||||
|
||||
if (setMutedHover) {
|
||||
const slidesContainer = document.getElementById('slides-container');
|
||||
slidesContainer.addEventListener('mouseenter', () => {
|
||||
const hoverContainer = document.getElementById('slides-container');
|
||||
hoverContainer.addEventListener('mouseenter', () => {
|
||||
if (player) {
|
||||
player.unMute();
|
||||
player.setVolume(unmutedVolume);
|
||||
isMuted = false;
|
||||
}
|
||||
});
|
||||
|
||||
slidesContainer.addEventListener('mouseleave', () => {
|
||||
hoverContainer.addEventListener('mouseleave', () => {
|
||||
if (player) {
|
||||
player.mute();
|
||||
player.setVolume(0);
|
||||
isMuted = true;
|
||||
}
|
||||
});
|
||||
@@ -90,6 +90,13 @@ function monitorOutro(player, outroSegment) {
|
||||
}, 500); // check every 500ms
|
||||
}
|
||||
|
||||
const clearMonitorOutroInterval = () => {
|
||||
if (monitorOutroInterval) {
|
||||
clearInterval(monitorOutroInterval);
|
||||
monitorOutroInterval = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const createElem = (tag, className, textContent, src, alt) => {
|
||||
const elem = document.createElement(tag);
|
||||
@@ -114,6 +121,7 @@ const cleanup = () => {
|
||||
player = null;
|
||||
clearTimeout(slideChangeTimeout);
|
||||
slideChangeTimeout = null;
|
||||
clearMonitorOutroInterval();
|
||||
const container = document.getElementById('slides-container');
|
||||
if (container) container.innerHTML = '';
|
||||
};
|
||||
@@ -291,11 +299,11 @@ const createSlideElement = (movie, hasVideo = false) => {
|
||||
mute: isMuted ? 1 : 0, // CHeck if the video should start muted
|
||||
controls: disableTrailerControls ? 0 : 1, // Hide the controls
|
||||
disablekb: 1, // Disable keyboard controls
|
||||
fs: 1, // Enavle fullscreen
|
||||
iv_load_policy: 3, // Disable annotations
|
||||
cc_load_policy: 3, // Disable captions
|
||||
},
|
||||
events: {
|
||||
'onReady': event => {
|
||||
'onReady': () => {
|
||||
if (useSponsorBlock) {
|
||||
fetchSponsorBlockData(videoId).then(({ intro, outro }) => {
|
||||
if (intro && skipIntro) {
|
||||
@@ -320,6 +328,7 @@ const createSlideElement = (movie, hasVideo = false) => {
|
||||
if (trailerMaxLength > 0) {
|
||||
clearTimeout(slideChangeTimeout);
|
||||
slideChangeTimeout = setTimeout(() => {
|
||||
clearMonitorOutroInterval();
|
||||
if (player) {
|
||||
player.stopVideo();
|
||||
player.destroy();
|
||||
@@ -329,14 +338,16 @@ const createSlideElement = (movie, hasVideo = false) => {
|
||||
}, trailerMaxLength);
|
||||
}
|
||||
if (isMuted) {
|
||||
event.target.setVolume(0); // Mute the video if the setting is MuteOn
|
||||
player.setVolume(0); // Mute the video if the setting is MuteOn
|
||||
} else {
|
||||
event.target.setVolume(unmutedVolume); // Set the volume, value between 0 and 100
|
||||
player.setVolume(unmutedVolume); // Set the volume, value between 0 and 100
|
||||
}
|
||||
event.target.playVideo();
|
||||
|
||||
player.playVideo();
|
||||
console.log(`Playing trailer for '${movie.Name}'`);
|
||||
},
|
||||
'onStateChange': event => {
|
||||
if (event.data === YT.PlayerState.PLAYING) {
|
||||
'onStateChange': () => {
|
||||
if (player.getPlayerState() === YT.PlayerState.PLAYING) {
|
||||
// Only show when YT video is successfully playing
|
||||
const backdrop = document.querySelector('.backdrop');
|
||||
if (backdrop) {
|
||||
@@ -361,14 +372,21 @@ const createSlideElement = (movie, hasVideo = false) => {
|
||||
if (logo) logo.style.left = 'calc(50% - 17vw)';
|
||||
|
||||
videoContainer.style.width = '34.4vw';
|
||||
} else if (event.data === YT.PlayerState.ENDED) {
|
||||
setTimeout(fetchRandomMovie, 100);
|
||||
/*} 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);
|
||||
}
|
||||
},
|
||||
'onError': () => {
|
||||
console.error(`YouTube prevented playback of '${movie.Name}'`);
|
||||
if (player) {
|
||||
clearInterval(monitorOutroInterval);
|
||||
clearMonitorOutroInterval();
|
||||
player.destroy();
|
||||
player = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user