|
|
|
@@ -1258,9 +1258,20 @@ const ApiUtils = {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async fetchSponsorBlockData(videoId) {
|
|
|
|
async fetchSponsorBlockData(videoId) {
|
|
|
|
if (!CONFIG.useSponsorBlock) return { intro: null, outro: null };
|
|
|
|
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 {
|
|
|
|
try {
|
|
|
|
const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&categories=["intro","outro"]`);
|
|
|
|
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();
|
|
|
|
const segments = await response.json();
|
|
|
|
let intro = null;
|
|
|
|
let intro = null;
|
|
|
|
@@ -1274,7 +1285,9 @@ const ApiUtils = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return { intro, outro };
|
|
|
|
const result = { intro, outro };
|
|
|
|
|
|
|
|
this._sponsorBlockCache[videoId] = result;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.warn('Error fetching SponsorBlock data:', error);
|
|
|
|
console.warn('Error fetching SponsorBlock data:', error);
|
|
|
|
return { intro: null, outro: null };
|
|
|
|
return { intro: null, outro: null };
|
|
|
|
@@ -1758,10 +1771,13 @@ const SlideCreator = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
if (event.data === YT.PlayerState.ENDED) {
|
|
|
|
if (event.data === YT.PlayerState.ENDED) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
} else {
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
event.target.playVideo(); // Loop if not waiting for end if trailer is shorter than slide duration
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
event.target.playVideo(); // Loop if trailer is shorter than slide duration
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@@ -1804,15 +1820,23 @@ const SlideCreator = {
|
|
|
|
STATE.slideshow.videoPlayers[itemId] = backdrop;
|
|
|
|
STATE.slideshow.videoPlayers[itemId] = backdrop;
|
|
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('play', () => {
|
|
|
|
backdrop.addEventListener('play', () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// backdrop.addEventListener('play', (event) => {
|
|
|
|
|
|
|
|
// const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!slide || !slide.classList.contains('active')) {
|
|
|
|
|
|
|
|
// console.log(`Local video ${itemId} started playing but is not active, pausing.`);
|
|
|
|
|
|
|
|
// event.target.pause();
|
|
|
|
|
|
|
|
// event.target.currentTime = 0;
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('ended', () => {
|
|
|
|
backdrop.addEventListener('ended', () => {
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('error', () => {
|
|
|
|
backdrop.addEventListener('error', () => {
|
|
|
|
@@ -2271,13 +2295,26 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
|
|
if (previousVisibleSlide) {
|
|
|
|
if (previousVisibleSlide) {
|
|
|
|
previousVisibleSlide.classList.remove("active");
|
|
|
|
previousVisibleSlide.classList.remove("active");
|
|
|
|
|
|
|
|
// previousVisibleSlide.setAttribute("inert", "");
|
|
|
|
|
|
|
|
// previousVisibleSlide.setAttribute("tabindex", "-1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentSlide.classList.add("active");
|
|
|
|
currentSlide.classList.add("active");
|
|
|
|
|
|
|
|
// // 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
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Pause all other YouTube players
|
|
|
|
// 1. Stop all other YouTube players
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
if (id !== currentItemId) {
|
|
|
|
if (id !== currentItemId) {
|
|
|
|
@@ -2299,6 +2336,18 @@ const SlideshowManager = {
|
|
|
|
// 3. Play and Reset current video
|
|
|
|
// 3. Play and Reset current video
|
|
|
|
const videoBackdrop = currentSlide.querySelector('.video-backdrop');
|
|
|
|
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
|
|
|
|
// Update mute button visibility
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
if (muteButton) {
|
|
|
|
if (muteButton) {
|
|
|
|
@@ -2318,8 +2367,8 @@ const SlideshowManager = {
|
|
|
|
videoBackdrop.play().catch(e => {
|
|
|
|
videoBackdrop.play().catch(e => {
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (videoBackdrop.paused) {
|
|
|
|
if (videoBackdrop.paused && currentSlide.classList.contains('active')) {
|
|
|
|
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`);
|
|
|
|
console.warn(`Autoplay blocked for ${currentItemId}, attempting muted fallback`);
|
|
|
|
videoBackdrop.muted = true;
|
|
|
|
videoBackdrop.muted = true;
|
|
|
|
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err));
|
|
|
|
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -2344,6 +2393,7 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
|
|
// Check if playback successfully started, otherwise fallback to muted
|
|
|
|
// Check if playback successfully started, otherwise fallback to muted
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
if (!currentSlide.classList.contains('active')) return;
|
|
|
|
if (player.getPlayerState &&
|
|
|
|
if (player.getPlayerState &&
|
|
|
|
player.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
player.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
player.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
player.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
@@ -2394,7 +2444,8 @@ const SlideshowManager = {
|
|
|
|
this.updateDots();
|
|
|
|
this.updateDots();
|
|
|
|
|
|
|
|
|
|
|
|
// Only restart interval if we are NOT waiting for a video to end
|
|
|
|
// Only restart interval if we are NOT waiting for a video to end
|
|
|
|
const hasVideo = currentSlide.querySelector('.video-backdrop');
|
|
|
|
const hasVideo = currentSlide.querySelector('.video-backdrop') ||
|
|
|
|
|
|
|
|
(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]);
|
|
|
|
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
|
|
|
|
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd && hasVideo) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd && hasVideo) {
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
@@ -2454,20 +2505,24 @@ const SlideshowManager = {
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
const preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
const preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
const preloadedIds = new Set();
|
|
|
|
const preloadedIds = new Set();
|
|
|
|
|
|
|
|
|
|
|
|
// Preload next slides
|
|
|
|
// Preload next slides
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
const nextIndex = (currentIndex + i) % totalItems;
|
|
|
|
const nextIndex = (currentIndex + i) % totalItems;
|
|
|
|
if (nextIndex === currentIndex) break;
|
|
|
|
if (nextIndex === currentIndex) break;
|
|
|
|
|
|
|
|
|
|
|
|
const itemId = STATE.slideshow.itemIds[nextIndex];
|
|
|
|
const itemId = STATE.slideshow.itemIds[nextIndex];
|
|
|
|
if (!preloadedIds.has(itemId)) {
|
|
|
|
if (!preloadedIds.has(itemId)) {
|
|
|
|
preloadedIds.add(itemId);
|
|
|
|
preloadedIds.add(itemId);
|
|
|
|
SlideCreator.createSlideForItemId(itemId);
|
|
|
|
SlideCreator.createSlideForItemId(itemId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Preload previous slides
|
|
|
|
// Preload previous slides
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
const prevIndex = (currentIndex - i + totalItems) % totalItems;
|
|
|
|
const prevIndex = (currentIndex - i + totalItems) % totalItems;
|
|
|
|
if (prevIndex === currentIndex) break;
|
|
|
|
if (prevIndex === currentIndex) break;
|
|
|
|
|
|
|
|
|
|
|
|
const prevItemId = STATE.slideshow.itemIds[prevIndex];
|
|
|
|
const prevItemId = STATE.slideshow.itemIds[prevIndex];
|
|
|
|
if (!preloadedIds.has(prevItemId)) {
|
|
|
|
if (!preloadedIds.has(prevItemId)) {
|
|
|
|
preloadedIds.add(prevItemId);
|
|
|
|
preloadedIds.add(prevItemId);
|
|
|
|
@@ -2724,18 +2779,24 @@ const SlideshowManager = {
|
|
|
|
const currentSlide = document.querySelector(`.slide[data-item-id="${currentItemId}"]`);
|
|
|
|
const currentSlide = document.querySelector(`.slide[data-item-id="${currentItemId}"]`);
|
|
|
|
if (!currentSlide) return;
|
|
|
|
if (!currentSlide) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Try YouTube Player
|
|
|
|
// YouTube player: just resume, don't reload
|
|
|
|
const ytPlayer = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
const ytPlayer = STATE.slideshow.videoPlayers?.[currentItemId];
|
|
|
|
if (ytPlayer && typeof ytPlayer.playVideo === 'function') {
|
|
|
|
if (ytPlayer && typeof ytPlayer.playVideo === 'function') {
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
|
|
|
if (typeof ytPlayer.mute === 'function') ytPlayer.mute();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (typeof ytPlayer.unMute === 'function') ytPlayer.unMute();
|
|
|
|
|
|
|
|
if (typeof ytPlayer.setVolume === 'function') ytPlayer.setVolume(40);
|
|
|
|
|
|
|
|
}
|
|
|
|
ytPlayer.playVideo();
|
|
|
|
ytPlayer.playVideo();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Try HTML5 Video
|
|
|
|
// HTML5 video: just resume, don't reset currentTime
|
|
|
|
const html5Video = currentSlide.querySelector('video');
|
|
|
|
const html5Video = currentSlide.querySelector('video.video-backdrop');
|
|
|
|
if (html5Video) {
|
|
|
|
if (html5Video) {
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
html5Video.muted = STATE.slideshow.isMuted;
|
|
|
|
html5Video.muted = true;
|
|
|
|
if (!STATE.slideshow.isMuted) html5Video.volume = 0.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
html5Video.play().catch(e => console.warn("Error resuming HTML5 video:", e));
|
|
|
|
html5Video.play().catch(e => console.warn("Error resuming HTML5 video:", e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|