Skip to content

Commit

Permalink
feat(bilibili): update presence (PreMiD#8688)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWhiteDog9487 authored Aug 28, 2024
1 parent 313e158 commit 83e2de7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
6 changes: 5 additions & 1 deletion websites/B/bilibili/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{
"name": "Moe Kotoki",
"id": "276627005280092162"
},
{
"name": "TheWhiteDog9487",
"id": "531317938863603722"
}
],
"service": "bilibili",
Expand All @@ -23,7 +27,7 @@
"biligame.com"
],
"regExp": "([a-z0-9-]+[.])*(bilibili|biligame)[.]com[/]",
"version": "2.4.2",
"version": "2.5.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/B/bilibili/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/B/bilibili/assets/thumbnail.jpg",
"color": "#05acff",
Expand Down
99 changes: 98 additions & 1 deletion websites/B/bilibili/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,72 @@ presence.on("UpdateData", async () => {
];
break;
}
case "opus": {
if (privacy) {
presenceData.details = "Viewing a tweet";
break;
}
presenceData.details = `Viewing ${document
.querySelector(".opus-module-author__name")
.textContent.trim()}'s tweet`;
presenceData.buttons = [
{
label: "View Tweet",
url: `https://www.bilibili.com/opus/${urlpath[2]}`,
},
];
presenceData.startTimestamp = browsingTimestamp;
break;
}
case "read": {
if (privacy) {
presenceData.details = "Reading an article";
break;
}
presenceData.details = document
.querySelector(".title")
.textContent.trim();
presenceData.state = document
.querySelector(".up-name")
.textContent.trim();
presenceData.buttons = [
{
label: "Read Article",
url: `https://www.bilibili.com/read/${urlpath[2]}`,
},
];
break;
}
case "list": {
if (privacy) {
presenceData.details = "Watching a playlist";
break;
}
if (urlpath[2] === "watchlater") {
presenceData.details = "Watching a watch later playlist";
break;
}
getTimestamps();
presenceData.details = document
.querySelector(".list-title")
.textContent.trim();
presenceData.state = document
.querySelector(".video-title")
.textContent.trim();
presenceData.buttons = [
{
label: "View Playlist",
url: `https://www.bilibili.com/list/${urlpath[2]}`,
},
{
label: "Watch Video",
url: `https:${document
.querySelector(".video-title-href")
.getAttribute("href")}`,
},
];
break;
}
default: {
presenceData.startTimestamp = browsingTimestamp;
break;
Expand All @@ -107,12 +173,43 @@ presence.on("UpdateData", async () => {
presenceData.state = `${uploader.textContent} | UID:${urlpath[1]}`;
presenceData.buttons = [
{
label: "View Space", // getString() later
label: "View Space",
url: `https://space.bilibili.com/${urlpath[1]}`,
},
];
break;
}
case "t.bilibili.com": {
presenceData.details = "Viewing tweets";
presenceData.startTimestamp = browsingTimestamp;
break;
}
case "message.bilibili.com": {
presenceData.details = "Viewing messages";
presenceData.startTimestamp = browsingTimestamp;
break;
}
case "live.bilibili.com": {
if (document.querySelector(".small-title") === null) {
presenceData.details = document
.querySelector(".smaller-title")
.textContent.trim();
} else if (document.querySelector(".smaller-title") === null) {
presenceData.details = document
.querySelector(".small-title")
.textContent.trim();
}
presenceData.state = document
.querySelector(".room-owner-username")
.textContent.trim();
presenceData.buttons = [
{
label: "Watch Stream",
url: `https://live.bilibili.com/${urlpath[1]}`,
},
];
break;
}
}

presence.setActivity(presenceData);
Expand Down

0 comments on commit 83e2de7

Please sign in to comment.