From 3909c1817121ca64e0f79aadb581ed954e507f0d Mon Sep 17 00:00:00 2001 From: RisingSunLight <85577959+RisingSunLight42@users.noreply.github.com> Date: Sun, 11 Sep 2022 13:38:11 +0200 Subject: [PATCH] feat(Anime Sama): add presence (#6766) Co-authored-by: Rhys Rakoff <64903135+EncryptedDev@users.noreply.github.com> Co-authored-by: Kozou <72155852+Kozou4ever@users.noreply.github.com> --- websites/A/Anime Sama/dist/metadata.json | 35 ++++++++ websites/A/Anime Sama/iframe.ts | 12 +++ websites/A/Anime Sama/presence.ts | 107 +++++++++++++++++++++++ websites/A/Anime Sama/tsconfig.json | 6 ++ 4 files changed, 160 insertions(+) create mode 100644 websites/A/Anime Sama/dist/metadata.json create mode 100644 websites/A/Anime Sama/iframe.ts create mode 100644 websites/A/Anime Sama/presence.ts create mode 100644 websites/A/Anime Sama/tsconfig.json diff --git a/websites/A/Anime Sama/dist/metadata.json b/websites/A/Anime Sama/dist/metadata.json new file mode 100644 index 000000000000..57d3f8bcff42 --- /dev/null +++ b/websites/A/Anime Sama/dist/metadata.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/websites/A/Anime Sama/iframe.ts b/websites/A/Anime Sama/iframe.ts new file mode 100644 index 000000000000..6dee01e1edb8 --- /dev/null +++ b/websites/A/Anime Sama/iframe.ts @@ -0,0 +1,12 @@ +const iframe = new iFrame(); + +iframe.on("UpdateData", async () => { + const video = document.querySelector("video"); + if (!isNaN(video?.duration)) { + iframe.send({ + currentTime: video.currentTime, + duration: video.duration, + paused: video.paused, + }); + } +}); diff --git a/websites/A/Anime Sama/presence.ts b/websites/A/Anime Sama/presence.ts new file mode 100644 index 000000000000..6335d0a2a190 --- /dev/null +++ b/websites/A/Anime Sama/presence.ts @@ -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("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("#selectEps"), + selectLecteur = + document.querySelector("#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("#selectChap"), + selectLang = + document.querySelector("#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( + "#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(); +}); diff --git a/websites/A/Anime Sama/tsconfig.json b/websites/A/Anime Sama/tsconfig.json new file mode 100644 index 000000000000..3bf4ca1f9f55 --- /dev/null +++ b/websites/A/Anime Sama/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist/" + } +}