mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-31 21:59:49 +03:00
Prevent error when video not loaded yet
This commit is contained in:
@@ -392,7 +392,8 @@ function durationChangeListener(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function segmentDurationFilter(segment: SponsorTime): boolean {
|
function segmentDurationFilter(segment: SponsorTime): boolean {
|
||||||
return segment.videoDuration === 0 || video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
|
return segment.videoDuration === 0 || !video
|
||||||
|
|| video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelSponsorSchedule(): void {
|
function cancelSponsorSchedule(): void {
|
||||||
@@ -922,7 +923,7 @@ function updatePreviewBar(): void {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
previewBar.set(previewBarSegments, video.duration)
|
previewBar.set(previewBarSegments, video?.duration)
|
||||||
|
|
||||||
if (Config.config.showTimeWithSkips) {
|
if (Config.config.showTimeWithSkips) {
|
||||||
const skippedDuration = utils.getTimestampsDuration(previewBarSegments.map(({segment}) => segment));
|
const skippedDuration = utils.getTimestampsDuration(previewBarSegments.map(({segment}) => segment));
|
||||||
@@ -1390,7 +1391,7 @@ function getRealCurrentTime(): number {
|
|||||||
|
|
||||||
if (playButtonSVGData === replaceSVGData) {
|
if (playButtonSVGData === replaceSVGData) {
|
||||||
// At the end of the video
|
// At the end of the video
|
||||||
return video.duration;
|
return video?.duration;
|
||||||
} else {
|
} else {
|
||||||
return video.currentTime;
|
return video.currentTime;
|
||||||
}
|
}
|
||||||
@@ -1890,7 +1891,7 @@ function showTimeWithoutSkips(skippedDuration: number): void {
|
|||||||
display.appendChild(duration);
|
display.appendChild(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
const durationAfterSkips = utils.getFormattedTime(video.duration - skippedDuration)
|
const durationAfterSkips = utils.getFormattedTime(video?.duration - skippedDuration)
|
||||||
|
|
||||||
duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")";
|
duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user