Skip to content

Commit

Permalink
feat(Moopa): add presence (#7576)
Browse files Browse the repository at this point in the history
* feat(Moopa): add presence

* feat(Moopa): update metadata.json

* feat(Moopa): update logo size

* feat(Moopa): update timestamps

* feat(Moopa): removed unnecessary curly

* Update websites/M/Moopa/presence.ts

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

* feat(Moopa): added gettitle function

* Update websites/M/Moopa/metadata.json

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Factiven <[email protected]>

---------

Signed-off-by: Factiven <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
Co-authored-by: Dark_Ville <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent 7cf3bd7 commit 9bc65f7
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 0 deletions.
38 changes: 38 additions & 0 deletions websites/M/Moopa/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://schemas.premid.app/metadata/1.9",
"author": {
"id": "338295424479789057",
"name": "factiven"
},
"service": "Moopa",
"description": {
"en": "Moopa is a free Anime and Manga streaming website with AniList integration where you can easily track your progress with a single click of a button."
},
"url": "moopa.live",
"version": "1.0.0",
"logo": "https://i.imgur.com/lelaLhp.png",
"thumbnail": "https://i.imgur.com/pNmZsH3.png",
"color": "#FF7F57",
"category": "anime",
"tags": [
"anime",
"manga",
"streaming",
"video",
"anilist",
"free"
],
"settings": [
{
"id": "title",
"title": "Title Language",
"icon": "fa-solid fa-language",
"value": 0,
"values": [
"Romaji",
"English",
"Native"
]
}
]
}
188 changes: 188 additions & 0 deletions websites/M/Moopa/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
const presence = new Presence({
clientId: "1139510267311562842",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.imgur.com/lelaLhp.png",
}

function getTitle(titleLang: number) {
const metaTitle = document.querySelector('meta[name="title"]'),
romajiTitle = metaTitle?.getAttribute("data-title-romaji");

switch (titleLang) {
case 0: {
return romajiTitle;
}
case 1: {
return metaTitle?.getAttribute("data-title-english") || romajiTitle;
}
case 2: {
return metaTitle?.getAttribute("data-title-native") || romajiTitle;
}
default: {
return null;
}
}
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
},
titleLang = (await presence.getSetting("title")) as number,
{ pathname, href } = document.location;

if (pathname === "/" || pathname === "/en/")
presenceData.details = "Browsing Homepage";
else if (pathname.includes("/id/"))
presenceData.details = "Browsing Anime/Manga";
else if (pathname.includes("/profile/")) {
presenceData.details =
document.querySelector("h1.font-karla.font-bold.text-2xl.pt-7")
?.textContent || "Getting data...";
presenceData.state = "Viewing profile";
} else if (pathname === "/en/anime/trending/")
presenceData.details = "Browsing trending Anime";
else if (pathname === "/en/anime/popular/")
presenceData.details = "Browsing popular Anime";
else if (
pathname.includes("/anime/") &&
!pathname.includes("/watch/") &&
!pathname.includes("/search/")
) {
if (document.querySelector('img[alt="404"]')) {
presenceData.state = "404 | Not Found";
presenceData.details = "Browsing Anime/Manga";
} else {
delete presenceData.startTimestamp;
const title = getTitle(titleLang);

presenceData.largeImageKey =
document
.querySelector('img[alt="poster anime"]')
?.getAttribute("src") || Assets.Logo;
presenceData.details = title || "Getting data...";
presenceData.state = "Viewing info";

if (title) {
presenceData.buttons = [
{
label: "View Anime",
url: href,
},
];
}
}
} else if (
pathname.includes("/manga/") &&
!pathname.includes("/read/") &&
!pathname.includes("/search/")
) {
if (document.querySelector('img[alt="404"]')) {
presenceData.state = "404 | Not Found";
presenceData.details = "Browsing Anime/Manga";
} else {
delete presenceData.startTimestamp;
const title = document.querySelector("h1.title")?.textContent;
presenceData.largeImageKey =
document.querySelector('img[alt="cover image"]')?.getAttribute("src") ||
Assets.Logo;
presenceData.details = title || "Getting data...";
presenceData.state = "Viewing info";

if (title) {
presenceData.buttons = [
{
label: "View Manga",
url: href,
},
];
}
}
} else if (pathname.includes("/watch/")) {
if (document.querySelector('img[alt="404"]')) {
presenceData.state = "404 | Not Found";
presenceData.details = "Browsing Anime/Manga";
} else {
const playingEpisode = document
.querySelector("h3")
?.textContent?.replace("Episode ", ""),
video: HTMLVideoElement = document.querySelector("video");
if (video && !Number.isNaN(Number(video.duration))) {
presenceData.endTimestamp = presence
.getTimestampsfromMedia(video)
.pop();
if (video.paused) {
presenceData.smallImageText = "Paused";
presenceData.smallImageKey = Assets.Pause;
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
} else {
presenceData.smallImageText = "Playing";
presenceData.smallImageKey = Assets.Play;
}
}

const total = document
.querySelector("div.grid.w-full.pl-5")
?.getAttribute("data-episode"),
title = getTitle(titleLang);

if (title) {
presenceData.buttons = [
{
label: "Stream Anime",
url: href,
},
];
}
presenceData.largeImageKey =
document.querySelector('img[alt="Anime Cover"]')?.getAttribute("src") ||
Assets.Logo;
presenceData.details = title || "Getting data...";
if (playingEpisode) {
presenceData.state = `Episode ${playingEpisode} of ${
total === "0" ? "???" : total
}`;
}
}
} else if (pathname.includes("/read/")) {
const title = document
.querySelector("title")
?.textContent.replace("Manga - ", "");

presenceData.largeImageKey =
document
.querySelector('meta[id="CoverImage"]')
.getAttribute("data-manga-cover") || Assets.Logo;
presenceData.details = title || "Getting data...";
presenceData.state = `Reading Chapter ${document
.querySelector('input[id="chapter-progress"]')
.getAttribute("value")}`;
presenceData.smallImageKey = Assets.Reading;
presenceData.smallImageText = "Reading";

if (title) {
presenceData.buttons = [
{
label: "Read Manga",
url: href,
},
];
}
} else if (pathname.includes("/search/") && pathname.includes("/anime/")) {
presenceData.details = "Browsing Anime";
presenceData.state = "Searching...";
presenceData.smallImageKey = Assets.Search;
} else if (pathname.includes("/search/") && pathname.includes("/manga/")) {
presenceData.details = "Browsing Manga";
presenceData.state = "Searching...";
presenceData.smallImageKey = Assets.Search;
} else presenceData.details = "Browsing Anime/Manga";

if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});

0 comments on commit 9bc65f7

Please sign in to comment.