add streaming button, fix twitch icon
All checks were successful
Code quality checks / biome (push) Successful in 9s

This commit is contained in:
creations 2025-04-27 18:16:48 -04:00
parent af872d538c
commit 076f886e79
Signed by: creations
GPG key ID: 8F553AA4320FC711

View file

@ -111,6 +111,11 @@ function resolveActivityImage(img, applicationId) {
return `https://i.scdn.co/image/${img.split(":")[1]}`; return `https://i.scdn.co/image/${img.split(":")[1]}`;
} }
if (img.startsWith("twitch:")) {
const username = img.split(":")[1];
return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${username}-440x248.jpg`;
}
return `https://cdn.discordapp.com/app-assets/${applicationId}/${img}.png`; return `https://cdn.discordapp.com/app-assets/${applicationId}/${img}.png`;
} }
@ -166,31 +171,36 @@ function buildActivityHTML(activity) {
</div>` </div>`
: ""; : "";
const activityButtons = const buttons = (activity.buttons || [])
(activity.buttons && activity.buttons.length > 0 .map((button, index) => {
? `<div class="activity-buttons"> const label = typeof button === "string" ? button : button.label;
${activity.buttons let url = null;
.map((button, index) => { if (typeof button === "object" && button.url) {
const label = typeof button === "string" ? button : button.label; url = button.url;
let url = null; } else if (index === 0 && activity.url) {
if (typeof button === "object" && button.url) { url = activity.url;
url = button.url; }
} else if (index === 0 && activity.url) { return url
url = activity.url; ? `<a href="${url}" class="activity-button" target="_blank" rel="noopener noreferrer">${label}</a>`
} : null;
return url })
? `<a href="${url}" class="activity-button" target="_blank" rel="noopener noreferrer">${label}</a>` .filter(Boolean);
: null;
}) if (!buttons.length && activity.name === "Twitch" && activity.url) {
.filter(Boolean) buttons.push(
.join("")} `<a href="${activity.url}" class="activity-button" target="_blank" rel="noopener noreferrer">Watch on Twitch</a>`,
</div>` );
: "") + }
(activity.name === "Spotify" && activity.sync_id
? `<div class="activity-buttons"> if (activity.name === "Spotify" && activity.sync_id) {
<a href="https://open.spotify.com/track/${activity.sync_id}" class="activity-button" target="_blank" rel="noopener noreferrer">Listen on Spotify</a> buttons.push(
</div>` `<a href="https://open.spotify.com/track/${activity.sync_id}" class="activity-button" target="_blank" rel="noopener noreferrer">Listen on Spotify</a>`,
: ""); );
}
const activityButtons = buttons.length
? `<div class="activity-buttons">${buttons.join("")}</div>`
: "";
const progressBar = const progressBar =
progress !== null progress !== null