From 0513a36a9ae34ce76cbc15696373ca7dd643c0de Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 23 Feb 2022 01:30:07 -0500 Subject: [PATCH] Fix chapters getting imported multiple times --- src/content.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/content.ts b/src/content.ts index b59ea0e1..2f8deb40 100644 --- a/src/content.ts +++ b/src/content.ts @@ -28,6 +28,7 @@ utils.wait(() => Config.config !== null, 5000, 10).then(addCSS); let sponsorDataFound = false; //the actual sponsorTimes if loaded and UUIDs associated with them let sponsorTimes: SponsorTime[] = null; +let existingChaptersImported = false; //what video id are these sponsors for let sponsorVideoID: VideoID = null; // List of open skip notices @@ -246,8 +247,8 @@ function resetValues() { lastCheckTime = 0; lastCheckVideoTime = -1; - //reset sponsor times sponsorTimes = null; + existingChaptersImported = false; sponsorSkipped = []; videoInfo = null; @@ -763,6 +764,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { const oldSegments = sponsorTimes || []; sponsorTimes = recievedSegments; + existingChaptersImported = false; // Hide all submissions smaller than the minimum duration if (Config.config.minDuration !== 0) { @@ -811,8 +813,9 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { if (Config.config.renderAsChapters) { GenericUtils.wait(() => getExistingChapters(sponsorVideoID, video.duration), 5000, 100, (c) => c?.length > 0).then((chapters) => { - if (chapters?.length > 0) { + if (!existingChaptersImported && chapters?.length > 0) { sponsorTimes = sponsorTimes.concat(...chapters); + existingChaptersImported = true; updatePreviewBar(); } });