From 076f886e79d007af51c4975e98046088b07f54ad Mon Sep 17 00:00:00 2001 From: creations Date: Sun, 27 Apr 2025 18:16:48 -0400 Subject: [PATCH] add streaming button, fix twitch icon --- public/js/index.js | 60 +++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index ad16c65..1dd67aa 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -111,6 +111,11 @@ function resolveActivityImage(img, applicationId) { 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`; } @@ -166,31 +171,36 @@ function buildActivityHTML(activity) { ` : ""; - const activityButtons = - (activity.buttons && activity.buttons.length > 0 - ? `
- ${activity.buttons - .map((button, index) => { - const label = typeof button === "string" ? button : button.label; - let url = null; - if (typeof button === "object" && button.url) { - url = button.url; - } else if (index === 0 && activity.url) { - url = activity.url; - } - return url - ? `${label}` - : null; - }) - .filter(Boolean) - .join("")} -
` - : "") + - (activity.name === "Spotify" && activity.sync_id - ? `
- Listen on Spotify -
` - : ""); + const buttons = (activity.buttons || []) + .map((button, index) => { + const label = typeof button === "string" ? button : button.label; + let url = null; + if (typeof button === "object" && button.url) { + url = button.url; + } else if (index === 0 && activity.url) { + url = activity.url; + } + return url + ? `${label}` + : null; + }) + .filter(Boolean); + + if (!buttons.length && activity.name === "Twitch" && activity.url) { + buttons.push( + `Watch on Twitch`, + ); + } + + if (activity.name === "Spotify" && activity.sync_id) { + buttons.push( + `Listen on Spotify`, + ); + } + + const activityButtons = buttons.length + ? `
${buttons.join("")}
` + : ""; const progressBar = progress !== null