Skip to content

Commit

Permalink
feat(Poolsuite FM): add presence (PreMiD#7740)
Browse files Browse the repository at this point in the history
* feat(Poolsuite FM): add presence

Signed-off-by: lanewills <[email protected]>

* fix(Poolsuite FM): syntax

Signed-off-by: lanewills <[email protected]>

* fix(Poolsuite FM): fix logo and thumbnail

Signed-off-by: lanewills <[email protected]>

* fix(Poolsuite FM): use const enum

Signed-off-by: lanewills <[email protected]>

---------

Signed-off-by: lanewills <[email protected]>
  • Loading branch information
lanewills authored Nov 17, 2023
1 parent 4f9c664 commit 5e8eb7e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
20 changes: 20 additions & 0 deletions websites/P/Poolsuite FM/metadata.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
63 changes: 63 additions & 0 deletions websites/P/Poolsuite FM/presence.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit 5e8eb7e

Please sign in to comment.