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(MangaGo): add new presence (PreMiD#8683)
* 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
Showing
2 changed files
with
148 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,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 | ||
} | ||
} | ||
] | ||
} |
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,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); | ||
}); |