-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AnimeDrive): add presence (#8329)
- Loading branch information
Showing
2 changed files
with
109 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,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" | ||
] | ||
} |
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,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); | ||
}); |