|
|
|
|
@@ -1258,9 +1258,20 @@ const ApiUtils = {
|
|
|
|
|
*/
|
|
|
|
|
async fetchSponsorBlockData(videoId) {
|
|
|
|
|
if (!CONFIG.useSponsorBlock) return { intro: null, outro: null };
|
|
|
|
|
|
|
|
|
|
// Return cached result if available
|
|
|
|
|
if (!this._sponsorBlockCache) this._sponsorBlockCache = {};
|
|
|
|
|
if (this._sponsorBlockCache[videoId]) {
|
|
|
|
|
return this._sponsorBlockCache[videoId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&categories=["intro","outro"]`);
|
|
|
|
|
if (!response.ok) return { intro: null, outro: null };
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const result = { intro: null, outro: null };
|
|
|
|
|
this._sponsorBlockCache[videoId] = result;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const segments = await response.json();
|
|
|
|
|
let intro = null;
|
|
|
|
|
@@ -1274,7 +1285,9 @@ const ApiUtils = {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { intro, outro };
|
|
|
|
|
const result = { intro, outro };
|
|
|
|
|
this._sponsorBlockCache[videoId] = result;
|
|
|
|
|
return result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Error fetching SponsorBlock data:', error);
|
|
|
|
|
return { intro: null, outro: null };
|
|
|
|
|
@@ -1709,13 +1722,6 @@ const SlideCreator = {
|
|
|
|
|
event.target._endTime = playerVars.end || undefined;
|
|
|
|
|
event.target._videoId = videoId;
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
event.target.mute();
|
|
|
|
|
} else {
|
|
|
|
|
event.target.unMute();
|
|
|
|
|
event.target.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof event.target.setPlaybackQuality === 'function') {
|
|
|
|
|
event.target.setPlaybackQuality(quality);
|
|
|
|
|
}
|
|
|
|
|
@@ -1725,6 +1731,14 @@ const SlideCreator = {
|
|
|
|
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
|
|
|
|
|
|
if (slide && slide.classList.contains('active') && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
|
// Set mute state only for active slide
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
event.target.mute();
|
|
|
|
|
} else {
|
|
|
|
|
event.target.unMute();
|
|
|
|
|
event.target.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event.target.playVideo();
|
|
|
|
|
|
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
|
@@ -1754,11 +1768,20 @@ const SlideCreator = {
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
event.target.mute();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
|
if (event.data === YT.PlayerState.ENDED) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
} else {
|
|
|
|
|
event.target.playVideo(); // Loop if trailer is shorter than slide duration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'onError': (event) => {
|
|
|
|
|
@@ -2275,29 +2298,26 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
if (previousVisibleSlide) {
|
|
|
|
|
previousVisibleSlide.classList.remove("active");
|
|
|
|
|
previousVisibleSlide.setAttribute("inert", "");
|
|
|
|
|
previousVisibleSlide.setAttribute("tabindex", "-1");
|
|
|
|
|
// previousVisibleSlide.setAttribute("inert", "");
|
|
|
|
|
// previousVisibleSlide.setAttribute("tabindex", "-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentSlide.classList.add("active");
|
|
|
|
|
currentSlide.removeAttribute("inert");
|
|
|
|
|
currentSlide.setAttribute("tabindex", "0");
|
|
|
|
|
|
|
|
|
|
// Update Play/Pause Button State if it was paused
|
|
|
|
|
if (STATE.slideshow.isPaused) {
|
|
|
|
|
STATE.slideshow.isPaused = false;
|
|
|
|
|
const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
if (pauseButton) {
|
|
|
|
|
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
pauseButton.setAttribute("aria-label", pauseLabel);
|
|
|
|
|
pauseButton.setAttribute("title", pauseLabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// // Update Play/Pause Button State if it was paused
|
|
|
|
|
// if (STATE.slideshow.isPaused) {
|
|
|
|
|
// STATE.slideshow.isPaused = false;
|
|
|
|
|
// const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
// if (pauseButton) {
|
|
|
|
|
// pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
// const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
// pauseButton.setAttribute("aria-label", pauseLabel);
|
|
|
|
|
// pauseButton.setAttribute("title", pauseLabel);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
|
|
|
|
|
// 1. Pause all other YouTube players
|
|
|
|
|
// 1. Stop all other YouTube players
|
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
|
if (id !== currentItemId) {
|
|
|
|
|
@@ -2313,13 +2333,24 @@ const SlideshowManager = {
|
|
|
|
|
document.querySelectorAll('video').forEach(video => {
|
|
|
|
|
if (!video.closest(`.slide[data-item-id="${currentItemId}"]`)) {
|
|
|
|
|
video.pause();
|
|
|
|
|
video.muted = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 3. Play and Reset current video
|
|
|
|
|
const videoBackdrop = currentSlide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
// Auto-unpause when a video slide becomes active
|
|
|
|
|
if (videoBackdrop && STATE.slideshow.isPaused) {
|
|
|
|
|
STATE.slideshow.isPaused = false;
|
|
|
|
|
const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
if (pauseButton) {
|
|
|
|
|
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
pauseButton.setAttribute("aria-label", pauseLabel);
|
|
|
|
|
pauseButton.setAttribute("title", pauseLabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update mute button visibility
|
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
|
if (muteButton) {
|
|
|
|
|
@@ -2339,8 +2370,8 @@ const SlideshowManager = {
|
|
|
|
|
videoBackdrop.play().catch(e => {
|
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (videoBackdrop.paused) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`);
|
|
|
|
|
if (videoBackdrop.paused && currentSlide.classList.contains('active')) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${currentItemId}, attempting muted fallback`);
|
|
|
|
|
videoBackdrop.muted = true;
|
|
|
|
|
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err));
|
|
|
|
|
}
|
|
|
|
|
@@ -2365,6 +2396,7 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
// Check if playback successfully started, otherwise fallback to muted
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (!currentSlide.classList.contains('active')) return;
|
|
|
|
|
if (player.getPlayerState &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
|
|