From 5e8eb7ea2bb93344e91acd86aa246011be3267bd Mon Sep 17 00:00:00 2001 From: lanewills <94198057+lanewills@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:25:29 -0400 Subject: [PATCH] feat(Poolsuite FM): add presence (#7740) * feat(Poolsuite FM): add presence Signed-off-by: lanewills <94198057+lanewills@users.noreply.github.com> * fix(Poolsuite FM): syntax Signed-off-by: lanewills <94198057+lanewills@users.noreply.github.com> * fix(Poolsuite FM): fix logo and thumbnail Signed-off-by: lanewills <94198057+lanewills@users.noreply.github.com> * fix(Poolsuite FM): use const enum Signed-off-by: lanewills <94198057+lanewills@users.noreply.github.com> --------- Signed-off-by: lanewills <94198057+lanewills@users.noreply.github.com> --- websites/P/Poolsuite FM/metadata.json | 20 +++++++++ websites/P/Poolsuite FM/presence.ts | 63 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 websites/P/Poolsuite FM/metadata.json create mode 100644 websites/P/Poolsuite FM/presence.ts diff --git a/websites/P/Poolsuite FM/metadata.json b/websites/P/Poolsuite FM/metadata.json new file mode 100644 index 000000000000..bc23635f6edd --- /dev/null +++ b/websites/P/Poolsuite FM/metadata.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.9", + "author": { + "id": "197422681530957824", + "name": "6co" + }, + "service": "Poolsuite FM", + "description": { + "en": "Poolsuite FM is an 80s-themed music website bringing summer vibes year-round." + }, + "url": "poolsuite.net", + "version": "1.0.0", + "logo": "https://i.imgur.com/u9dOCzX.jpg", + "thumbnail": "https://i.imgur.com/HpZEVbG.png", + "color": "#03cafc", + "category": "music", + "tags": [ + "music" + ] +} diff --git a/websites/P/Poolsuite FM/presence.ts b/websites/P/Poolsuite FM/presence.ts new file mode 100644 index 000000000000..2f8a48def4ed --- /dev/null +++ b/websites/P/Poolsuite FM/presence.ts @@ -0,0 +1,63 @@ +const presence = new Presence({ + clientId: "1174478441450573924", +}); + +// Function to convert the site's duration timer to raw seconds +function convertToSeconds(duration: string): number { + const [minutes, seconds] = duration.split(":").map(Number); + return minutes * 60 + seconds; +} + +const enum Assets { + Logo = "https://i.imgur.com/u9dOCzX.jpg", +} + +let details: string, state: string, artist: string; +presence.on("UpdateData", async () => { + // Grab channel and artist name + details = `Channel: ${ + document.querySelector(".select-wrapper").lastChild.textContent + }`; + artist = document.querySelector(".current-track").lastChild.textContent; + + // If next track is loading, replace current track text with "Tuning..." instead of track + if (artist === "We'll be right back") state = "Tuning..."; + else { + state = `${artist} - ${ + document.querySelector(".current-track").firstChild.nextSibling + .textContent + }`; + } + if (document.querySelector(".middle").firstChild.textContent === "Pause") { + // Set presence data for a playing song + const elapsed = Math.floor(Date.now() / 1000), + presenceData: PresenceData = { + details, + state, + largeImageKey: Assets.Logo, + startTimestamp: elapsed, + endTimestamp: + elapsed + + (convertToSeconds( + document.querySelector(".timer").lastChild.textContent + ) - + convertToSeconds( + document.querySelector(".timer").firstChild.textContent + )), + smallImageKey: Assets.Play, + smallImageText: "Playing", + }; + presence.setActivity(presenceData); + } else { + // Set presence data for a paused song + const presenceData: PresenceData = { + details, + state, + largeImageKey: Assets.Logo, + endTimestamp: 0, + smallImageKey: Assets.Pause, + smallImageText: "Paused", + }; + presence.setActivity(presenceData); + } +});