aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2021-10-01 18:07:15 -0400
committerAjay Ramachandran <[email protected]>2021-10-01 18:07:15 -0400
commitef70e710511dfd977f6d53ef8d34b1ff748e70ee (patch)
treefc76fd9edcea48980fc26ed190fd4c70203f4b25
parent23a91c626d07f0267f28d1a0bd80f4ac606915ff (diff)
downloadSponsorBlock-ef70e710511dfd977f6d53ef8d34b1ff748e70ee.tar.gz
SponsorBlock-ef70e710511dfd977f6d53ef8d34b1ff748e70ee.zip
Fix segments not appearing when loaded early
-rw-r--r--src/content.ts8
-rw-r--r--src/types.ts1
2 files changed, 8 insertions, 1 deletions
diff --git a/src/content.ts b/src/content.ts
index 6d1dab93..1762eb54 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -386,6 +386,12 @@ function createPreviewBar(): void {
function durationChangeListener(): void {
updateAdFlag();
updatePreviewBar();
+
+ sponsorTimes = sponsorTimes.filter(segmentDurationFilter);
+}
+
+function segmentDurationFilter(segment: SponsorTime): boolean {
+ return segment.videoDuration === 0 || video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
}
function cancelSponsorSchedule(): void {
@@ -669,7 +675,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
const recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === id)
?.map((video) => video.segments)[0]
- ?.filter((segment) => segment.videoDuration === 0 || Math.abs(video.duration - segment.videoDuration) < 2);
+ ?.filter(segmentDurationFilter);
if (!recievedSegments || !recievedSegments.length) {
// return if no video found
retryFetch();
diff --git a/src/types.ts b/src/types.ts
index cb5cc0e2..c60e52bb 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -80,6 +80,7 @@ export interface SponsorTime {
hidden?: SponsorHideType;
source?: SponsorSourceType;
+ videoDuration?: number;
}
export interface ScheduledTime extends SponsorTime {