mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-11 18:10:06 +08:00
- contentScripts: 仅在支持的视频平台(B 站 / YouTube / 抖音 / 快手)注入悬浮 BiliNote 按钮,点击通过 webext-bridge 发 'bilinote-start' 给 background - background: 处理 bilinote-start 与右键菜单点击;调 /api/generate_note;写 chrome.storage;自动打开侧边栏。logic/storage 是 Vue 反应式版本,service worker 不能 import,因此把常量抽到 logic/constants.ts - contextMenus: onInstalled 时注册"用 BiliNote 总结此视频",限定 4 个支持平台域名 - 浏览器 Cookie 同步:options 页加按钮,按平台读 chrome.cookies.getAll,序列化为 'name=value; ...' 后 POST 给后端 /api/update_downloader_cookie。chrome.cookies + contextMenus 权限补到 manifest - 侧边栏(P3 首版):从 storage 读最近任务并轮询,复用 TaskProgress + MarkdownView。markmap 思维导图与 RAG 问答推到后续 - 修 P1 endpoint 拼错的 bug:/api/get_models_by_provider 实际是 /api/model_enable,404 来自这里 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { setDownloaderCookie } from './api'
|
||
import type { Platform } from './types'
|
||
|
||
// 后端期望的 cookie 字符串格式:name=value; name=value; ...
|
||
// 见 backend/app/downloaders/bilibili_downloader.py 的 split("; ")
|
||
const COOKIE_DOMAINS: Record<Exclude<Platform, 'local'>, string> = {
|
||
bilibili: '.bilibili.com',
|
||
youtube: '.youtube.com',
|
||
douyin: '.douyin.com',
|
||
kuaishou: '.kuaishou.com',
|
||
}
|
||
|
||
export const SUPPORTED_COOKIE_PLATFORMS: Array<Exclude<Platform, 'local'>> = [
|
||
'bilibili',
|
||
'douyin',
|
||
'kuaishou',
|
||
'youtube',
|
||
]
|
||
|
||
export async function readBrowserCookies(platform: Exclude<Platform, 'local'>): Promise<string> {
|
||
const domain = COOKIE_DOMAINS[platform]
|
||
const list = await browser.cookies.getAll({ domain })
|
||
return list.map(c => `${c.name}=${c.value}`).join('; ')
|
||
}
|
||
|
||
export async function syncCookieToBackend(platform: Exclude<Platform, 'local'>): Promise<{ ok: boolean, count: number, error?: string }> {
|
||
try {
|
||
const cookieStr = await readBrowserCookies(platform)
|
||
if (!cookieStr)
|
||
return { ok: false, count: 0, error: '当前浏览器没有该域名的 cookie,先在浏览器内登录目标站点' }
|
||
const count = cookieStr.split('; ').length
|
||
await setDownloaderCookie(platform, cookieStr)
|
||
return { ok: true, count }
|
||
}
|
||
catch (e) {
|
||
return { ok: false, count: 0, error: (e as Error).message }
|
||
}
|
||
}
|