From f0a5f8627aa40476d4711e0962e62ca317bbb967 Mon Sep 17 00:00:00 2001 From: Dark_Ville <42322979+DarkVillager@users.noreply.github.com> Date: Wed, 16 Aug 2023 02:57:04 +0200 Subject: [PATCH] fix(Youtube): fix & optimize yt-shorts (#7580) --- websites/Y/YouTube/metadata.json | 2 +- websites/Y/YouTube/presence.ts | 61 ++++++++++++-------------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/websites/Y/YouTube/metadata.json b/websites/Y/YouTube/metadata.json index 38e76bd11609..54f506c87752 100644 --- a/websites/Y/YouTube/metadata.json +++ b/websites/Y/YouTube/metadata.json @@ -67,7 +67,7 @@ "www.youtube.com", "studio.youtube.com" ], - "version": "5.4.8", + "version": "5.4.9", "logo": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube/assets/thumbnail.jpg", "color": "#E40813", diff --git a/websites/Y/YouTube/presence.ts b/websites/Y/YouTube/presence.ts index 313b994d633e..3ab9e44c53bd 100644 --- a/websites/Y/YouTube/presence.ts +++ b/websites/Y/YouTube/presence.ts @@ -15,6 +15,7 @@ function truncateAfter(str: string, pattern: string): string { } let cached: { id: string; uploader: string; channelURL: string }, + fetched: { id: string; uploader: string; channelURL: string }, closest: Element; function delay(ms: number) { @@ -23,47 +24,31 @@ function delay(ms: number) { async function cacheIt(hostname: string, shortsPath: string) { if (!cached?.id || cached.id !== shortsPath) { - if (!cached) { - closest = - document - .querySelectorAll("video")[1] - ?.closest("#player") - ?.parentElement?.parentElement?.querySelector( - '[spellcheck="false"]' - ) ?? - document - .querySelectorAll("video")[0] - ?.closest("#player") - ?.parentElement?.parentElement?.querySelector('[spellcheck="false"]'); - } else { - await delay(300); - closest = - document - .querySelectorAll("video")[1] - ?.closest("#player") - ?.parentElement?.parentElement?.querySelector( - '[class="yt-simple-endpoint style-scope yt-formatted-string"]' - ) ?? - document - .querySelectorAll("video")[0] - ?.closest("#player") - ?.parentElement?.parentElement?.querySelector( - '[class="yt-simple-endpoint style-scope yt-formatted-string"]' - ); - } - const fetched = { + await delay(300); + closest = + document + .querySelectorAll("video")[0] + ?.closest("ytd-reel-video-renderer") + ?.querySelector( + "yt-formatted-string#text.style-scope.ytd-channel-name" + ) ?? + document + .querySelectorAll("video")[1] + ?.closest("ytd-reel-video-renderer") + ?.querySelector( + "yt-formatted-string#text.style-scope.ytd-channel-name" + ); + fetched = { id: shortsPath, - uploader: - closest?.textContent ?? - document - .querySelectorAll('div[class="style-scope ytd-channel-name"]')[2] - .querySelector( - '[class="yt-simple-endpoint style-scope yt-formatted-string"]' - )?.textContent, - channelURL: `https://${hostname}${closest?.getAttribute("href")}`, + uploader: `${closest + .querySelector("a") + ?.getAttribute("href") + ?.replace("/", "") + ?.replace("@", "")} (${closest?.textContent})`, + channelURL: `https://${hostname}/${closest?.textContent}`, }; cached = fetched; - return fetched; + return cached; } else return cached; }