Skip to content

Commit

Permalink
feat(Animevietsub): add presence (PreMiD#6779)
Browse files Browse the repository at this point in the history
* feat(Animevietsub): add presence

style(Animevietsub): remove unnecesary code

chore(Animevietsub): if => switch

feat(Animevietsub): more buttons

* fix(Animevietsub): typo & titleCase

* feat(Animevietsub): covers & settings

* feat(animevietsub): fix desc typo & nl desc

* chore(Animevietsub): remove broken code

* chore(Animevietsub): remove enum
  • Loading branch information
Dark_Ville authored Sep 11, 2022
1 parent 8603bbf commit 958d5b8
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
41 changes: 41 additions & 0 deletions websites/A/Animevietsub/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://schemas.premid.app/metadata/1.7",
"author": {
"name": "Dark_Ville",
"id": "638080361179512853"
},
"contributors": [
{
"name": "Minh",
"id": "457040540421324812"
}
],
"service": "Animevietsub",
"description": {
"en": "Watch your favorite anime online with Vietnamese subtitle!",
"vi_VN": "Xem anime online với phụ đề tiếng việt.",
"nl": "Bekijk jouw favoriete anime online met Vietnamese ondertiteling!"
},
"url": "animevietsub.cc",
"version": "1.0.0",
"logo": "https://i.imgur.com/trQFagl.jpeg",
"thumbnail": "https://i.imgur.com/cSWQACH.png",
"color": "#8b0000",
"category": "anime",
"tags": [
"animevietsub",
"anime"
],
"settings": [
{
"id": "lang",
"multiLanguage": true
},
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
}
]
}
173 changes: 173 additions & 0 deletions websites/A/Animevietsub/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
const presence = new Presence({
clientId: "1016991973531451502",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

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

async function getStrings() {
return presence.getStrings(
{
pause: "general.paused",
play: "general.playing",
},
await presence.getSetting<string>("lang").catch(() => "en")
);
}

presence.on("UpdateData", async () => {
const playback =
!!document.querySelector("#title") ||
(document.querySelectorAll("video").length &&
document.querySelectorAll("video")[0].className !== "previewVideo"),
{ pathname, href } = document.location,
[newLang, buttons] = await Promise.all([
presence.getSetting<string>("lang").catch(() => "en"),
presence.getSetting<boolean>("buttons"),
]),
splitPath = pathname.split("/"),
presenceData: PresenceData = {
largeImageKey: "https://i.imgur.com/trQFagl.jpeg",
startTimestamp: browsingTimestamp,
};

if (oldLang !== newLang || !strings) {
oldLang = newLang;
strings = await getStrings();
}

if (!playback) {
switch (splitPath[1]) {
case "anime-bo":
case "anime-sap-chieu":
case "anime-le":
case "danh-sach":
case "hoat-hinh-trung-quoc": {
presenceData.details = "Đang chọn phim";
presenceData.buttons = [
{
label: "Xem Phim",
url: href,
},
];
break;
}
case "": {
presenceData.details = "Đang xem trang chủ...";
break;
}
case "tim-kiem": {
presenceData.details = "Đang tìm kiếm...";
break;
}
case "the-laoi": {
presenceData.details = "Đang chọn thể loại phim";
break;
}
case "tu-phim": {
presenceData.details = "Đang xem danh sách đã lưu trong hộp phim";
break;
}
case "season": {
presenceData.details = "Đang chọn mùa phim";
presenceData.buttons = [
{
label: "Xem Phần",
url: href,
},
];
break;
}
case "bang-xep-hang": {
presenceData.details = "Đang xem bảng xếp hạng anime";
break;
}
case "phim": {
presenceData.details = `Định xem phim ${
document.querySelector<HTMLAnchorElement>(".Title").textContent
}`;
presenceData.buttons = [
{
label: "Xem Phim",
url: href,
},
];
break;
}
case "quen-mat-khau.html": {
presenceData.details = "Đang bị quên mật khẩu kek.";
break;
}
case "/lich-chieu-phim.html": {
presenceData.details = "Đang xem lịch chiếu anime";
break;
}
case "anime":
case "account": {
switch (splitPath[2]) {
case "info": {
presenceData.details = "Đang xem profile...";
break;
}
case "login": {
presenceData.details = "Đang đăng nhập...";
break;
}
case "register": {
presenceData.details = "Đang đăng ký...";
break;
}
case "library": {
presenceData.details = "Đang xem thử viện alime";
presenceData.buttons = [
{
label: "Xem Thư Viện Anime",
url: href,
},
];
break;
}
}
break;
}
default: {
presenceData.details = "Đang xem trang chủ...";
break;
}
}
} else {
const [video] = document.querySelectorAll("video");

if (!isNaN(video?.duration)) {
delete presenceData.startTimestamp;
const [titleArrOne] = (
document.querySelectorAll(".Title")
? document.querySelector(".Title").textContent
: "Không tìm thấy còn cặc - Tập ?"
).split(" - ");
presenceData.smallImageKey = video.paused ? "pause" : "play";
presenceData.smallImageText = video.paused ? strings.pause : strings.play;
presenceData.endTimestamp = presence.getTimestamps(
Math.floor(video.currentTime),
Math.floor(video.duration)
)[1];

presenceData.details = `Đang xem: ${titleArrOne} `;
presenceData.state = `Tập: ${
document.querySelector<HTMLAnchorElement>(".episode.playing")
.textContent
}`;
presenceData.buttons = [
{
label: "Xem Phim",
url: href,
},
];
if (video.paused) delete presenceData.endTimestamp;
}
}
if (!buttons) delete presenceData.buttons;
if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});
6 changes: 6 additions & 0 deletions websites/A/Animevietsub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit 958d5b8

Please sign in to comment.