mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { getCookieValue } from '@/core/utils'
|
|
import { FeedsCardCallback } from '../types'
|
|
import { feedsCardCallbacks } from './base'
|
|
import { FeedsCardsManagerV1 } from './v1'
|
|
import { FeedsCardsManagerV2 } from './v2'
|
|
|
|
export * from './base'
|
|
export const isV2Feeds = () => {
|
|
const hasCookieValue = parseInt(getCookieValue('hit-dyn-v2')) > 0
|
|
if (!hasCookieValue) {
|
|
return false
|
|
}
|
|
return [
|
|
't.bilibili.com',
|
|
'space.bilibili.com',
|
|
].some(host => location.host === host)
|
|
}
|
|
export const feedsCardsManager = (() => {
|
|
const isV2 = isV2Feeds()
|
|
if (isV2) {
|
|
return new FeedsCardsManagerV2()
|
|
}
|
|
return new FeedsCardsManagerV1()
|
|
})()
|
|
/**
|
|
* 为每个动态卡片执行特定操作
|
|
* @param callback 回调函数
|
|
*/
|
|
export const forEachFeedsCard = async (callback: FeedsCardCallback) => {
|
|
const success = await feedsCardsManager.startWatching()
|
|
if (!success) {
|
|
console.error('feedsCardsManager.startWatching() failed')
|
|
return null
|
|
}
|
|
|
|
const { added } = callback
|
|
if (added) {
|
|
feedsCardsManager.cards.forEach(c => added(c))
|
|
}
|
|
feedsCardCallbacks.push({ added: none, removed: none, ...callback })
|
|
return feedsCardsManager
|
|
}
|