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

chore(Weverse): update Presence #8816

Merged
merged 17 commits into from
Oct 17, 2024
Merged
2 changes: 1 addition & 1 deletion websites/W/Weverse/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"en": "Enjoy every moment with artists on global fandom life platform Weverse."
},
"url": "weverse.io",
"version": "1.0.1",
"version": "1.0.2",
"logo": "https://cdn.rcd.gg/PreMiD/websites/W/Weverse/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/W/Weverse/assets/thumbnail.png",
"color": "#08ccc9",
Expand Down
45 changes: 32 additions & 13 deletions websites/W/Weverse/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Weverse extends Presence {
node.matches("[class*=LiveBadgeView_badge]")
)
);

return (
titleTextNodes
.map(node => node.textContent)
Expand Down Expand Up @@ -73,6 +72,20 @@ class Weverse extends Presence {
?.textContent?.trim() ?? "Unknown User"
);
}

getProfileName(): string {
return (
document
.querySelector("h3[class*=CommunityProfileInfoView_profile_name]")
?.textContent?.trim() ?? "Unknown User"
);
}

getProfileThumbnailUrl(): string | undefined {
return document.querySelector<HTMLImageElement>(
"a[class*=CommunityProfileInfoView_link_thumbnail] img"
)?.src;
}
}

const presence = new Weverse({
Expand Down Expand Up @@ -101,13 +114,8 @@ presence.on("UpdateData", async () => {
},
];
} else if (video) {
if (video.paused) {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Paused";
} else {
presenceData.smallImageKey = Assets.Live;
presenceData.smallImageText = "Live";
}
presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Live;
presenceData.smallImageText = video.paused ? "Paused" : "Live";
presenceData.buttons = [
{
label: `Visit ${presence.getArtistName()} Live`,
Expand All @@ -126,10 +134,9 @@ presence.on("UpdateData", async () => {
}

if (thumbnailUrl) presenceData.largeImageKey = thumbnailUrl;
} else if (document.location.pathname === "/") {
} else if (document.location.pathname === "/")
presenceData.details = "Browsing Weverse";
presenceData.state = "On Homepage";
} else if (document.location.pathname.includes("/feed")) {
else if (document.location.pathname.includes("/feed")) {
presenceData.details = "Viewing Community Feed";
presenceData.state = presence.getCommunityName();

Expand All @@ -145,7 +152,6 @@ presence.on("UpdateData", async () => {
} else if (document.location.pathname.includes("/artist")) {
presenceData.details = "Viewing Artist";
presenceData.state = presence.getArtistPageName();

presenceData.buttons = [
{
label: `Visit ${presence.getArtistPageName()} Artist`,
Expand All @@ -168,13 +174,26 @@ presence.on("UpdateData", async () => {
} else if (document.location.pathname.includes("/media")) {
presenceData.details = "Viewing Media";
presenceData.state = presence.getCommunityName();

presenceData.buttons = [
{
label: `Visit ${presence.getCommunityName()} Media`,
url: document.location.href,
},
];
} else if (document.location.pathname.includes("/profile")) {
const profileName = presence.getProfileName();
presenceData.details = `Viewing Profile of ${profileName}`;
presenceData.state = `Community: ${presence.getCommunityName()}`;

const profileThumbnailUrl = presence.getProfileThumbnailUrl();
if (profileThumbnailUrl) presenceData.largeImageKey = profileThumbnailUrl;

presenceData.buttons = [
{
label: `Visit ${profileName}'s Profile`,
url: document.location.href,
},
];
}

presence.setActivity(presenceData);
Expand Down
Loading