diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Captube.iml b/.idea/Captube.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Captube.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..710d32f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b151ab --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c60c43e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..33e2c2f --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,158 @@ +# CapTube 架构文档 + +CapTube 是一个 Chrome / Firefox 浏览器扩展(MV2),为 YouTube 提供**双语字幕 + AI 翻译**能力。 +核心设计:**注入页面 hook 数据 + 后台代理翻译 + SVG 双语渲染**。 + +--- + +## 文件树与职责 + +``` +Captube/ +│ +├── 构建 / 配置层 +│ ├── package.json 依赖与脚本 (build / pack) +│ ├── webpack.config.js 5 入口打包,双浏览器输出 [name].min.js +│ ├── utils/ +│ │ ├── build.js 调 webpack 构建 chrome / firefox +│ │ └── pack.js 打包成 .zip 分发包 +│ └── .travis.yml CI +│ +├── 扩展元数据 +│ └── src/manifest.json MV2 清单:权限 / 入口 / 资源声明 +│ +└── src/ 源码 (约 1975 行) + │ + ├── ① 注入桥接层 + │ └── content.js [32] 沙箱脚本 → 注入 captube.js 到页面,传 extId/settings + │ + ├── ② 页面核心引擎 (运行在 YouTube 真实上下文) + │ └── captube.js [1069] 重心:字幕发现 / 管理 / SVG 渲染 + │ ├ CaptionBase / NativeCaption / YouTubeTransCaption + │ │ / TencentTransCaption / DeepLTransCaption ← 字幕数据层 (状态机) + │ ├ CaptionManager / CapTubeManager ← 管理调度层 + │ └ RendererLoop ← rAF + SVG 渲染层 + │ + ├── ③ 后台中枢 + │ └── background.js [232] 设置存储 + 翻译请求路由 + 图标状态 + │ ├ 依赖 → tencent-helper.js [161] 分块 / HMAC-SHA1 签名 / 限速 调腾讯 API + │ ├ 依赖 → deepl-helper.js [97] 分块 / 限速 调 DeepL API + │ └ 依赖 → default-settings.js[44] 默认配置常量 + │ + ├── ④ UI 层 + │ ├── popup.html / popup.css + │ ├── popup.js [227] 快捷设置面板 (布局 / 字号 / API key) + │ ├── options.html + │ └── options.js [77] Pro 设置 (直接编辑 JSON) + │ + ├── ⑤ 公共工具 + │ ├── utils.js [27] RateLimiter 限速器 (被两个 helper 用) + │ └── console.js [9] 日志加 "CapTube>" 前缀 + │ + └── 资源 + ├── icon16/32/128.png 常态彩色图标 + ├── icon*-gray.png 不适配页面 (灰) + └── icon*-half.png 检测到 YouTube (半灰) +``` + +--- + +## 模块依赖与通信关系 + +``` + chrome.storage.local + ▲ + │ 读写设置 + ┌───────┴────────┐ + UPDATE_SETTINGS ┌────▶│ background.js │◀────┐ TRANSLATION_REQUEST + DISPATCH_SETTINGS│ │ (后台中枢) │ │ TRANSLATION_RESULT + │ └───┬────────┬───┘ │ SET_ICON + 内部 port │ │import │import │ 外部 port (onConnectExternal) + ┌───────────┴──┐ ┌───▼───┐ ┌──▼─────┐ │ + │ popup.js │ │tencent│ │deepl │ │ + │ options.js │ │-helper│ │-helper │ │ + └──────────────┘ └───┬───┘ └──┬─────┘ │ + (UI 设置) └─┬──────┘ │ + import │ utils.js │ + (RateLimiter 限速器) │ + │ + ═══════════ 扩展沙箱 │ 页面真实上下文 ════════│═══════ + │ + ┌──────────────┐ 注入 ┌────────────────┴───┐ + │ content.js │────────▶│ captube.js │ + │ (注入桥) │