From 5d37880f3a28853accb9c342fd1ba232e397d1df Mon Sep 17 00:00:00 2001 From: Skully Date: Fri, 25 Oct 2024 22:41:31 +0200 Subject: [PATCH 1/2] feat(Anime Sama): add privacy mode and update timestamps --- websites/A/Anime Sama/iframe.ts | 2 +- websites/A/Anime Sama/metadata.json | 24 ++++++--- websites/A/Anime Sama/presence.ts | 79 ++++++++++++++++++++--------- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/websites/A/Anime Sama/iframe.ts b/websites/A/Anime Sama/iframe.ts index 6dee01e1edb8..3dce46b55a6d 100644 --- a/websites/A/Anime Sama/iframe.ts +++ b/websites/A/Anime Sama/iframe.ts @@ -2,7 +2,7 @@ const iframe = new iFrame(); iframe.on("UpdateData", async () => { const video = document.querySelector("video"); - if (!isNaN(video?.duration)) { + if (video && !isNaN(video.duration)) { iframe.send({ currentTime: video.currentTime, duration: video.duration, diff --git a/websites/A/Anime Sama/metadata.json b/websites/A/Anime Sama/metadata.json index ea69457a80e3..f6ee7ded33dd 100644 --- a/websites/A/Anime Sama/metadata.json +++ b/websites/A/Anime Sama/metadata.json @@ -2,13 +2,13 @@ "$schema": "https://schemas.premid.app/metadata/1.11", "apiVersion": 1, "author": { - "name": "RisingSunLight", - "id": "240521747852558347" + "name": "Atom Skully", + "id": "671037171611729920" }, "contributors": [ { - "name": "Atom Skully", - "id": "671037171611729920" + "name": "RisingSunLight", + "id": "240521747852558347" } ], "service": "Anime Sama", @@ -17,7 +17,7 @@ "fr": "Votre site de streaming préféré pour vos animes et scans sans pubs." }, "url": "anime-sama.fr", - "version": "1.1.9", + "version": "1.2.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/thumbnail.png", "color": "#0063c0", @@ -30,7 +30,7 @@ "vostfr" ], "iframe": true, - "iFrameRegExp": ".*((sendvid)|(sibnet)|(myvi)).*", + "iFrameRegExp": ".*", "settings": [ { "id": "buttons", @@ -38,6 +38,18 @@ "icon": "fas fa-compress-arrows-alt", "value": true }, + { + "id": "privacy", + "title": "Privacy Mode", + "icon": "fad fa-user-secret", + "value": false + }, + { + "id": "timestamps", + "title": "Show Timestamps", + "icon": "fad fa-stopwatch", + "value": true + }, { "id": "cover", "title": "Show Cover", diff --git a/websites/A/Anime Sama/presence.ts b/websites/A/Anime Sama/presence.ts index 907ac911ef2d..2ef657ed188d 100644 --- a/websites/A/Anime Sama/presence.ts +++ b/websites/A/Anime Sama/presence.ts @@ -12,19 +12,18 @@ const enum Assets { Logo = "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/logo.png", } -interface IFrameData { - duration: number; - currentTime: number; - paused: boolean; -} - -let duration: number, - currentTime: number, - paused = true; +let video = { + duration: 0, + currentTime: 0, + paused: true, +}; -presence.on("iFrameData", (data: IFrameData) => { - ({ duration, currentTime, paused } = data); -}); +presence.on( + "iFrameData", + (data: { duration: number; currentTime: number; paused: boolean }) => { + if (data?.duration) video = data; + } +); presence.on("UpdateData", async () => { const presenceData: PresenceData = { @@ -34,16 +33,22 @@ presence.on("UpdateData", async () => { }, { pathname, href } = document.location, pathArr = pathname.split("/"), - [showButtons, showCover] = await Promise.all([ + [showButtons, privacyMode, showTimestamps, showCover] = await Promise.all([ presence.getSetting("buttons"), + presence.getSetting("privacy"), + presence.getSetting("timestamps"), presence.getSetting("cover"), ]); - if (Object.keys(staticPages).includes(pathArr[1]) && pathArr.length <= 3) + if (Object.keys(staticPages).includes(pathArr[1]) && pathArr.length <= 3) { presenceData.details = staticPages[pathArr[1]]; - else if (pathArr.length === 4) { + if (privacyMode) presenceData.details = "Navigue..."; + } else if (pathArr.length === 4) { + const pageTitle = document.querySelector( + "h2.border-slate-500" + )?.textContent; presenceData.details = - document.querySelector("h2.border-slate-500")?.textContent === "Anime" + pageTitle === "Anime" ? "Regarde la page de l'anime" : "Regarde la page du manga"; presenceData.state = document @@ -53,6 +58,13 @@ presence.on("UpdateData", async () => { presenceData.largeImageKey = document.querySelector("[property='og:image']") ?.content ?? Assets.Logo; + if (privacyMode) { + delete presenceData.state; + presenceData.details = + pageTitle === "Anime" + ? "Regarde la page d'un anime" + : "Regarde la page d'un manga"; + } } else if (document.querySelector("#selectEpisodes")) { const season = document.querySelector("#avOeuvre").textContent, selectEps = document.querySelector("#selectEpisodes"), @@ -61,21 +73,33 @@ presence.on("UpdateData", async () => { presenceData.details = `Regarde ${ document.querySelector("#titreOeuvre").textContent }`; + const [startTimestamp, endTimestamp] = presence.getTimestamps( + video.currentTime, + video.duration + ); presenceData.state = `${season ? `${season} - ` : ""}${ selectEps.options[selectEps.selectedIndex].value }`; presenceData.buttons = [{ label: "Voir l'Anime", url: href }]; - presenceData.smallImageKey = Assets.Pause; + presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play; presenceData.smallImageText = selectLecteur.options[selectLecteur.selectedIndex].value; presenceData.largeImageKey = document.querySelector("[property='og:image']") ?.content ?? Assets.Logo; - if (!paused) { - [presenceData.startTimestamp, presenceData.endTimestamp] = - presence.getTimestamps(currentTime, duration); - presenceData.smallImageKey = Assets.Play; + [presenceData.startTimestamp, presenceData.endTimestamp] = [ + startTimestamp, + endTimestamp, + ]; + if (video.paused) { + delete presenceData.startTimestamp; + delete presenceData.endTimestamp; + } + if (privacyMode) { + delete presenceData.state; + delete presenceData.smallImageKey; + presenceData.details = "Regarde un anime"; } } else { const selectChapitres = @@ -94,10 +118,19 @@ presence.on("UpdateData", async () => { presenceData.largeImageKey = document.querySelector("[property='og:image']") ?.content ?? Assets.Logo; + if (privacyMode) { + delete presenceData.state; + delete presenceData.smallImageKey; + presenceData.details = "Lit un manga"; + } } - if (!showButtons) delete presenceData.buttons; - if (!showCover) presenceData.largeImageKey = Assets.Logo; + if (!showButtons || privacyMode) delete presenceData.buttons; + if (!showTimestamps) { + delete presenceData.startTimestamp; + delete presenceData.endTimestamp; + } + if (!showCover || privacyMode) presenceData.largeImageKey = Assets.Logo; if (presenceData.details) presence.setActivity(presenceData); else presence.setActivity(); }); From 72866a06d3c77abd639a70236ffdb8678a03cceb Mon Sep 17 00:00:00 2001 From: Skully <117316808+skullysmods@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:28:31 +0100 Subject: [PATCH 2/2] fix: correcting a spelling mistake Signed-off-by: Skully <117316808+skullysmods@users.noreply.github.com> --- websites/A/Anime Sama/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/A/Anime Sama/presence.ts b/websites/A/Anime Sama/presence.ts index 2ef657ed188d..01f12dac2efe 100644 --- a/websites/A/Anime Sama/presence.ts +++ b/websites/A/Anime Sama/presence.ts @@ -4,7 +4,7 @@ const presence = new Presence({ clientId: "1016797607370162256" }), "": "Visionne la page d'accueil", planning: "Regarde le planning des sorties", aide: "Lit la page d'aide", - profil: "visionne son profil", + profil: "Visionne son profil", catalogue: "Parcourir le catalogue", };