diff --git a/script.js b/script.js index 150b647..fc5c6f2 100644 --- a/script.js +++ b/script.js @@ -7,7 +7,7 @@ let useTrailers = true; // Set to false to disable trailers let setRandomMovie = true; // Set to false to disable random movie selection from the list let showOnOtherPages = false; // Set to true to show the slideshow on all pages eg. favorites tab, requests tab, etc. //let showTitle = false; // Set to false to hide the title TBD -let disableTrailerControls = true; // Set to false to enable trailer controls +let disableTrailerControls = false; // Set to false to enable trailer controls let setMutedHover = true; // Set to false to disable unmuting the video on hover let umuteOnHover = true; // Set to false to disable unmuting the video on hover let unmutedVolume = 20; // Set the volume level when the video is unmuted @@ -42,18 +42,28 @@ if (setMutedHover) { }); } -// Get SponsorBlock-Data for the outro segment of the trailer -const fetchSponsorBlockOutro = async (videoId) => { +// Get SponsorBlock-Data for the outro/intro segment of the trailer +const fetchSponsorBlockData = async (videoId) => { try { - const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&category=outro`); + const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&categories=["intro","outro"]`); const segments = await response.json(); - if (segments.length > 0 && Array.isArray(segments[0].segment)) { - return segments[0].segment; // returns array: [start, end] - } - return null; + + let intro = null; + let outro = null; + + segments.forEach(segment => { + if (segment.category === "intro" && Array.isArray(segment.segment)) { + intro = segment.segment; // [start, end] of the intro + } else if (segment.category === "outro" && Array.isArray(segment.segment)) { + outro = segment.segment; // [start, end] of the outro + } + }); + return { intro, outro }; } catch (error) { console.error('Error fetching SponsorBlock data:', error); return null; + //return { intro: null, outro: null }; + } }; @@ -287,15 +297,24 @@ const createSlideElement = (movie, hasVideo = false) => { events: { 'onReady': event => { if (useSponsorBlock) { - fetchSponsorBlockOutro(videoId).then(outroSegment => { - if (outroSegment) { - console.log(`SponsorBlock outro segment: Start - ${outroSegment[0]}s, End - ${outroSegment[1]}s`); + fetchSponsorBlockData(videoId).then(({ intro, outro }) => { + if (intro) { + console.log(`SponsorBlock intro segment: Start - ${intro[0]}s, End - ${intro[1]}s`); + if (player && typeof player.seekTo === 'function') { + player.seekTo(intro[1], true); + } + } else { + console.log('No intro segment found/provided'); + } + + if (outro) { + console.log(`SponsorBlock outro segment: Start - ${outro[0]}s, End - ${outro[1]}s`); monitorOutro(player, outroSegment); } else { console.log('No outro segment found/provided'); } }).catch(error => { - console.error('Error reading SponsorBlock outro segment:', error); + console.error('Error reading SponsorBlock data:', error); }); } if (trailerMaxLength > 0) {