Load existing chapters

This commit is contained in:
Ajay
2022-02-22 21:22:30 -05:00
parent cf3b3c5c48
commit 2ebc5489cd
7 changed files with 90 additions and 28 deletions

View File

@@ -15,7 +15,7 @@ import { Message, MessageResponse, VoteResponse } from "./messageTypes";
import * as Chat from "./js-components/chat";
import { SkipButtonControlBar } from "./js-components/skipButtonControlBar";
import { getStartTimeFromUrl } from "./utils/urlParser";
import { findValidElement, getControls, getHashParams, isVisible } from "./utils/pageUtils";
import { findValidElement, getControls, getExistingChapters, getHashParams, isVisible } from "./utils/pageUtils";
import { isSafari, keybindEquals } from "./utils/configUtils";
import { CategoryPill } from "./render/CategoryPill";
import { AnimationUtils } from "./utils/animationUtils";
@@ -806,6 +806,17 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
//otherwise the listener can handle it
updatePreviewBar();
}
// Add existing chapters if we can
if (utils.chaptersEnabled()) {
GenericUtils.wait(() => getExistingChapters(sponsorVideoID, video.duration),
5000, 100, (c) => c?.length > 0).then((chapters) => {
if (chapters?.length > 0) {
sponsorTimes = sponsorTimes.concat(...chapters);
updatePreviewBar();
}
});
}
} else if (response?.status === 404) {
retryFetch();
}