Skip to content

Commit

Permalink
feat(MangaGo): add new presence (#8683)
Browse files Browse the repository at this point in the history
* feat(MangaGo): add new presence

* refactor: replace a querySelectorAll with querySelector

Signed-off-by: Antonino <[email protected]>

* Update websites/M/MangaGo/metadata.json

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: Antonino <[email protected]>

* fix: blurry images

---------

Signed-off-by: Antonino <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
  • Loading branch information
Hikki0710 and theusaf authored Aug 28, 2024
1 parent 4656023 commit 313e158
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
46 changes: 46 additions & 0 deletions websites/M/MangaGo/metadata.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
102 changes: 102 additions & 0 deletions websites/M/MangaGo/presence.ts
Original file line number Diff line number Diff line change
@@ -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<string>("lang").catch(() => "en")
);
}

let strings: Awaited<ReturnType<typeof getStrings>>,
oldLang: string = null;

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
},
[newLang, time, privacy, cover] = await Promise.all([
presence.getSetting<string>("lang").catch(() => "en"),
presence.getSetting<boolean>("time"),
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("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<HTMLInputElement>("#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<HTMLImageElement>(".left.cover > img")
?.src ?? Assets.LogoV2
: Assets.LogoV2;
}
}

presence.setActivity(presenceData);
});

0 comments on commit 313e158

Please sign in to comment.