Skip to content

Commit

Permalink
style(AnimeLib): change activity styling (#9127)
Browse files Browse the repository at this point in the history
* style(AnimeLib): change activity styling

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: "Коллекция по <type>" ("<type> 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

* 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
  • Loading branch information
Kitosight authored Jan 9, 2025
1 parent 8828d15 commit eacbde2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 33 deletions.
3 changes: 3 additions & 0 deletions websites/A/AnimeLib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface CollectionData {
id: number;
name: string;
user: Author;
type: "titles" | "character" | "people";
adult: boolean;
}

export interface ReviewData {
Expand Down Expand Up @@ -93,6 +95,7 @@ interface Cover {
}

export type AgeRestriction =
| { id: 0; label: "Нет" }
| { id: 1; label: "6+" }
| { id: 2; label: "12+" }
| { id: 3; label: "16+" }
Expand Down
2 changes: 1 addition & 1 deletion websites/A/AnimeLib/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
124 changes: 92 additions & 32 deletions websites/A/AnimeLib/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>("privacy"),
Expand Down Expand Up @@ -81,42 +83,47 @@ presence.on("UpdateData", async () => {
break;
}

if (animeData.toast) {
const cover =
document.querySelector<HTMLImageElement>(".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
.querySelector(".menu-item.is-active")
?.querySelector(".menu-item__text").textContent ??
document
.querySelector(".btn.is-plain.is-outline")
?.querySelector("strong")?.textContent;

if (dub) {
presenceData.details = animeData.rus_name;
presenceData.state = `${
document.querySelector("[id^='episode'][class*=' ']")
?.querySelector("strong")?.textContent,
episode =
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;

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 !== "" ? animeData.rus_name : animeData.name;
presenceData.buttons = [
{
label: "Открыть аниме",
Expand Down Expand Up @@ -160,11 +167,35 @@ presence.on("UpdateData", async () => {
}
}
} else {
if (animeData.toast) {
const cover =
document.querySelector<HTMLImageElement>(".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.state = `${
animeData.rus_name !== "" ? animeData.rus_name : animeData.name
} (${animeData.eng_name ?? animeData.name})`;
presenceData.largeImageKey = animeData.cover.default;
presenceData.largeImageText =
animeData.rus_name !== "" ? animeData.rus_name : animeData.name;
presenceData.buttons = [
{
label: "Открыть аниме",
Expand All @@ -187,6 +218,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нажа",
Expand All @@ -210,15 +243,18 @@ presence.on("UpdateData", async () => {
path.split("/")[3].split("-")[0]
).then(response => <PersonData>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: "Открыть человека",
Expand Down Expand Up @@ -248,6 +284,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 = [
{
Expand Down Expand Up @@ -275,9 +312,30 @@ presence.on("UpdateData", async () => {
path.split("/")[3]
).then(response => <CollectionData>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ллекцию",
Expand Down Expand Up @@ -308,9 +366,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 = [
Expand Down Expand Up @@ -423,8 +482,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: "Открыть новость",
Expand Down

0 comments on commit eacbde2

Please sign in to comment.