Skip to content

Commit

Permalink
feat(AniMi Club): add presence (PreMiD#7983)
Browse files Browse the repository at this point in the history
  • Loading branch information
riktikdev authored Jan 26, 2024
1 parent b264de8 commit 03c572a
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
16 changes: 16 additions & 0 deletions websites/A/AniMi Club/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const iframe = new iFrame();

iframe.on("UpdateData", async () => {
if (document.querySelector("video")) {
const video: HTMLVideoElement =
document.querySelector<HTMLVideoElement>("video");

if (video && !isNaN(video.duration)) {
iframe.send({
duration: video.duration,
currentTime: video.currentTime,
paused: video.paused,
});
}
}
});
47 changes: 47 additions & 0 deletions websites/A/AniMi Club/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "https://schemas.premid.app/metadata/1.9",
"author": {
"id": "546262814424170498",
"name": "official_riktik"
},
"service": "AniMi Club",
"description": {
"en": "Watch anime online for free. Large database of the best anime with russian voiceover in good quality.",
"ru": "Смотреть аниме онлайн бесплатно. Большая база лучших аниме с русской озвучкой в хорошем качестве.",
"uk_UA": "Дивитися аніме онлайн безкоштовно. Велика база найкращих аніме з російською озвучкою в хорошій якості."
},
"url": [
"animi.club",
"www.animi.club",
"dev.animi.club"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/BZtDh0g.png",
"thumbnail": "https://i.imgur.com/Anc197L.png",
"color": "#e11d48",
"category": "anime",
"tags": [
"anime",
"аниме",
"animi",
"аними",
"animiclub",
"анимиклаб"
],
"iframe": true,
"iFrameRegExp": ".*",
"settings": [
{
"id": "privacy",
"title": "Приватный режим",
"icon": "fad fa-user-secret",
"value": false
},
{
"id": "time",
"title": "Показывать оставшееся время просмотра",
"icon": "fad fa-stopwatch",
"value": true
}
]
}
98 changes: 98 additions & 0 deletions websites/A/AniMi Club/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const presence = new Presence({
clientId: "1127599137374871563",
});

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

interface VideoData {
duration: number;
currentTime: number;
paused: boolean;
}

async function getStrings() {
return presence.getStrings({
play: "general.playing",
pause: "general.paused",
browse: "general.browsing",
viewPage: "general.viewPage",
page: "general.page",
});
}

let strings: Awaited<ReturnType<typeof getStrings>>,
video: VideoData = {
duration: 0,
currentTime: 0,
paused: true,
};

presence.on("iFrameData", (data: VideoData) => {
video = data;
});

presence.on("UpdateData", async () => {
const [privacy, time] = await Promise.all([
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("time"),
]),
presenceData: PresenceData = {
details: "Где-то на сайте",
largeImageKey: Assets.Logo,
smallImageText: "AniMi Club",
};

if (!strings) strings = await getStrings();

const typeCurrent =
document
.querySelector("meta[property='og:url']")
.getAttribute("content")
.split("/")[3] === "anime"
? "аниме"
: "манга";

if (document.location.pathname === "/")
presenceData.details = "На главной странице";
else if (document.location.pathname.match(/\/(anime|manga)\//)) {
const title =
document
.querySelector("meta[property='og:title']")
?.getAttribute("content") ?? "Неизвестное название";

presenceData.details = `Смотрит страницу ${typeCurrent}`;

if (!privacy) {
presenceData.state = ${title}»`;

presenceData.buttons = [
{
label: "Смотреть страницу",
url:
document
.querySelector("meta[property='og:url']")
?.getAttribute("content") || "",
},
];
}

if (video.duration) {
presenceData.smallImageKey = video.paused ? Assets.Play : Assets.Pause;
presenceData.smallImageText = video.paused ? strings.play : strings.pause;

if (time) {
if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
} else {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestamps(video.currentTime, video.duration);
}
}
}
}

presence.setActivity(presenceData);
});

0 comments on commit 03c572a

Please sign in to comment.