Skip to content

Commit

Permalink
feat(AnimeDrive): add presence (#8329)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferivoq authored Apr 29, 2024
1 parent 0495fb6 commit 8b1c91d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
25 changes: 25 additions & 0 deletions websites/A/AnimeDrive/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "291136400068444161",
"name": "ferivoq"
},
"service": "AnimeDrive",
"description": {
"en": "AnimeDrive is an anime streaming website with Hungarian subs/dubs"
},
"url": [
"animedrive.hu",
"www.animedrive.hu"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/VlBtvJo.png",
"thumbnail": "https://i.imgur.com/uP6s5yc.png",
"color": "#6f0094",
"category": "anime",
"tags": [
"anime",
"animes",
"animedrive"
]
}
84 changes: 84 additions & 0 deletions websites/A/AnimeDrive/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const presence = new Presence({
clientId: "1211027222815711282",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "https://i.imgur.com/VlBtvJo.png",
startTimestamp: browsingTimestamp,
},
{ pathname, search } = document.location;

switch (pathname) {
case "/": {
presenceData.details = "Főoldal Böngészése";
break;
}
case "/search/": {
presenceData.details = "Anime Keresése";
break;
}
case "/anime/": {
if (search.startsWith("?id=")) {
const animeId = search.split("?id=")[1].split("&")[0],
contentDiv = document.querySelector(".col-sm-12.col-md-8.col-lg-9"),
h2Content = contentDiv ? contentDiv.querySelector("h2") : null,
h4Content = contentDiv ? contentDiv.querySelector("h4") : null;

if (h4Content && h4Content.textContent.trim()) {
presenceData.details = "Adatlap böngészése:";
presenceData.state = `${h2Content.textContent.trim()}`;
} else if (h2Content && h2Content.textContent.trim()) {
presenceData.details = "Adatlap böngészése:";
presenceData.state = `${h2Content.textContent.trim()}`;
} else {
presenceData.details = "Adatlap böngészése:";
presenceData.state = `ID: ${animeId}`;
}

presenceData.buttons = [
{
label: "Adatlap",
url: `https://animedrive.hu/anime/?id=${animeId}`,
},
];
} else presenceData.details = "Anime Böngészése";

break;
}
case "/watch/": {
if (search.startsWith("?id=")) {
const animeId = search.split("?id=")[1].split("&")[0],
linkElement = document.querySelector(
'a.text-white[href^="https://animedrive.hu/anime/?id="]'
),
h2Element = linkElement ? linkElement.querySelector("h2") : null,
episodeElement = document.querySelector(
"a.nk-pagination-current-white"
);
if (h2Element && h2Element.textContent.trim()) {
presenceData.details = `${h2Element.textContent.trim()}`;
presenceData.state = `Epizód: ${episodeElement.textContent.trim()}`;
} else {
presenceData.details = "Adatlap böngészése:";
presenceData.state = `ID: ${animeId}`;
}

presenceData.buttons = [
{
label: "Lejátszás",
url: `https://animedrive.hu/watch/?id=${animeId}&ep=${
episodeElement.textContent.match(/\d+/)[0]
}`,
},
];
} else presenceData.details = "Anime Nézése";

break;
}
default:
presenceData.details = "AnimeDrive Böngészése";
}
presence.setActivity(presenceData);
});

0 comments on commit 8b1c91d

Please sign in to comment.