Skip to content

Commit

Permalink
feat(Trakt): display show and movie covers (#9120)
Browse files Browse the repository at this point in the history
Co-authored-by: Anaxes <DiscordAnaxes@users.noreply.github.com>
  • Loading branch information
DiscordAnaxes and DiscordAnaxes authored Jan 7, 2025
1 parent d1b5db3 commit 24d12cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion websites/T/Trakt/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"en": "Track what you watch and when. Discover what's hot and where you can watch it. Share comments, ratings and recommendations."
},
"url": "trakt.tv",
"version": "1.0.10",
"version": "1.0.11",
"logo": "https://cdn.rcd.gg/PreMiD/websites/T/Trakt/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/T/Trakt/assets/thumbnail.png",
"color": "#ff0000",
Expand Down
18 changes: 16 additions & 2 deletions websites/T/Trakt/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ const presence = new Presence({
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://cdn.rcd.gg/PreMiD/websites/T/Trakt/assets/logo.png",
}
presence.on("UpdateData", async () => {
let presenceData: PresenceData = {
largeImageKey: "https://cdn.rcd.gg/PreMiD/websites/T/Trakt/assets/logo.png",
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
};

Expand Down Expand Up @@ -74,7 +77,8 @@ presence.on("UpdateData", async () => {
"/auth/signin": { details: "Registering on Trakt" },
"/auth/login": { details: "Logging in to Trakt" },
"/widgets": { details: "Browsing widgets" },
};
},
imagePath = document.querySelector("img.real")?.getAttribute("src");

for (const [path, data] of Object.entries(pages))
if (pathname.includes(path)) presenceData = { ...presenceData, ...data };
Expand Down Expand Up @@ -115,6 +119,8 @@ presence.on("UpdateData", async () => {
"#summary-wrapper > div.container.summary > div > div > div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title > h1 > span.main-title"
).textContent
}`;
presenceData.largeImageKey = imagePath;
presenceData.smallImageKey = Assets.Logo;
presenceData.buttons = [{ label: "Check episode", url: href }];
} else if (pathname.includes("/seasons/")) {
presenceData.details = "Browsing season";
Expand All @@ -125,13 +131,17 @@ presence.on("UpdateData", async () => {
"#summary-wrapper > div.container.summary > div > div > div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title > h1"
).firstChild.textContent
}`;
presenceData.largeImageKey = imagePath;
presenceData.smallImageKey = Assets.Logo;
presenceData.buttons = [{ label: "Check season", url: href }];
} else {
try {
presenceData.details = "Browsing TV show";
presenceData.state = document.querySelector(
"#summary-wrapper > div.container.summary > div > div > div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title > h1"
).firstChild.textContent;
presenceData.largeImageKey = imagePath;
presenceData.smallImageKey = Assets.Logo;
presenceData.buttons = [{ label: "Check TV show", url: href }];
} catch {
presenceData.details = "Browsing";
Expand All @@ -143,6 +153,8 @@ presence.on("UpdateData", async () => {
presenceData.state = document.querySelector(
"#summary-wrapper > div.container.summary > div > div > div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title > h1"
).childNodes[0].textContent;
presenceData.largeImageKey = imagePath;
presenceData.smallImageKey = Assets.Logo;
presenceData.buttons = [{ label: "Check movie", url: href }];
} catch {
presenceData.details = "Browsing";
Expand All @@ -152,6 +164,8 @@ presence.on("UpdateData", async () => {
presenceData.state = document.querySelector(
"#summary-wrapper > div.container.summary > div > div > div.col-md-10.col-md-offset-2.col-sm-9.col-sm-offset-3.mobile-title > h1"
).textContent;
presenceData.largeImageKey = imagePath;
presenceData.smallImageKey = Assets.Logo;
presenceData.buttons = [{ label: "Check actor", url: href }];
} else if (pathname.includes("/search")) {
presenceData.details = "Searching for";
Expand Down

0 comments on commit 24d12cd

Please sign in to comment.