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

feat(Weverse): add presence #8777

Merged
merged 13 commits into from
Oct 8, 2024
25 changes: 25 additions & 0 deletions websites/W/Weverse/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://schemas.premid.app/metadata/1.11",
"apiVersion": 1,
"author": {
"id": "712745906876842025",
"name": "hanifhan1f"
},
"service": "Weverse",
"description": {
"en": "Displays the current live stream activity for a Weverse live page."
Synxx12 marked this conversation as resolved.
Show resolved Hide resolved
},
"url": "weverse.io",
"version": "1.0.0",
"logo": "https://res.cloudinary.com/debvitdiw/image/upload/v1727852958/Presences/WeverseLogo.png",
"thumbnail": "https://res.cloudinary.com/debvitdiw/image/upload/v1726211170/Presences/thumbnail.png",
"color": "#08ccc9",
"category": "music",
"tags": [
"weverse",
"kpop",
"live",
"streaming",
"music"
]
}
181 changes: 181 additions & 0 deletions websites/W/Weverse/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
class Weverse extends Presence {
constructor(options: PresenceOptions) {
super(options);
}

getArtistName(): string {
return (
document
.querySelector(".LiveArtistProfileView_name_item__8W66y")
?.textContent?.trim() ?? "Unknown Artist"
);
}

getStreamTitle(): string {
const titleElement = document.querySelector("h2.TitleView_title__SSnHb");
Synxx12 marked this conversation as resolved.
Show resolved Hide resolved
if (titleElement) {
const titleTextNodes = Array.from(titleElement.childNodes).filter(
node =>
!(
node instanceof HTMLElement &&
node.matches(".LiveBadgeView_badge__o2vFt")
)
);

return (
titleTextNodes
.map(node => node.textContent)
.join("")
.trim() || "Unknown Title"
);
}
return "Unknown Title";
}

getThumbnailUrl(): string | undefined {
return document.querySelector<HTMLImageElement>(
".ProfileThumbnailView_thumbnail_wrap__ZgeTf img"
)?.src;
}

getCommunityName(): string {
return (
document
.querySelector(".HeaderCommunityDropdownWrapperView_name__FZXsx")
?.textContent?.trim() ?? "Unknown Community"
);
}

getCommunityImageUrl(): string | undefined {
return document.querySelector<HTMLImageElement>(
".CommunityAsideWelcomeView_thumbnail__5MVun"
)?.src;
}

getArtistPageName(): string {
return (
document
.querySelector(".HeaderCommunityDropdownWrapperView_name__FZXsx")
?.textContent?.trim() ?? "Unknown Artist"
);
}

getMomentThumbnailUrl(): string | undefined {
return document.querySelector<HTMLImageElement>(
".ProfileThumbnailView_thumbnail_wrap__ZgeTf img"
)?.src;
}

getMomentNickname(): string {
return (
document
.querySelector(".PostHeaderView_nickname__6Cb7X")
?.textContent?.trim() ?? "Unknown User"
);
}
}

const presence = new Weverse({
clientId: "1284048129414402109",
});

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://res.cloudinary.com/debvitdiw/image/upload/v1727852958/Presences/WeverseLogo.png",
};

if (document.location.pathname.includes("/live/")) {
const thumbnailUrl = presence.getThumbnailUrl();
presenceData.details = presence.getStreamTitle();
presenceData.state = presence.getArtistName();

const video = document.querySelector("video");
if (document.querySelector(".LiveBadgeView_-replay__nNx34") !== null) {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Replay";
presenceData.buttons = [
{
label: `Watch ${presence.getArtistName()} Replay`,
url: document.location.href,
},
];
} else if (video) {
if (video.paused) {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Paused";
} else {
presenceData.smallImageKey = Assets.Live;
presenceData.smallImageText = "Live";
}
presenceData.buttons = [
{
label: `Visit ${presence.getArtistName()} Live`,
url: document.location.href,
},
];
} else {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Playing";
presenceData.buttons = [
{
label: `Watch ${presence.getArtistName()} Replay`,
url: document.location.href,
},
];
}

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

const communityImageUrl = presence.getCommunityImageUrl();
if (communityImageUrl) presenceData.largeImageKey = communityImageUrl;

presenceData.buttons = [
{
label: `Visit ${presence.getCommunityName()} Feed`,
url: document.location.href,
},
];
} else if (document.location.pathname.includes("/artist")) {
presenceData.details = "Viewing Artist";
presenceData.state = presence.getArtistPageName();

presenceData.buttons = [
{
label: `Visit ${presence.getArtistPageName()} Artist`,
url: document.location.href,
},
];
} else if (document.location.pathname.includes("/moment")) {
presenceData.details = "Viewing Moment";
presenceData.state = presence.getMomentNickname();

const momentThumbnailUrl = presence.getMomentThumbnailUrl();
if (momentThumbnailUrl) presenceData.largeImageKey = momentThumbnailUrl;

presenceData.buttons = [
{
label: `Visit ${presence.getMomentNickname()} Moment`,
url: document.location.href,
},
];
} 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,
},
];
}

presence.setActivity(presenceData);
});
Loading