Skip to content

Commit

Permalink
handle multiple thumbnail label insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Jan 15, 2025
1 parent 77c548e commit cd4905e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/thumbnail-utils/thumbnails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function labelThumbnail(thumbnail: HTMLElement, containerType: stri
);
if (videoIDs.size !== 1) {
// none or multiple video IDs found
hideThumbnailLabel(thumbnail);
await hideThumbnailLabel(thumbnail);
return null;
}
const [videoID] = videoIDs;
Expand All @@ -43,7 +43,7 @@ export async function labelThumbnail(thumbnail: HTMLElement, containerType: stri

const category = await getVideoLabel(videoID);
if (!category) {
hideThumbnailLabel(thumbnail);
await hideThumbnailLabel(thumbnail);
return null;
}

Expand All @@ -65,12 +65,12 @@ export async function labelThumbnail(thumbnail: HTMLElement, containerType: stri
return overlay;
}

function getOldThumbnailLabel(thumbnail: HTMLElement): HTMLElement | null {
return thumbnail.querySelector("#sponsorThumbnailLabel") as HTMLElement | null;
async function getOldThumbnailLabel(thumbnail: HTMLElement): Promise<HTMLElement> {
return waitFor(() => thumbnail.querySelector("#sponsorThumbnailLabel"), 50, 5).catch(() => null);
}

function hideThumbnailLabel(thumbnail: HTMLElement): void {
const oldLabel = getOldThumbnailLabel(thumbnail);
async function hideThumbnailLabel(thumbnail: HTMLElement): Promise<void> {
const oldLabel = await getOldThumbnailLabel(thumbnail);
if (oldLabel) {
oldLabel.classList.remove("sponsorThumbnailLabelVisible");
oldLabel.removeAttribute("data-category");
Expand All @@ -81,7 +81,7 @@ async function createOrGetThumbnail(
thumbnail: HTMLElement,
containerType: string
): Promise<{ overlay: HTMLElement; text: HTMLElement }> {
const oldLabelElement = getOldThumbnailLabel(thumbnail);
const oldLabelElement = await getOldThumbnailLabel(thumbnail);
if (oldLabelElement) {
return {
overlay: oldLabelElement as HTMLElement,
Expand Down

0 comments on commit cd4905e

Please sign in to comment.