From fd260f4caa97f3f5520936de4e859f50bef7d783 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 3 May 2022 14:28:05 -0400 Subject: [PATCH] Fix old video ids potentially being fetched --- src/content.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/content.ts b/src/content.ts index 655259ef..f24c03af 100644 --- a/src/content.ts +++ b/src/content.ts @@ -195,14 +195,14 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo break; case "whitelistChange": channelWhitelisted = request.value; - sponsorsLookup(sponsorVideoID); + sponsorsLookup(); break; case "submitTimes": submitSponsorTimes(); break; case "refreshSegments": - sponsorsLookup(sponsorVideoID, false).then(() => sendResponse({ + sponsorsLookup(false).then(() => sendResponse({ found: sponsorDataFound, sponsorTimes: sponsorTimes, onMobileYouTube @@ -235,7 +235,7 @@ function contentConfigUpdateListener(changes: StorageChangesObject) { updateVisibilityOfPlayerControlsButton() break; case "categorySelections": - sponsorsLookup(sponsorVideoID); + sponsorsLookup(); break; } } @@ -747,11 +747,11 @@ function setupCategoryPill() { categoryPill.attachToPage(onMobileYouTube, onInvidious, voteAsync); } -async function sponsorsLookup(id: string, keepOldSubmissions = true) { +async function sponsorsLookup(keepOldSubmissions = true) { if (!video || !isVisible(video)) refreshVideoAttachments(); //there is still no video here if (!video) { - setTimeout(() => sponsorsLookup(id), 100); + setTimeout(() => sponsorsLookup(), 100); return; } @@ -765,7 +765,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment; // Check for hashPrefix setting - const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4) as VideoID & HashedValue; + const hashPrefix = (await utils.getHash(sponsorVideoID, 1)).slice(0, 4) as VideoID & HashedValue; const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, { categories, actionTypes: getEnabledActionTypes(), @@ -775,7 +775,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { if (response?.ok) { const recievedSegments: SponsorTime[] = JSON.parse(response.responseText) - ?.filter((video) => video.videoID === id) + ?.filter((video) => video.videoID === sponsorVideoID) ?.map((video) => video.segments)[0]; if (!recievedSegments || !recievedSegments.length) { // return if no video found @@ -835,7 +835,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { //update the preview bar //leave the type blank for now until categories are added - if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(video.duration))) { + if (lastPreviewBarUpdate == sponsorVideoID || (lastPreviewBarUpdate == null && !isNaN(video.duration))) { //set it now //otherwise the listener can handle it updatePreviewBar(); @@ -845,7 +845,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { } if (Config.config.isVip) { - lockedCategoriesLookup(id); + lockedCategoriesLookup(); } } @@ -861,13 +861,13 @@ function getEnabledActionTypes(): ActionType[] { return actionTypes; } -async function lockedCategoriesLookup(id: string): Promise { - const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4); +async function lockedCategoriesLookup(): Promise { + const hashPrefix = (await utils.getHash(sponsorVideoID, 1)).slice(0, 4); const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix); if (response.ok) { try { - const categoriesResponse = JSON.parse(response.responseText).filter((lockInfo) => lockInfo.videoID === id)[0]?.categories; + const categoriesResponse = JSON.parse(response.responseText).filter((lockInfo) => lockInfo.videoID === sponsorVideoID)[0]?.categories; if (Array.isArray(categoriesResponse)) { lockedCategories = categoriesResponse; } @@ -882,7 +882,7 @@ function retryFetch(): void { setTimeout(() => { if (sponsorVideoID && sponsorTimes?.length === 0) { - sponsorsLookup(sponsorVideoID); + sponsorsLookup(); } }, 10000 + Math.random() * 30000); } @@ -1593,7 +1593,7 @@ function startOrEndTimingNewSegment() { Config.forceSyncUpdate("unsubmittedSegments"); // Make sure they know if someone has already submitted something it while they were watching - sponsorsLookup(sponsorVideoID); + sponsorsLookup(); updateEditButtonsOnPlayer(); updateSponsorTimesSubmitting(false); @@ -1908,7 +1908,7 @@ async function sendSubmitMessage() { return; } - sponsorsLookup(sponsorVideoID); + sponsorsLookup(); // Add loading animation playerButtons.submit.image.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker.svg");