From a9a85d9816750427bc36a927808ea347bdb47bcf Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 31 May 2021 14:33:17 -0400 Subject: [PATCH] Clean segment recieving code --- src/content.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/content.ts b/src/content.ts index d3d44a78..5f43ae75 100644 --- a/src/content.ts +++ b/src/content.ts @@ -568,25 +568,15 @@ async function sponsorsLookup(id: string) { categories }).then(async (response: FetchResponse) => { if (response?.ok) { - let result = JSON.parse(response.responseText); - result = result.filter((video) => video.videoID === id); - if (result.length > 0) { - result = result[0].segments; - if (result.length === 0) { // return if no segments found - retryFetch(); - return; - } - } else { // return if no video found + const recievedSegments: SponsorTime[] = JSON.parse(response.responseText) + ?.filter((video) => video.videoID === id) + ?.map((video) => video.segments)[0]; + if (!recievedSegments || !recievedSegments.length) { + // return if no video found retryFetch(); return; } - const recievedSegments: SponsorTime[] = result; - if (!recievedSegments.length) { - console.error("[SponsorBlock] Server returned malformed response: " + JSON.stringify(recievedSegments)); - return; - } - sponsorDataFound = true; // Check if any old submissions should be kept