Skip to content

Commit

Permalink
feat(bilibili): update presence
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWhiteDog9487 committed Nov 4, 2024
1 parent 6a7255a commit b8dce75
Showing 1 changed file with 58 additions and 41 deletions.
99 changes: 58 additions & 41 deletions websites/B/bilibili/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ let uploader: HTMLElement,
duration: number,
timestamps: number[];

const multiUploader = document.querySelector("div.membersinfo-normal");

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
Expand Down Expand Up @@ -48,49 +46,53 @@ presence.on("UpdateData", async () => {
}
}

switch (document.location.hostname) {
case "www.bilibili.com": {
switch (urlpath[1]) {
case "video": {
if (privacy) {
presenceData.details = "Watching a video";
break;
}
async function setVideoStatus() {
if (privacy) {
presenceData.details = "Watching a video";
return;
}

getTimestamps();
getTimestamps();

if (multiUploader) {
uploader = document.querySelector(".staff-name");
if (document.querySelector("div.membersinfo-normal")) {
uploader = document.querySelector(".staff-name");

uploaderName = `${uploader.textContent.trim()} + ${
parseInt(
document
.querySelector(".staff-amt")
.textContent.trim()
.replaceAll("人", "")
) - 1
} more`;
} else {
uploader = document.querySelector(".up-name");
// "\n <USERNAME>\n " -> "<USERNAME>"
uploaderName = uploader.textContent.trim();
}
uploaderName = `${uploader.textContent.trim()} + ${
parseInt(
document
.querySelector(".staff-amt")
.textContent.trim()
.replaceAll("人", "")
) - 1
} more`;
} else {
uploader = document.querySelector(".up-name");
// "\n <USERNAME>\n " -> "<USERNAME>"
uploaderName = uploader.textContent.trim();
}

uploaderLink = uploader.getAttribute("href");
title = document.querySelector(".video-title");
uploaderLink = uploader.getAttribute("href");
title = document.querySelector(".video-title");

presenceData.details = title.getAttribute("title");
presenceData.state = uploaderName;
presenceData.buttons = [
{
label: "Watch Video", // getString() later
url: `https://www.bilibili.com/video/${urlpath[2]}`,
},
{
label: "View Space", // getString() later
url: `https:${uploaderLink}`,
},
];
presenceData.details = title.getAttribute("title");
presenceData.state = uploaderName;
presenceData.buttons = [
{
label: "Watch Video", // getString() later
url: `https://www.bilibili.com/video/${urlpath[2]}`,
},
{
label: "View Space", // getString() later
url: `https:${uploaderLink}`,
},
];
}

switch (document.location.hostname) {
case "www.bilibili.com": {
switch (urlpath[1]) {
case "video": {
setVideoStatus();
break;
}
case "opus": {
Expand Down Expand Up @@ -135,7 +137,7 @@ presence.on("UpdateData", async () => {
break;
}
if (urlpath[2] === "watchlater") {
presenceData.details = "Watching a watch later playlist";
setVideoStatus();
break;
}
getTimestamps();
Expand All @@ -161,6 +163,7 @@ presence.on("UpdateData", async () => {
}
default: {
presenceData.startTimestamp = browsingTimestamp;
presenceData.details = "Viewing the homepage";
break;
}
}
Expand Down Expand Up @@ -210,6 +213,20 @@ presence.on("UpdateData", async () => {
];
break;
}
case "search.bilibili.com": {
if (privacy) {
presenceData.details = "Searching for something";
break;
}
presenceData.details = `Searching for ${document
.querySelector(".search-input-el")
.getAttribute("value")}`;
presenceData.state = `Browsing ${
document.querySelector(".vui_tabs--nav-item-active").textContent
} Category`;
presenceData.startTimestamp = browsingTimestamp;
break;
}
}

presence.setActivity(presenceData);
Expand Down

0 comments on commit b8dce75

Please sign in to comment.