mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Fix starting segment sometimes not being skipped and duration filter
This commit is contained in:
@@ -388,12 +388,11 @@ function durationChangeListener(): void {
|
|||||||
updateAdFlag();
|
updateAdFlag();
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
|
|
||||||
sponsorTimes = sponsorTimes.filter(segmentDurationFilter);
|
if (sponsorTimes) sponsorTimes = sponsorTimes.filter(segmentDurationFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function segmentDurationFilter(segment: SponsorTime): boolean {
|
function segmentDurationFilter(segment: SponsorTime): boolean {
|
||||||
return segment.videoDuration === 0 || !video
|
return segment.videoDuration === 0 || !video?.duration || Math.abs(video.duration - segment.videoDuration) < 2;
|
||||||
|| video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelSponsorSchedule(): void {
|
function cancelSponsorSchedule(): void {
|
||||||
@@ -559,14 +558,18 @@ function setupVideoListeners() {
|
|||||||
switchingVideos = false;
|
switchingVideos = false;
|
||||||
|
|
||||||
video.addEventListener('play', () => {
|
video.addEventListener('play', () => {
|
||||||
switchingVideos = false;
|
|
||||||
|
|
||||||
// If it is not the first event, then the only way to get to 0 is if there is a seek event
|
// If it is not the first event, then the only way to get to 0 is if there is a seek event
|
||||||
// This check makes sure that changing the video resolution doesn't cause the extension to think it
|
// This check makes sure that changing the video resolution doesn't cause the extension to think it
|
||||||
// gone back to the begining
|
// gone back to the begining
|
||||||
if (!firstEvent && video.currentTime === 0) return;
|
if (!firstEvent && video.currentTime === 0) return;
|
||||||
firstEvent = false;
|
firstEvent = false;
|
||||||
|
|
||||||
|
if (switchingVideos) {
|
||||||
|
switchingVideos = false;
|
||||||
|
// If already segments loaded before video, retry to skip starting segments
|
||||||
|
if (sponsorTimes) startSkipScheduleCheckingForStartSponsors();
|
||||||
|
}
|
||||||
|
|
||||||
// Check if an ad is playing
|
// Check if an ad is playing
|
||||||
updateAdFlag();
|
updateAdFlag();
|
||||||
|
|
||||||
@@ -770,7 +773,7 @@ function retryFetch(): void {
|
|||||||
* Ex. When segments are first loaded
|
* Ex. When segments are first loaded
|
||||||
*/
|
*/
|
||||||
function startSkipScheduleCheckingForStartSponsors() {
|
function startSkipScheduleCheckingForStartSponsors() {
|
||||||
if (!switchingVideos) {
|
if (!switchingVideos && sponsorTimes) {
|
||||||
// See if there are any starting sponsors
|
// See if there are any starting sponsors
|
||||||
let startingSegmentTime = -1;
|
let startingSegmentTime = -1;
|
||||||
let startingSegment: SponsorTime = null;
|
let startingSegment: SponsorTime = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user