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(Anime Sama): add presence (PreMiD#6766)
Co-authored-by: Rhys Rakoff <64903135+EncryptedDev@users.noreply.github.com> Co-authored-by: Kozou <72155852+Kozou4ever@users.noreply.github.com>
- Loading branch information
1 parent
15cde60
commit 3909c18
Showing
4 changed files
with
160 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,35 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.7", | ||
"author": { | ||
"name": "RisingSunLight", | ||
"id": "240521747852558347" | ||
}, | ||
"service": "Anime Sama", | ||
"description": { | ||
"en": "Your streaming website for animes and scans without ad.", | ||
"fr": "Votre site de streaming préféré pour vos animes et scans sans pubs." | ||
}, | ||
"url": "anime-sama.fr", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/Q4kwFRA.jpg", | ||
"thumbnail": "https://i.imgur.com/R32QLIO.jpg", | ||
"color": "#0063c0", | ||
"category": "anime", | ||
"tags": [ | ||
"anime", | ||
"anime-sama", | ||
"scan", | ||
"vf", | ||
"vostfr" | ||
], | ||
"iframe": true, | ||
"iFrameRegExp": ".*((sendvid)|(sibnet)|(myvi)).*", | ||
"settings": [ | ||
{ | ||
"id": "buttons", | ||
"title": "Show Buttons", | ||
"icon": "fas fa-compress-arrows-alt", | ||
"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,12 @@ | ||
const iframe = new iFrame(); | ||
|
||
iframe.on("UpdateData", async () => { | ||
const video = document.querySelector<HTMLVideoElement>("video"); | ||
if (!isNaN(video?.duration)) { | ||
iframe.send({ | ||
currentTime: video.currentTime, | ||
duration: video.duration, | ||
paused: video.paused, | ||
}); | ||
} | ||
}); |
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,107 @@ | ||
const presence = new Presence({ clientId: "1016797607370162256" }), | ||
browsingTimestamp = Math.floor(Date.now() / 1000), | ||
staticPages: { [name: string]: string } = { | ||
search: "Recherche un anime ou un scan", | ||
"": "Visionne la page d'accueil", | ||
planning: "Regarde le planning des sorties", | ||
}; | ||
|
||
enum Assets { | ||
Logo = "https://i.imgur.com/Q4kwFRA.jpg", | ||
Pause = "https://i.imgur.com/BtWUfrZ.png", | ||
Play = "https://i.imgur.com/KNneWuF.png", | ||
Reading = "https://i.imgur.com/53N4eY6.png", | ||
} | ||
|
||
interface IFrameData { | ||
duration: number; | ||
currentTime: number; | ||
paused: boolean; | ||
} | ||
|
||
let duration: number, | ||
currentTime: number, | ||
paused = true; | ||
|
||
presence.on("iFrameData", (data: IFrameData) => { | ||
({ duration, currentTime, paused } = data); | ||
}); | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: Assets.Logo, | ||
startTimestamp: browsingTimestamp, | ||
}, | ||
{ pathname, href } = document.location, | ||
pathArr = pathname.split("/"), | ||
showButtons = await presence.getSetting<boolean>("buttons"); | ||
|
||
switch (pathArr[1]) { | ||
case "anime": | ||
if (pathArr.length === 3) presenceData.details = "Parcours les animés"; | ||
else if (pathArr.length === 4) { | ||
presenceData.details = "Regarde la page de l'animé"; | ||
presenceData.state = document.querySelector("h5").textContent; | ||
presenceData.buttons = [{ label: "Voir la Page", url: href }]; | ||
} else { | ||
const [anime, season] = document | ||
.querySelector(".soustitreaccueil") | ||
.textContent.split(" - "), | ||
selectEps = document.querySelector<HTMLSelectElement>("#selectEps"), | ||
selectLecteur = | ||
document.querySelector<HTMLSelectElement>("#selectLecteurs"); | ||
presenceData.details = `Regarde ${anime}`; | ||
presenceData.state = `${ | ||
season ? `${season[0].toUpperCase() + season.slice(1)} - ` : "" | ||
}${selectEps.options[selectEps.selectedIndex].value}`; | ||
|
||
presenceData.buttons = [{ label: "Voir l'Anime", url: href }]; | ||
presenceData.smallImageKey = Assets.Pause; | ||
presenceData.smallImageText = | ||
selectLecteur.options[selectLecteur.selectedIndex].value; | ||
|
||
if (!paused) { | ||
[presenceData.startTimestamp, presenceData.endTimestamp] = | ||
presence.getTimestamps(currentTime, duration); | ||
presenceData.smallImageKey = Assets.Play; | ||
} | ||
} | ||
break; | ||
case "scan": | ||
if (pathArr.length === 3) presenceData.details = "Parcours les scans"; | ||
else { | ||
const selectEps = | ||
document.querySelector<HTMLSelectElement>("#selectChap"), | ||
selectLang = | ||
document.querySelector<HTMLSelectElement>("#selectLanguesScan"), | ||
chapter = selectEps.options[selectEps.selectedIndex].value.trim(), | ||
scanTitle = document.querySelector("h5").textContent; | ||
if (chapter === "Choisissez un chapitre") { | ||
presenceData.details = "Regarde la page du scan"; | ||
presenceData.state = scanTitle; | ||
} else { | ||
presenceData.details = `Lit ${scanTitle}`; | ||
presenceData.state = `${chapter} - ${ | ||
selectLang.options[selectLang.selectedIndex].value | ||
}`; | ||
|
||
const selectLecteur = document.querySelector<HTMLSelectElement>( | ||
"#selectLecteursScan" | ||
); | ||
presenceData.smallImageKey = Assets.Reading; | ||
presenceData.smallImageText = | ||
selectLecteur.options[selectLecteur.selectedIndex].value; | ||
} | ||
|
||
presenceData.buttons = [{ label: "Voir le Scan", url: href }]; | ||
} | ||
break; | ||
default: | ||
if (Object.keys(staticPages).includes(pathArr[1])) | ||
presenceData.details = staticPages[pathArr[1]]; | ||
} | ||
|
||
if (!showButtons) delete presenceData.buttons; | ||
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/" | ||
} | ||
} |