mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add repost data (#1036)
This commit is contained in:
parent
55f5a6b675
commit
f8a8f972a3
2
min/feeds-apis.min.js
vendored
2
min/feeds-apis.min.js
vendored
File diff suppressed because one or more lines are too long
@ -4,11 +4,15 @@ export interface FeedsCardType {
|
|||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
export interface RepostFeedsCardType extends FeedsCardType {
|
||||||
|
id: 1
|
||||||
|
name: '转发'
|
||||||
|
}
|
||||||
export const feedsCardTypes = {
|
export const feedsCardTypes = {
|
||||||
repost: {
|
repost: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: '转发',
|
name: '转发',
|
||||||
} as FeedsCardType,
|
} as RepostFeedsCardType,
|
||||||
textWithImages: {
|
textWithImages: {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: '图文'
|
name: '图文'
|
||||||
@ -68,7 +72,7 @@ export const feedsCardTypes = {
|
|||||||
liveRecord: {
|
liveRecord: {
|
||||||
id: 2047, // FIXME: 暂时随便写个 id 了, 这个东西目前找不到 type
|
id: 2047, // FIXME: 暂时随便写个 id 了, 这个东西目前找不到 type
|
||||||
name: '开播记录',
|
name: '开播记录',
|
||||||
},
|
} as FeedsCardType,
|
||||||
}
|
}
|
||||||
export interface FeedsCard {
|
export interface FeedsCard {
|
||||||
id: string
|
id: string
|
||||||
@ -82,6 +86,11 @@ export interface FeedsCard {
|
|||||||
presented: boolean
|
presented: boolean
|
||||||
getText: () => Promise<string>
|
getText: () => Promise<string>
|
||||||
}
|
}
|
||||||
|
export interface RepostFeedsCard extends FeedsCard {
|
||||||
|
repostUsername: string
|
||||||
|
repostText: string
|
||||||
|
type: RepostFeedsCardType
|
||||||
|
}
|
||||||
const getFeedsCardType = (element: HTMLElement) => {
|
const getFeedsCardType = (element: HTMLElement) => {
|
||||||
if (element.querySelector('.repost')) {
|
if (element.querySelector('.repost')) {
|
||||||
return feedsCardTypes.repost
|
return feedsCardTypes.repost
|
||||||
@ -112,7 +121,9 @@ const getFeedsCardType = (element: HTMLElement) => {
|
|||||||
}
|
}
|
||||||
return feedsCardTypes.text
|
return feedsCardTypes.text
|
||||||
}
|
}
|
||||||
|
const isRepostType = (card: FeedsCard): card is RepostFeedsCard => {
|
||||||
|
return card.type === feedsCardTypes.repost
|
||||||
|
}
|
||||||
export type FeedsCardCallback = {
|
export type FeedsCardCallback = {
|
||||||
added?: (card: FeedsCard) => void
|
added?: (card: FeedsCard) => void
|
||||||
removed?: (card: FeedsCard) => void
|
removed?: (card: FeedsCard) => void
|
||||||
@ -213,6 +224,25 @@ class FeedsCardsManager extends EventTarget {
|
|||||||
const subElementText = subElement.innerText.trim()
|
const subElementText = subElement.innerText.trim()
|
||||||
return subElementText
|
return subElementText
|
||||||
}
|
}
|
||||||
|
const getRepostData = (vueData: any) => {
|
||||||
|
// 被转发动态已失效
|
||||||
|
if (vueData.card.origin === undefined) {
|
||||||
|
return {
|
||||||
|
originalText: '',
|
||||||
|
originalDescription: '',
|
||||||
|
originalTitle: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const originalCard = JSON.parse(vueData.card.origin)
|
||||||
|
const originalText: string = vueData.originCardData.pureText
|
||||||
|
const originalDescription: string = _.get(originalCard, 'item.description', '')
|
||||||
|
const originalTitle: string = originalCard.title
|
||||||
|
return {
|
||||||
|
originalText,
|
||||||
|
originalDescription,
|
||||||
|
originalTitle,
|
||||||
|
}
|
||||||
|
}
|
||||||
const getComplexText = async (type: FeedsCardType) => {
|
const getComplexText = async (type: FeedsCardType) => {
|
||||||
if (type === feedsCardTypes.bangumi) {
|
if (type === feedsCardTypes.bangumi) {
|
||||||
return ''
|
return ''
|
||||||
@ -232,19 +262,10 @@ class FeedsCardsManager extends EventTarget {
|
|||||||
const vueData = getVueData(el)
|
const vueData = getVueData(el)
|
||||||
if (type === feedsCardTypes.repost) {
|
if (type === feedsCardTypes.repost) {
|
||||||
const currentText = vueData.card.item.content
|
const currentText = vueData.card.item.content
|
||||||
// 被转发动态已失效
|
const repostData = getRepostData(vueData)
|
||||||
if (vueData.card.origin === undefined) {
|
|
||||||
return currentText
|
|
||||||
}
|
|
||||||
const originalCard = JSON.parse(vueData.card.origin)
|
|
||||||
const originalText = vueData.originCardData.pureText
|
|
||||||
const originalDescription = _.get(originalCard, 'item.description', '')
|
|
||||||
const originalTitle = originalCard.title
|
|
||||||
return [
|
return [
|
||||||
currentText,
|
currentText,
|
||||||
originalText,
|
...Object.values(repostData).filter(it => it !== ''),
|
||||||
originalDescription,
|
|
||||||
originalTitle
|
|
||||||
].filter(it => Boolean(it)).join('\n')
|
].filter(it => Boolean(it)).join('\n')
|
||||||
}
|
}
|
||||||
const currentText = vueData.originCardData.pureText
|
const currentText = vueData.originCardData.pureText
|
||||||
@ -281,13 +302,15 @@ class FeedsCardsManager extends EventTarget {
|
|||||||
await card.getText()
|
await card.getText()
|
||||||
card.presented = element.parentNode !== null
|
card.presented = element.parentNode !== null
|
||||||
element.setAttribute('data-type', card.type.id.toString())
|
element.setAttribute('data-type', card.type.id.toString())
|
||||||
if (card.type === feedsCardTypes.repost) {
|
if (isRepostType(card)) {
|
||||||
const currentUsername = card.username
|
const currentUsername = card.username
|
||||||
const vueData = getVueData(card.element)
|
const vueData = getVueData(card.element)
|
||||||
const repostUsername = _.get(vueData, 'card.origin_user.info.uname', '')
|
const repostUsername = _.get(vueData, 'card.origin_user.info.uname', '')
|
||||||
if (currentUsername === repostUsername) {
|
if (currentUsername === repostUsername) {
|
||||||
element.setAttribute('data-self-repost', 'true')
|
element.setAttribute('data-self-repost', 'true')
|
||||||
}
|
}
|
||||||
|
card.repostUsername = repostUsername
|
||||||
|
card.repostText = getRepostData(vueData).originalText
|
||||||
}
|
}
|
||||||
// if (card.text === '') {
|
// if (card.text === '') {
|
||||||
// console.warn('card text parsing failed!', card)
|
// console.warn('card text parsing failed!', card)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user