forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Poolsuite FM): add presence (PreMiD#7740)
* 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
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |