From 313e1589434967c218bfb1ecb350bf0fe127ad19 Mon Sep 17 00:00:00 2001 From: Antonino <133604163+Hikki0710@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:00:58 +0200 Subject: [PATCH] feat(MangaGo): add new presence (#8683) * feat(MangaGo): add new presence * refactor: replace a querySelectorAll with querySelector Signed-off-by: Antonino <133604163+Hikki0710@users.noreply.github.com> * Update websites/M/MangaGo/metadata.json Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> Signed-off-by: Antonino <133604163+Hikki0710@users.noreply.github.com> * fix: blurry images --------- Signed-off-by: Antonino <133604163+Hikki0710@users.noreply.github.com> Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> --- websites/M/MangaGo/metadata.json | 46 ++++++++++++++ websites/M/MangaGo/presence.ts | 102 +++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 websites/M/MangaGo/metadata.json create mode 100644 websites/M/MangaGo/presence.ts diff --git a/websites/M/MangaGo/metadata.json b/websites/M/MangaGo/metadata.json new file mode 100644 index 000000000000..a62cb0d0bebf --- /dev/null +++ b/websites/M/MangaGo/metadata.json @@ -0,0 +1,46 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.10", + "author": { + "id": "533014724569333770", + "name": "_hikki_" + }, + "service": "MangaGo", + "description": { + "en": "MangaGo is a popular online platform for reading manga, manhwa and more, offering a vast library of titles across various genres", + "it": "MangaGo è una popolare piattaforma online per la lettura di manga, manhwa e altro ancora, che offre una vasta libreria di titoli di vari generi" + }, + "url": ["www.mangago.me","mangago.me"], + "version": "1.0.0", + "logo": "https://i.imgur.com/H99kQ0R.png", + "thumbnail": "https://i.imgur.com/JuRQMxr.png", + "color": "#C19C93", + "category": "anime", + "tags": ["mangago", "manga", "manwha", "manhua", "reading"], + "settings": [ + { + "id": "lang", + "multiLanguage": true + }, + { + "id": "time", + "title": "Show timestamps", + "icon": "fad fa-stopwatch", + "value": true + }, + { + "id": "privacy", + "title": "Privacy Mode", + "icon": "fad fa-user-secret", + "value": false + }, + { + "id": "cover", + "title": "Show Cover", + "icon": "fad fa-images", + "value": true, + "if": { + "privacy": false + } + } + ] +} diff --git a/websites/M/MangaGo/presence.ts b/websites/M/MangaGo/presence.ts new file mode 100644 index 000000000000..82975a67d28f --- /dev/null +++ b/websites/M/MangaGo/presence.ts @@ -0,0 +1,102 @@ +const presence = new Presence({ + clientId: "1276562016332546049", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); + +const enum Assets { + Logo = "https://i.imgur.com/H99kQ0R.png", + LogoV2 = "https://i.imgur.com/n4K3YfZ.png", +} + +async function getStrings() { + return presence.getStrings( + { + search: "general.searchFor", + searchSomething: "general.searchSomething", + viewHome: "general.viewHome", + viewAManga: "general.viewAManga", + viewManga: "general.viewManga", + reading: "general.reading", + viewGenre: "general.viewGenre", + }, + await presence.getSetting("lang").catch(() => "en") + ); +} + +let strings: Awaited>, + oldLang: string = null; + +presence.on("UpdateData", async () => { + const presenceData: PresenceData = { + largeImageKey: Assets.Logo, + }, + [newLang, time, privacy, cover] = await Promise.all([ + presence.getSetting("lang").catch(() => "en"), + presence.getSetting("time"), + presence.getSetting("privacy"), + presence.getSetting("cover"), + ]), + { pathname } = document.location; + + if (time) presenceData.startTimestamp = browsingTimestamp; + + if (oldLang !== newLang || !strings) { + oldLang = newLang; + strings = await getStrings(); + } + + if (pathname === "/") presenceData.details = strings.viewHome; + else if (pathname.startsWith("/topmanga")) + presenceData.details = "Viewing top-manga"; + else if (pathname.startsWith("/r/l_search")) { + presenceData.smallImageKey = Assets.Search; + presenceData.smallImageText = strings.search; + presenceData.details = privacy + ? strings.searchSomething + : `${strings.search} ${ + document.querySelector("#searchform_name").value + }`; + } else if (pathname.startsWith("/genre")) { + presenceData.details = `${strings.viewGenre} ${pathname + .split("/")[2] + .replaceAll("%20", " ")}`; + } else if (pathname.startsWith("/read-manga")) { + if (document.querySelector("#dropdown-chapter-page")) { + presenceData.smallImageKey = Assets.Reading; + presenceData.smallImageText = strings.reading; + presenceData.largeImageKey = Assets.LogoV2; + presenceData.details = privacy + ? strings.reading + : `${strings.reading}: ${ + document.querySelector("#series").textContent + }`; + if (!privacy) { + presenceData.state = `${ + document.querySelector("#dropdown-chapter-page").textContent + }/${ + document + .querySelector(".dropdown-menu.chapter") + .querySelectorAll("li").length + }`; + } + } else { + presenceData.smallImageKey = Assets.Viewing; + presenceData.smallImageText = strings.viewAManga; + presenceData.details = privacy + ? strings.viewAManga + : `${strings.viewManga} ${document + .querySelector(".w-title") + .textContent.replace(/\t|\n/g, "")}`; + presenceData.state = `⭐ ${ + document.querySelector(".rating_num").textContent + }/10 `; + presenceData.largeImageKey = + !privacy && cover + ? document.querySelector(".left.cover > img") + ?.src ?? Assets.LogoV2 + : Assets.LogoV2; + } + } + + presence.setActivity(presenceData); +});