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(Tellingtone): add presence (PreMiD#6626)
* feat(Tellingtone): add new presence * chore(Tellingtone): run yarn format * feat(Tellingtone): add smallImageKey * feat(Tellingtone): fix behavior when listening or not * chore(Tellingtone): change if statements for settings * feat(Tellingtone): add the currentlyListening localized string * chore(Tellingtone): fix currentlyListening localized string * fix(Tellingtone): fix wrong replace * fix(Tellingtone): add replace * Update websites/T/Tellingtone/presence.ts Signed-off-by: Bas950 <[email protected]> Signed-off-by: Bas950 <[email protected]> Co-authored-by: Bas950 <[email protected]>
- Loading branch information
1 parent
5bf8b03
commit 1735ca0
Showing
3 changed files
with
146 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,41 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.7", | ||
"author": { | ||
"name": "RisingSunLight", | ||
"id": "240521747852558347" | ||
}, | ||
"service": "Tellingtone", | ||
"description": { | ||
"en": "Discover our catalog of original audio series, stories designed at the start to be listened to as a podcast. Immerse yourself in our fantastic universe where suspense, magic and investigation intertwine...", | ||
"fr": "Découvrez notre catalogue de séries audio originales, des histoires conçues dès l'écriture pour être écoutées en podcast. Plongez dans nos univers fantastiques où s'entremêlent suspense, magie et enquête…" | ||
}, | ||
"url": "tellingtone.com", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/L4eWRh1.png", | ||
"thumbnail": "https://i.imgur.com/6FokOfw.png", | ||
"color": "#45A8FC", | ||
"category": "other", | ||
"tags": [ | ||
"superflame", | ||
"stories", | ||
"audio" | ||
], | ||
"settings": [ | ||
{ | ||
"id": "lang", | ||
"multiLanguage": true | ||
}, | ||
{ | ||
"id": "time", | ||
"title": "Show Timestamp", | ||
"icon": "fad fa-stopwatch", | ||
"value": true | ||
}, | ||
{ | ||
"id": "cover", | ||
"title": "Show Cover", | ||
"icon": "fad fa-images", | ||
"value": true | ||
} | ||
] | ||
} |
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,99 @@ | ||
const presence = new Presence({ clientId: "1006201873985961984" }), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
async function getStrings() { | ||
return presence.getStrings( | ||
{ | ||
viewHome: "general.viewHome", | ||
paused: "general.paused", | ||
playing: "general.playing", | ||
episode: "general.episode", | ||
viewPage: "general.viewPage", | ||
buttonViewSeries: "general.buttonViewSeries", | ||
currentlyListening: "general.currentlyListening", | ||
}, | ||
await presence.getSetting<string>("lang").catch(() => "en") | ||
); | ||
} | ||
|
||
let strings: Awaited<ReturnType<typeof getStrings>>, | ||
oldLang: string = null; | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: "logo", | ||
startTimestamp: browsingTimestamp, | ||
}, | ||
{ pathname, href } = document.location, | ||
pathSplit = pathname.split("/"), | ||
[newLang, time, showCover] = await Promise.all([ | ||
presence.getSetting<string>("lang").catch(() => "en"), | ||
presence.getSetting<boolean>("time"), | ||
presence.getSetting<boolean>("cover"), | ||
]); | ||
|
||
if (oldLang !== newLang || !strings) { | ||
oldLang = newLang; | ||
strings = await getStrings(); | ||
} | ||
|
||
switch (pathSplit[1]) { | ||
case "": | ||
presenceData.details = strings.viewHome; | ||
break; | ||
case "shop": | ||
case "blog": | ||
presenceData.details = `Viewing ${pathSplit[1]}`; | ||
break; | ||
case "series": | ||
presenceData.details = strings.viewPage; | ||
presenceData.state = | ||
document.querySelector<HTMLHeadingElement>("div.head > h1").textContent; | ||
presenceData.largeImageKey = | ||
document.querySelector<HTMLImageElement>("div.head > img").src; | ||
|
||
presenceData.buttons = [{ label: strings.buttonViewSeries, url: href }]; | ||
} | ||
if (document.querySelector("div#Player")) { | ||
presenceData.details = strings.currentlyListening | ||
.replace("{0}", " ") | ||
.replace( | ||
"{1}", | ||
document.querySelector<HTMLDivElement>("div.media-title").textContent | ||
); | ||
presenceData.state = | ||
document.querySelector<HTMLDivElement>("div.media-episode").textContent; | ||
presenceData.largeImageKey = document | ||
.querySelector<HTMLImageElement>("div.media-image > svg > image") | ||
.getAttribute("xlink:href"); | ||
|
||
const timers: string[] = []; | ||
for (const element of document.querySelectorAll("div.desktop > div.timer")) | ||
timers.push(element.textContent); | ||
[presenceData.startTimestamp, presenceData.endTimestamp] = | ||
presence.getTimestamps( | ||
presence.timestampFromFormat(timers[0]), | ||
presence.timestampFromFormat(timers[1]) | ||
); | ||
delete presenceData.buttons; | ||
|
||
if (document.querySelector(".icon-pause")) { | ||
presenceData.smallImageKey = "play"; | ||
presenceData.smallImageText = strings.playing; | ||
} else { | ||
presenceData.smallImageKey = "pause"; | ||
presenceData.smallImageText = strings.paused; | ||
delete presenceData.endTimestamp; | ||
delete presenceData.startTimestamp; | ||
} | ||
} | ||
|
||
if (!time) { | ||
delete presenceData.startTimestamp; | ||
delete presenceData.endTimestamp; | ||
} | ||
if (!showCover) presenceData.largeImageKey = "logo"; | ||
|
||
if (presenceData.details) presence.setActivity(presenceData); | ||
else presence.setActivity(); | ||
}); |
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,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/" | ||
} | ||
} |