diff --git a/src/content.ts b/src/content.ts index 647dbe2e..4e1a6545 100644 --- a/src/content.ts +++ b/src/content.ts @@ -13,6 +13,7 @@ import { PlayerButton } from "./render/PlayerButton"; import SkipNotice from "./render/SkipNotice"; import SubmissionNotice from "./render/SubmissionNotice"; import { asyncRequestToServer } from "./requests/requests"; +import { getVideoLabel } from "./requests/videoLabels"; import { setupThumbnailListener, updateAll } from "./thumbnail-utils/thumbnailManagement"; import { ActionType, @@ -2374,6 +2375,8 @@ async function sendSubmitMessage(): Promise { const fullVideoSegment = sponsorTimes.filter((time) => time.actionType === ActionType.Full)[0]; if (fullVideoSegment) { categoryPill?.setSegment(fullVideoSegment); + // refresh the video labels cache + getVideoLabel(getVideoID(), true); } return true; diff --git a/src/requests/videoLabels.ts b/src/requests/videoLabels.ts index 41dacadf..1e074eba 100644 --- a/src/requests/videoLabels.ts +++ b/src/requests/videoLabels.ts @@ -14,14 +14,14 @@ export interface LabelCacheEntry { const labelCache: Record = {}; const cacheLimit = 1000; -async function getLabelHashBlock(hashPrefix: string): Promise { +async function getLabelHashBlock(hashPrefix: string, refreshCache: boolean = false): Promise { // Check cache const cachedEntry = labelCache[hashPrefix]; - if (cachedEntry) { + if (cachedEntry && !refreshCache) { return cachedEntry; } - const response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}`); + const response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}`, {}, refreshCache); if (response.status !== 200) { // No video labels or server down labelCache[hashPrefix] = { @@ -54,9 +54,9 @@ async function getLabelHashBlock(hashPrefix: string): Promise { +export async function getVideoLabel(videoID: VideoID, refreshCache: boolean = false): Promise { const prefix = (await getVideoIDHash(videoID)).slice(0, 3); - const result = await getLabelHashBlock(prefix); + const result = await getLabelHashBlock(prefix, refreshCache); if (result) { const category = result.videos[videoID];