Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(AnimeLib): change activity styling #9127

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Bas950 marked this conversation as resolved.
Show resolved Hide resolved
},
[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
Loading