diff --git a/websites/A/AniMi Club/iframe.ts b/websites/A/AniMi Club/iframe.ts new file mode 100644 index 000000000000..b7bf83e2d2cb --- /dev/null +++ b/websites/A/AniMi Club/iframe.ts @@ -0,0 +1,16 @@ +const iframe = new iFrame(); + +iframe.on("UpdateData", async () => { + if (document.querySelector("video")) { + const video: HTMLVideoElement = + document.querySelector("video"); + + if (video && !isNaN(video.duration)) { + iframe.send({ + duration: video.duration, + currentTime: video.currentTime, + paused: video.paused, + }); + } + } +}); diff --git a/websites/A/AniMi Club/metadata.json b/websites/A/AniMi Club/metadata.json new file mode 100644 index 000000000000..5f9d5d959b59 --- /dev/null +++ b/websites/A/AniMi Club/metadata.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/websites/A/AniMi Club/presence.ts b/websites/A/AniMi Club/presence.ts new file mode 100644 index 000000000000..d87b9f2194ee --- /dev/null +++ b/websites/A/AniMi Club/presence.ts @@ -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>, + 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("privacy"), + presence.getSetting("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); +});