From abaf25304d0eff11b2e88dc6310fd63ba159fc09 Mon Sep 17 00:00:00 2001 From: Kito Date: Wed, 8 Jan 2025 04:27:57 +0300 Subject: [PATCH 1/2] style(AnimeLib): change activity styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(AnimeLib): privacy mode for 'collections' case feat(AnimeLib): add collection type in 'collections' case Collection type is shown in the details and follows this format: "Коллекция по " (" collection") feat(AnimeLib): add placeholder for unavailability to display info when watching a licensed anime fix(AnimeLib): fail to get current episode number in specific window size --- websites/A/AnimeLib/lib.ts | 3 + websites/A/AnimeLib/metadata.json | 2 +- websites/A/AnimeLib/presence.ts | 102 +++++++++++++++++++++++------- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/websites/A/AnimeLib/lib.ts b/websites/A/AnimeLib/lib.ts index 682fc6727208..c7dd07413d1d 100644 --- a/websites/A/AnimeLib/lib.ts +++ b/websites/A/AnimeLib/lib.ts @@ -51,6 +51,8 @@ export interface CollectionData { id: number; name: string; user: Author; + type: "titles" | "character" | "people"; + adult: boolean; } export interface ReviewData { @@ -93,6 +95,7 @@ interface Cover { } export type AgeRestriction = + | { id: 0; label: "Нет" } | { id: 1; label: "6+" } | { id: 2; label: "12+" } | { id: 3; label: "16+" } diff --git a/websites/A/AnimeLib/metadata.json b/websites/A/AnimeLib/metadata.json index df512a3e3efe..56ec41c1381c 100644 --- a/websites/A/AnimeLib/metadata.json +++ b/websites/A/AnimeLib/metadata.json @@ -14,7 +14,7 @@ "ru": "Смотрите аниме онлайн на русском" }, "url": "anilib.me", - "version": "1.0.4", + "version": "1.0.5", "logo": "https://cdn.rcd.gg/PreMiD/websites/A/AnimeLib/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/AnimeLib/assets/thumbnail.png", "color": "#A020F0", diff --git a/websites/A/AnimeLib/presence.ts b/websites/A/AnimeLib/presence.ts index 49b6af04e4e2..5a15ea8e06e5 100644 --- a/websites/A/AnimeLib/presence.ts +++ b/websites/A/AnimeLib/presence.ts @@ -48,6 +48,8 @@ presence.on("UpdateData", async () => { largeImageKey: Assets.Logo, type: ActivityType.Watching, startTimestamp: browsingTimestamp, + largeImageText: "AnimeLib", + smallImageText: "AnimeLib", }, [privacySetting, buttonsSetting] = await Promise.all([ presence.getSetting("privacy"), @@ -81,22 +83,20 @@ presence.on("UpdateData", async () => { break; } - if (animeData.toast) { - const cover = - document.querySelector(".cover__img")?.src, - title = document.querySelector("h1")?.textContent, - altTitle = document.querySelector("h2")?.textContent; + if (path.endsWith("/watch")) { + if (animeData.toast) { + presenceData.details = "Смотрит лицензированное аниме"; + presenceData.state = "Информация пока что не доступна"; + presenceData.buttons = [ + { + label: "Открыть аниме", + url: cleanUrl(document.location), + }, + ]; - if (cover && title && altTitle) { - presenceData.details = "Страница лицензированного аниме"; - presenceData.state = `${title} (${altTitle})`; - presenceData.largeImageKey = cover; + break; } - break; - } - - if (path.endsWith("/watch")) { const video = document.querySelector("video"), dub = document @@ -109,14 +109,18 @@ presence.on("UpdateData", async () => { if (dub) { presenceData.details = animeData.rus_name; presenceData.state = `${ - document.querySelector("[id^='episode'][class*=' ']") + document.querySelector("[id^='episode'][class*=' '] > span") ?.textContent ?? document .querySelectorAll(".btn.is-outline")[6] ?.querySelector("span")?.textContent ?? + document + .querySelectorAll(".btn.is-outline")[7] + ?.querySelector("span")?.textContent ?? "Фильм" } | ${dub}`; presenceData.largeImageKey = animeData.cover.default; + presenceData.largeImageText = animeData.rus_name; presenceData.buttons = [ { label: "Открыть аниме", @@ -160,11 +164,34 @@ presence.on("UpdateData", async () => { } } } else { + if (animeData.toast) { + const cover = + document.querySelector(".cover__img")?.src, + title = document.querySelector("h1")?.textContent, + altTitle = document.querySelector("h2")?.textContent; + + if (cover && title && altTitle) { + presenceData.details = "Страница лицензированного аниме"; + presenceData.state = `${title} (${altTitle})`; + presenceData.largeImageKey = cover; + presenceData.largeImageText = title; + presenceData.buttons = [ + { + label: "Открыть аниме", + url: cleanUrl(document.location), + }, + ]; + } + + break; + } + presenceData.details = "Страница аниме"; presenceData.state = `${animeData.rus_name} (${ animeData.eng_name ?? animeData.name })`; presenceData.largeImageKey = animeData.cover.default; + presenceData.largeImageText = animeData.rus_name; presenceData.buttons = [ { label: "Открыть аниме", @@ -187,6 +214,8 @@ presence.on("UpdateData", async () => { presenceData.details = "Страница персонажа"; presenceData.state = `${characterData.rus_name} (${characterData.name})`; presenceData.largeImageKey = characterData.cover.default; + presenceData.largeImageText = characterData.rus_name; + presenceData.smallImageKey = Assets.Logo; presenceData.buttons = [ { label: "Oткрыть персoнажа", @@ -210,15 +239,18 @@ presence.on("UpdateData", async () => { path.split("/")[3].split("-")[0] ).then(response => response.data); - presenceData.details = "Страница человека"; - presenceData.state = `${ + const name = peopleData.rus_name !== "" ? peopleData.rus_name : peopleData.alt_name !== "" ? peopleData.alt_name - : peopleData.name - } (${peopleData.name})`; + : peopleData.name; + + presenceData.details = "Страница человека"; + presenceData.state = `${name} (${peopleData.name})`; presenceData.largeImageKey = peopleData.cover.default; + presenceData.largeImageText = name; + presenceData.smallImageKey = Assets.Logo; presenceData.buttons = [ { label: "Открыть человека", @@ -248,6 +280,7 @@ presence.on("UpdateData", async () => { presenceData.details = "Страница пользователя"; presenceData.state = userData.username; presenceData.largeImageKey = userData.avatar.url; + presenceData.largeImageText = userData.username; presenceData.smallImageKey = Assets.Logo; presenceData.buttons = [ { @@ -275,9 +308,30 @@ presence.on("UpdateData", async () => { path.split("/")[3] ).then(response => response.data); - presenceData.details = "Страница коллекции"; + // Show collection viewing in privacy mode if it's enabled, or enforce it when collection was marked as for adults + if (privacySetting || collectionData.adult) { + setPrivacyMode(presenceData); + break; + } + + let collectionType: string; + switch (collectionData.type) { + case "titles": + collectionType = "тайтлам"; + break; + case "character": + collectionType = "персонажам"; + break; + case "people": + collectionType = "людям"; + break; + } + + presenceData.details = `Коллекция по ${collectionType}`; presenceData.state = `${collectionData.name} от ${collectionData.user.username}`; - presenceData.largeImageKey = collectionData.user.avatar.url; + presenceData.largeImageKey = Assets.Logo; + presenceData.smallImageKey = collectionData.user.avatar.url; + presenceData.smallImageText = collectionData.user.username; presenceData.buttons = [ { label: "Oткрыть кoллекцию", @@ -308,9 +362,10 @@ presence.on("UpdateData", async () => { break; } - presenceData.details = `Страница отзыва на ${reviewData.related.rus_name}`; + presenceData.details = `Отзыв на ${reviewData.related.rus_name}`; presenceData.state = `${reviewData.title} от ${reviewData.user.username}`; presenceData.largeImageKey = reviewData.related.cover.default; + presenceData.largeImageText = reviewData.related.rus_name; presenceData.smallImageKey = reviewData.user.avatar.url; presenceData.smallImageText = reviewData.user.username; presenceData.buttons = [ @@ -423,8 +478,9 @@ presence.on("UpdateData", async () => { if (avatar && username && title) { presenceData.details = "Читает новость"; presenceData.state = `${title} от ${username}`; - presenceData.largeImageKey = avatar; - presenceData.smallImageKey = Assets.Logo; + presenceData.largeImageKey = Assets.Logo; + presenceData.smallImageKey = avatar; + presenceData.smallImageText = username; presenceData.buttons = [ { label: "Открыть новость", From a4ccf1492776c9aec4ce321e4b1f0f078533fa35 Mon Sep 17 00:00:00 2001 From: Kitosight Date: Thu, 9 Jan 2025 05:49:14 +0300 Subject: [PATCH 2/2] chore(AnimeLib): more accurate checks for episode number/movie fix(AnimeLib): crash when 'rus_name' is empty string Replaces with 'name' as it is always present --- websites/A/AnimeLib/presence.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/websites/A/AnimeLib/presence.ts b/websites/A/AnimeLib/presence.ts index 5a15ea8e06e5..6fea0b8b06f3 100644 --- a/websites/A/AnimeLib/presence.ts +++ b/websites/A/AnimeLib/presence.ts @@ -104,11 +104,8 @@ presence.on("UpdateData", async () => { ?.querySelector(".menu-item__text").textContent ?? document .querySelector(".btn.is-plain.is-outline") - ?.querySelector("strong")?.textContent; - - if (dub) { - presenceData.details = animeData.rus_name; - presenceData.state = `${ + ?.querySelector("strong")?.textContent, + episode = document.querySelector("[id^='episode'][class*=' '] > span") ?.textContent ?? document @@ -116,11 +113,17 @@ presence.on("UpdateData", async () => { ?.querySelector("span")?.textContent ?? document .querySelectorAll(".btn.is-outline")[7] - ?.querySelector("span")?.textContent ?? - "Фильм" + ?.querySelector("span")?.textContent; + + if (dub) { + presenceData.details = + animeData.rus_name !== "" ? animeData.rus_name : animeData.name; + presenceData.state = `${ + episode ? (episode.includes("эпизод") ? episode : "Фильм") : "Фильм" } | ${dub}`; presenceData.largeImageKey = animeData.cover.default; - presenceData.largeImageText = animeData.rus_name; + presenceData.largeImageText = + animeData.rus_name !== "" ? animeData.rus_name : animeData.name; presenceData.buttons = [ { label: "Открыть аниме", @@ -187,11 +190,12 @@ presence.on("UpdateData", async () => { } presenceData.details = "Страница аниме"; - presenceData.state = `${animeData.rus_name} (${ - animeData.eng_name ?? animeData.name - })`; + presenceData.state = `${ + animeData.rus_name !== "" ? animeData.rus_name : animeData.name + } (${animeData.eng_name ?? animeData.name})`; presenceData.largeImageKey = animeData.cover.default; - presenceData.largeImageText = animeData.rus_name; + presenceData.largeImageText = + animeData.rus_name !== "" ? animeData.rus_name : animeData.name; presenceData.buttons = [ { label: "Открыть аниме",