Skip to content

Commit

Permalink
feat(bilibili): add episode support and fix article bug (#9259)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Metz <[email protected]>
  • Loading branch information
TheWhiteDog9487 and Timeraa authored Feb 19, 2025
1 parent 38af026 commit 80733b5
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions websites/B/bilibili/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,27 @@ presence.on('UpdateData', async () => {
presenceData.details = 'Viewing a tweet'
break
}
presenceData.details = `Viewing ${document
.querySelector('.opus-module-author__name')
const type
= document.querySelector('.opus-module-title') === null
? 'tweet'
: 'article'
presenceData.details
= type === 'tweet'
? null
: document.querySelector('.opus-module-title')?.textContent?.trim()
presenceData.state = `Viewing ${document
?.querySelector('.opus-module-author__name')
?.textContent
?.trim()}'s tweet`
?.trim()}'s ${type}`
presenceData.buttons = [
{
label: 'View Tweet',
label: `View ${type}`,
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'
Expand All @@ -148,11 +135,11 @@ presence.on('UpdateData', async () => {
}
getTimestamps()
presenceData.details = document
.querySelector('.list-title')
?.querySelector('.list-title')
?.textContent
?.trim()
presenceData.state = document
.querySelector('.video-title')
?.querySelector('.video-title')
?.textContent
?.trim()
presenceData.buttons = [
Expand All @@ -163,12 +150,34 @@ presence.on('UpdateData', async () => {
{
label: 'Watch Video',
url: `https:${document
.querySelector('.video-title-href')
?.querySelector('.video-title-href')
?.getAttribute('href')}`,
},
]
break
}
case 'bangumi': {
if (privacy) {
presenceData.details = 'Watching an episode'
break
}
getTimestamps()
presenceData.details = document
?.querySelector('.mediainfo_mediaTitle__Zyiqh')
?.textContent
?.trim()
presenceData.state = `Watching Episode ${document
?.querySelector('.numberListItem_select__WgCVr')
?.getAttribute('title')
?.trim()} now`
presenceData.buttons = [
{
label: 'Watch Episode',
url: `https://www.bilibili.com/bangumi/play/${urlpath[3]}`,
},
]
break
}
default: {
presenceData.startTimestamp = browsingTimestamp
presenceData.details = 'Viewing the homepage'
Expand Down

0 comments on commit 80733b5

Please sign in to comment.