Skip to content

Commit

Permalink
fix(Youtube): fix & optimize yt-shorts (PreMiD#7580)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark_Ville authored Aug 16, 2023
1 parent 5b6a800 commit f0a5f86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion websites/Y/YouTube/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 23 additions & 38 deletions websites/Y/YouTube/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit f0a5f86

Please sign in to comment.