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 page and settings #8834

Merged
merged 21 commits into from
Oct 24, 2024
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
21 changes: 19 additions & 2 deletions 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.2",
"version": "1.0.3",
"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 All @@ -21,5 +21,22 @@
"live",
"streaming",
"music"
],
"settings": [
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fad fa-user-secret",
"value": false
},
{
"id": "buttons",
"if": {
"privacy": false
},
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
}
]
}
}
132 changes: 69 additions & 63 deletions websites/W/Weverse/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,48 @@ class Weverse extends Presence {
"a[class*=CommunityProfileInfoView_link_thumbnail] img"
)?.src;
}

getFanPostNickname(): string {
const nicknameElement = document.querySelector(
"#modal [class*=PostHeaderView_nickname]"
);
if (nicknameElement) {
const tempDiv = document.createElement("div");
tempDiv.innerHTML = nicknameElement.innerHTML;

for (const el of Array.from(tempDiv.querySelectorAll("em, span")))
el.remove();

return tempDiv.textContent?.trim() ?? "Unknown User";
}
return "Unknown User";
}

getFanPostThumbnailUrl(): string | undefined {
return document.querySelector<HTMLImageElement>(
"#modal [class*=ProfileThumbnailView_thumbnail] img"
)?.src;
}
}

const presence = new Weverse({
clientId: "1284048129414402109",
});
clientId: "1284048129414402109",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/W/Weverse/assets/logo.png",
};
const privacy = await presence.getSetting<boolean>("privacy"),
showButtons = await presence.getSetting<boolean>("buttons"),
presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/W/Weverse/assets/logo.png",
startTimestamp: browsingTimestamp,
};

if (privacy) {
presence.setActivity(presenceData);
return;
}

if (document.location.pathname.includes("/live/")) {
const thumbnailUrl = presence.getThumbnailUrl();
Expand All @@ -107,30 +138,36 @@ presence.on("UpdateData", async () => {
if (document.querySelector("[class*=LiveBadgeView_-replay]") !== null) {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Replay";
presenceData.buttons = [
{
label: `Watch ${presence.getArtistName()} Replay`,
url: document.location.href,
},
];
if (showButtons) {
presenceData.buttons = [
{
label: `Watch ${presence.getArtistName()} Replay`,
url: document.location.href,
},
];
}
} else if (video) {
presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Live;
presenceData.smallImageText = video.paused ? "Paused" : "Live";
presenceData.buttons = [
{
label: `Visit ${presence.getArtistName()} Live`,
url: document.location.href,
},
];
if (showButtons) {
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 (showButtons) {
presenceData.buttons = [
{
label: `Watch ${presence.getArtistName()} Replay`,
url: document.location.href,
},
];
}
}

if (thumbnailUrl) presenceData.largeImageKey = thumbnailUrl;
Expand All @@ -139,62 +176,31 @@ presence.on("UpdateData", async () => {
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,
},
];
} else if (document.location.pathname.includes("/profile")) {
const profileName = presence.getProfileName();
presenceData.details = `Viewing Profile of ${profileName}`;
presenceData.details = `Viewing Profile of ${presence.getProfileName()}`;
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,
},
];
} else if (document.location.pathname.includes("/fanpost/")) {
presenceData.details = "Viewing Fan Post";
presenceData.state = presence.getFanPostNickname();
const fanPostThumbnailUrl = presence.getFanPostThumbnailUrl();
if (fanPostThumbnailUrl) presenceData.largeImageKey = fanPostThumbnailUrl;
}

presence.setActivity(presenceData);
if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});
Loading