mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-07-03 13:41:22 +08:00
feat(extension): 侧边栏与 popup 用视频标题替代链接显示
在任务未完成的早期阶段(PENDING/DOWNLOADING 等),侧边栏和 popup 只能回退到 videoUrl,用户看到的是一长串链接,难以辨认。 改动: - TaskRecord 新增 title 字段,用于存储浏览器标签页标题 - popup 创建任务时保存 tab.title - background startTask 接收可选 title,右键菜单和悬浮按钮均传入 - 显示优先级:result.audio_meta.title > title > videoUrl - 所有平台(Bilibili / YouTube / Douyin / Kuaishou)均受益 测试: - pnpm typecheck 通过 - pnpm build 通过 - 在 B 站、YouTube 视频页提交任务,侧边栏和 popup 均显示标题而非链接
This commit is contained in:
@@ -56,7 +56,7 @@ async function upsertTask(record: TaskRecord) {
|
||||
|
||||
// ---------- 启动任务 ----------
|
||||
|
||||
async function startTask(url: string): Promise<{ ok: boolean, taskId?: string, error?: string }> {
|
||||
async function startTask(url: string, title?: string): Promise<{ ok: boolean, taskId?: string, error?: string }> {
|
||||
const platform = detectPlatform(url)
|
||||
if (!platform)
|
||||
return { ok: false, error: '当前链接不是支持的视频平台' }
|
||||
@@ -107,6 +107,7 @@ async function startTask(url: string): Promise<{ ok: boolean, taskId?: string, e
|
||||
message: '已提交',
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
title,
|
||||
})
|
||||
return { ok: true, taskId: body.data.task_id }
|
||||
}
|
||||
@@ -129,8 +130,8 @@ async function openSidePanelInTab(tabId?: number) {
|
||||
|
||||
// ---------- 消息桥 ----------
|
||||
|
||||
onMessage<{ url: string }, 'bilinote-start'>('bilinote-start', async ({ data, sender }) => {
|
||||
const result = await startTask(data.url)
|
||||
onMessage<{ url: string; title?: string }, 'bilinote-start'>('bilinote-start', async ({ data, sender }) => {
|
||||
const result = await startTask(data.url, data.title)
|
||||
// 成功就把侧边栏拉起来给用户看进度
|
||||
if (result.ok)
|
||||
await openSidePanelInTab(sender?.tabId)
|
||||
@@ -168,7 +169,7 @@ browser.contextMenus?.onClicked.addListener(async (info, tab) => {
|
||||
const url = info.linkUrl || tab?.url
|
||||
if (!url)
|
||||
return
|
||||
const result = await startTask(url)
|
||||
const result = await startTask(url, tab?.title)
|
||||
if (result.ok)
|
||||
await openSidePanelInTab(tab?.id)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user