🎈 pref: 优化哔哩哔哩视频信息显示逻辑

- 调整哔哩哔哩视频信息构造顺序,先判断是否显示信息,再构造数据
- 优化简介和在线人数信息的显示逻辑,确保信息展示的一致性和准确性
- 移除冗余的代码段,提高代码的整洁性和可维护性
This commit is contained in:
zhiyu1998 2024-09-14 20:19:51 +08:00
parent eeb859845c
commit f4b20ba2bf

View File

@ -629,6 +629,10 @@ export class tools extends plugin {
const { title, desc, bvid, cid, pic } = videoInfo;
// 视频信息
const { view, danmaku, reply, favorite, coin, share, like } = videoInfo.stat;
// 格式化数据
let combineContent = "";
// 是否显示信息
if (this.biliDisplayInfo) {
// 构造一个可扩展的Map
const dataProcessMap = {
"点赞": like,
@ -639,22 +643,18 @@ export class tools extends plugin {
"弹幕数量": danmaku,
"评论": reply
};
// 过滤简介中的一些链接
const filteredDesc = await filterBiliDescLink(desc);
// 拼接在线人数
const onlineTotal = await this.biliOnlineTotal(bvid, cid);
// 格式化数据
let combineContent = "";
// 是否显示信息
if (this.biliDisplayInfo) {
combineContent += `\n${ formatBiliInfo(dataProcessMap) }`;
}
// 是否显示简介
if (this.biliDisplayIntro) {
// 过滤简介中的一些链接
const filteredDesc = await filterBiliDescLink(desc);
combineContent += `\n📝 简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`;
}
// 是否显示在线人数
if (this.biliDisplayOnline) {
// 拼接在线人数
const onlineTotal = await this.biliOnlineTotal(bvid, cid);
combineContent += `\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`;
}
let biliInfo = [`${ this.identifyPrefix } 识别:哔哩哔哩:${ title }`, combineContent]