TransLite+:Tampermonkey 网页翻译脚本,跨网页保存配置,支持 LLM/百度/MyMemory 引擎、流式输出、角色预设、快捷键与 GitHub 模式。TransLite+ is a Tampermonkey translation userscript with cross-site config saving, LLM/Baidu/MyMemory engines, streaming, role presets, shortcuts, GitHub mode.
TransLite+ 是 TransLite 的 Tampermonkey 移植版。它保留了原版基于大语言模型的批量网页翻译能力,并用 Tampermonkey 的 GM_setValue / GM_getValue 存储 API 彻底解决了原版在 Via 浏览器中“配置无法跨网页保存”的核心痛点。
核心改进:配置现在可以真正跨网页、跨域名持久化保存。
| 功能 | 说明 |
|---|---|
| 跨网页配置保存(核心) | 基于 Tampermonkey 的 GM 存储,配置在所有网页之间共享,切换域名不丢失 |
| 全局 / 单站 双作用域 | 可设为「全局」(所有网页共用)或「仅当前站点」(按域名隔离并覆盖全局) |
| LLM 批量翻译 | 将页面段落编号后合并为单条消息发送,大幅减少 API 调用次数 |
| MyMemory 兜底 | LLM 调用失败时自动切换至 MyMemory API,保证基础翻译可用性 |
| 多翻译引擎 | 支持 LLM / Baidu / MyMemory / 自定义 API 四种引擎 |
| 翻译角色(预设) | 内置 9 个系统提示词角色(默认通用 / 科技编程 / 医学论文 / 机械论文 / 新闻媒体 / 法律译者 / 小说译者 / 游戏译者 / 论文通用),可自定义多个角色并跨网页持久化 |
| 四指手势翻译 | 在触摸屏上四指同时按下并保持即可触发翻译(兼容 Android 多点触控) |
| 可拖动按钮 | 设置按钮(⚙️)与悬浮翻译按钮(🌐)均可自由拖动并自动吸附屏幕边缘,位置持久化;两个按钮都可在设置中开关(🌐 默认显示,⚙️ 默认隐藏) |
| 双语模式 | 支持「直接替换」和「双语对照」两种翻译模式 |
| 菜单命令 | 通过 Tampermonkey 脚本菜单即可打开设置、翻译页面、恢复原文 |
| CORS 无忧 | 网络请求优先走 GM_xmlhttpRequest,绕过浏览器同源限制 |
| GitHub 自动模式 | 访问 github.com / *.github.io 等域名使用 AI 翻译时,自动切换 GitHub 模式:保留代码/命令/路径/链接不翻译,跳过文件名单元格,仅翻译正文(参考沉浸式翻译原理) |
| 自定义快捷键 | 可在设置中录制翻译快捷键(默认 Ctrl+Alt+T),电脑键盘 / 移动端外接键盘即时触发;可选「双击页面空白区域翻译」 |
| 流式输出 | LLM 请求默认走 stream 流式,首 token 到达即开始累积并实时显示已接收字符数,慢模型不再干等整批生成完(可在设置中关闭) |
| 429 限流保护 | 429 重试次数可自定义(默认 3);多次失败自动弹窗提示「429 多并发限流」并立即停止当前翻译任务(清除计时与进度) |
TransLite+.js,全选复制,在 Tampermonkey 中「添加新脚本」并粘贴保存;或直接将 .js 文件拖入 Tampermonkey 扩展以导入TransLite+ 的 LLM 引擎为 OpenAI 兼容接口,不内置任何默认服务商——API 地址、Key、模型名称均由你自己填写。首次使用前请配置:
/v1,如 https://你的域名/v1)Simplified Chinese💡 可参考的免费模型(需自行填写对应服务的地址与 Key):
- 小红书点点(dots.ai) — 模型
dots3-note-prev:完全免费、无额度限制,控制台 https://dots.ai/platform。- 智谱清言官方(BigModel / open.bigmodel.cn) — 模型
glm-4.7-flash:官方免费模型,需在 https://open.bigmodel.cn 申请 API Key。旧版本内置的默认服务商(七牛云等)已全部移除,配置中如残留旧值会被自动清空,请自行填写你的服务。
💡 跨网页保存已默认开启:保存后,你在任意网页修改的配置都会写入 Tampermonkey 的
GM存储,下次访问任何网页(含不同域名)都会自动读取,无需重新配置。
在设置面板顶部的「配置作用域」中:
GM 键下,对全部网页生效。这是「跨网页保存」的标准模式。配置合并优先级:UI 保存的配置 > GM 持久化配置 > DEFAULT_CONFIG
🌐 悬浮翻译按钮默认开启(右下角),点击即可直接翻译当前页面;按钮可拖动,位置会被持久化。如需关闭,在设置面板「界面与快捷操作」中取消「悬浮翻译按钮」开关。
在设置面板「LLM 配置」中可选用「翻译角色」:
[N] 编号与 {{targetLang}} 占位符,指示模型输出 ONLY [N] 行。在设置面板「快捷键」区可配置:
Ctrl+Alt+T,默认开启):点击「🎬 录制」→ 按下你想要的组合键(如 Ctrl+Shift+L)→ 保存设置即可生效。电脑键盘与移动端外接(蓝牙)键盘均有效;在输入框/文本框内输入时不会误触发。💡 取消翻译:翻译进行中,再次按下翻译快捷键或再次点击 🌐 悬浮按钮(菜单命令/手势/双击同理)即可取消当前任务,进度条与计时随之清除。已翻译的段落会保留,未翻译的段落保持原文。
原版 TransLite 在 Via 浏览器中受困于:普通脚本无法使用 GM_setValue,而 localStorage 受同源策略限制,切换域名后配置全部丢失,只能靠硬编码 HARDCODED 解决。
TransLite+ 运行在 Tampermonkey 环境下,原生支持 GM_setValue / GM_getValue:
getEffectiveConfig() 依次合并 DEFAULT_CONFIG → 全局 GM 配置 →(若作用域为单站)站点级 GM 配置saveConfig() 根据当前作用域写入对应的 GM 键translite_cfg_global(全局)、translite_cfg_site_<hostname>(按域名隔离)这实现了真正的「跨网页保存」——无论在哪个域名下配置,只要作用域为全局,其他网页都会自动继承。
传统翻译脚本每段单独调用 API,效率低且容易触发速率限制。本脚本采用编号合并策略:
输入(合并为单条消息):
[0] Hello world
[1] This is a test.
[2] Good morning!
LLM 输出(按编号对应):
[0] 你好世界
[1] 这是一个测试。
[2] 早上好!
脚本按编号将翻译结果映射回对应 DOM 节点,实现批量翻译。
当 LLM API 调用失败(网络错误、配额耗尽、超时等)时,脚本自动切换至 MyMemory Translation API 作为兜底,保证基本翻译功能始终可用。
所有翻译请求优先使用 GM_xmlhttpRequest(Tampermonkey 提供的跨域请求能力),可绕过浏览器同源策略限制;仅在 GM_xmlhttpRequest 不可用时回退到原生 fetch。配合限流退避重试(429/5xx 指数退避),提升弱网稳定性。
参考「沉浸式翻译」的事件队列设计,兼容 Android 多点触控:
touch 点时启动计时,达到延迟阈值触发翻译touchmove / touchend 会清空计时,避免误触与滑动干扰document 与 document.documentElement 双目标注册,提升兼容性参考「沉浸式翻译」对 GitHub 的处理方式:在 github.com / gist.github.com / *.github.io / *.github.dev 等域名下使用 AI 翻译时,自动切换 GitHub 模式,具体行为:
DEFAULT_GITHUB_PROMPT,明确指示模型只翻译正文(README / Issue / PR / 评论等),不翻译代码、终端命令、文件路径、URL、包名、API 名与编程标识符,并保留 Markdown / HTML 结构与格式。<pre> 与 <code> 列入跳过集合(GITHUB_SKIP),避免把代码块送进翻译,效果与沉浸式翻译一致。.react-directory-filename-cell,旧版 table.files td.content),文件名不翻译;commit message、日期等正文照常翻译。githubActive 运行标志在 doTranslate() 中依据「开启 githubAuto 且当前为 GitHub 域名且为 AI 引擎」自动置位,并弹出提示;也可在设置面板「GitHub 自动模式」开关关闭。针对慢模型/冷启动导致「整批生成完才返回、极易 60s 超时」的问题,LLM 请求默认开启 stream: true(可在设置中关闭):
GM_xmlhttpRequest 的 onprogress 逐行解析 data: {json} / data: [DONE],choices[0].delta.content 实时累积——首 token 到达即开始,进度条实时显示「已接收 N 字符」。split('\n') 以换行结尾时末位是空段/半行,必须留到下次数据到达再处理(游标越过后新数据会落空),已按此实现并自检。stream 参数)。XMLHttpRequest.timeout 为空闲超时,持续有数据到达不会误触发超时。| 问题 | 状态 | 说明 |
|---|---|---|
| 依赖 Tampermonkey 环境 | 🟡 设计约束 | 跨网页保存依赖 GM_setValue/GM_getValue,需在 Tampermonkey / 类似管理器(Violentmonkey 等)中运行;直接以普通脚本运行将退回默认值。 |
部分网页 touchstart 事件被拦截 |
🟡 部分兼容 | 某些动态网页会阻止事件冒泡,导致四指手势无响应。脚本已在 document 与 documentElement 双目标注册以缓解。 |
| 华为设备三指/四指截屏手势冲突 | 🟡 部分兼容 | 系统级截屏手势会发出 touchcancel,脚本已做容错,但仍有概率被系统截获。建议暂时关闭系统多指截屏手势。 |
本项目的版本号格式为:年份.迭代数.月份
| 字段 | 含义 | 示例 |
|---|---|---|
| 年份 | 两位年份(2026 → 26) | 26 |
| 迭代数 | 大版本迭代,架构级变更时 +1 | 2 |
| 月份 | 发布月份(1~12) | 8 |
当前版本:26.2.8(2026年,第2代,8月;Tampermonkey 移植版)
由 TransLite v26.1.6(Via 脚本)移植而来,主要改进:
GM_setValue/GM_getValue,彻底解决原版配置无法跨域名持久化的问题GM_xmlhttpRequest,绕过同源限制GM 存储HARDCODED 硬编码配置区(不再需要,配置全部走 GM 存储)TransLite+.js 文件末尾注释块,并在脚本头部声明 @license/chat/completions 则不再重复拼接;超时 / 网络错误提示附带主机名便于排查dots3-note-prev 预览版)首次生成可能超过 60s,调优后大多一次通过Ctrl+Alt+T,支持电脑键盘/移动端外接键盘)与可选的「双击页面空白区域翻译」,均可在设置面板配置[N] 编号 + {{targetLang}} 格式stream:true,SSE 增量解析、首 token 秒回、进度条实时显示已接收字符;服务端不支持流式时自动回退非流式;可在设置中关闭\n\n)解析,兼容 CRLF 与增量分块;onload 时若增量内容为空,会对完整响应文本做全量 SSE 解析再兜底完整 JSON,仍为空则打印响应前 300 字符诊断日志.react-directory-filename-cell,旧版 table.files td.content),commit message、日期等正文照常翻译本项目以 AGPL-3.0(GNU Affero General Public License v3.0) 开源。
详见项目根目录的 LICENSE 文件(或 AGPL-3.0 全文)。脚本文件 TransLite+.js 头部的 @license 元数据与文件末尾注释块内已内嵌完整 AGPL-3.0 许可证文本。
最后更新:2026-08-26
TransLite+ is a Tampermonkey translation userscript with cross-site config saving, LLM/Baidu/MyMemory engines, streaming, role presets, shortcuts, and GitHub mode. TransLite+:Tampermonkey 网页翻译脚本,跨网页保存配置,支持 LLM/百度/MyMemory 引擎、流式输出、角色预设、快捷键与 GitHub 模式。
TransLite+ is the Tampermonkey port of TransLite. It retains the original LLM-based batch webpage translation capabilities, and uses Tampermonkey's GM_setValue / GM_getValue storage API to fully resolve the core pain point of the original Via-browser version: "configurations cannot persist across webpages".
Key improvement: configurations can now truly persist across webpages and across domains.
| Feature | Description |
|---|---|
| Cross-webpage config saving (core) | Based on Tampermonkey GM storage; configurations are shared across all webpages and survive domain switches |
| Global / Per-site scope | Set as "global" (shared across all webpages) or "current site only" (isolated per domain and overrides global) |
| LLM Batch Translation | Number paragraphs on the page and merge them into a single message, drastically reducing the number of API calls |
| MyMemory Fallback | Automatically switches to the MyMemory API when LLM calls fail, ensuring basic translation availability |
| Multiple Translation Engines | Supports four engines: LLM / Baidu / MyMemory / Custom API |
| Translation Roles (presets) | 9 built-in system-prompt roles (Default / Tech & Programming / Medical Papers / Mechanical Papers / News Media / Legal / Novel / Game / Academic), plus unlimited user-defined roles persisted across webpages |
| Four-Finger Gesture Translation | Trigger translation by pressing four fingers simultaneously on a touchscreen (compatible with Android multi-touch) |
| Draggable Buttons | Both the settings button (⚙️) and the floating translation button (🌐) can be dragged and auto-snap to the screen edge; positions persist. Both can be toggled in settings (🌐 shown by default, ⚙️ hidden by default) |
| Bilingual Mode | Supports both "direct replacement" and "bilingual side-by-side" translation modes |
| Menu Commands | Open settings, translate the page, or restore original text directly from the Tampermonkey script menu |
| CORS-Free | Network requests prefer GM_xmlhttpRequest, bypassing browser same-origin restrictions |
| GitHub Auto Mode | When using AI translation on github.com / *.github.io etc., automatically switches to GitHub mode: keeps code/commands/paths/links untranslated, skips file-name cells, and translates only the prose (inspired by Immersive Translate) |
| Custom Shortcuts | Record your own translation shortcut in settings (default Ctrl+Alt+T) — instant trigger on desktop keyboards / mobile external keyboards; optional "double-click blank page area to translate" for mouse users |
| Streaming Output | LLM requests use stream by default — the first token arrives immediately and received-char counts show live, so slow models no longer force you to wait for the whole batch (toggleable in settings) |
| 429 Rate-Limit Protection | Customizable 429 retry count (default 3); after repeated failures it pops up "429 rate limited, please retry later" and immediately stops the current translation task (clears the timer and progress) |
TransLite+.js, select all and copy, then "Add New Script" in Tampermonkey and paste to save; or simply drag the .js file into the Tampermonkey extension to import itThe LLM engine of TransLite+ is OpenAI-compatible and ships with no built-in provider — the API base URL, Key, and model name are all filled in by you. Configure before first use:
/v1, e.g. https://your-domain/v1)Simplified Chinese💡 Reference free models (fill in the corresponding service's URL and Key yourself):
- Xiaohongshu Diandian (dots.ai) — model
dots3-note-prev: completely free with no quota limit, console at https://dots.ai/platform.- Zhipu AI official (BigModel / open.bigmodel.cn) — model
glm-4.7-flash: official free model; apply for an API Key at https://open.bigmodel.cn.Built-in providers from older versions (Qiniu Cloud, etc.) have been fully removed; any legacy values left in your saved config are auto-cleared — fill in your own service instead.
💡 Cross-webpage saving is enabled by default: after saving, the configuration you modify on any webpage is written to Tampermonkey's
GMstorage and automatically read on every subsequent visit — including different domains — with no need to reconfigure.
In the "Configuration Scope" section at the top of the settings panel:
GM key and apply to all webpages. This is the standard mode for "cross-webpage saving".Configuration merge priority: UI-saved config > GM-persisted config > DEFAULT_CONFIG
The 🌐 floating translation button is enabled by default (bottom-right); tap it to translate the current page directly. The button is draggable and its position is persisted. To disable it, turn off "Floating translation button" in the settings panel under "Interface & Shortcuts".
In the "LLM Configuration" section of the settings panel, use "Translation Role":
[N] numbering and the {{targetLang}} placeholder, and instruct the model to output ONLY [N] lines.In the "Shortcuts" section of the settings panel:
Ctrl+Alt+T, enabled by default): click "🎬 Record" → press the combination you want (e.g. Ctrl+Shift+L) → save settings. Works with desktop keyboards and mobile external (Bluetooth) keyboards; typing in input fields will never accidentally trigger it.💡 Cancel translation: while a translation is running, press the shortcut or tap the 🌐 floating button again (menu command / gesture / double-click work the same) to cancel the current task — the progress bar and timer are cleared immediately. Already-translated paragraphs stay, remaining ones keep the original text.
The original TransLite was stuck on Via Browser because ordinary scripts could not use GM_setValue, while localStorage was limited by the same-origin policy — all config was lost after switching domains, only solvable via hardcoding HARDCODED.
TransLite+ runs under Tampermonkey and natively supports GM_setValue / GM_getValue:
getEffectiveConfig() merges DEFAULT_CONFIG → global GM config → (if scope is per-site) site-level GM configsaveConfig() writes to the corresponding GM key based on the current scopetranslite_cfg_global (global), translite_cfg_site_<hostname> (isolated per domain)This achieves true "cross-webpage saving": regardless of which domain you configure on, as long as the scope is global, other webpages automatically inherit it.
Traditional translation scripts call the API separately for each paragraph, which is inefficient and prone to rate limiting. This script adopts a numbered merging strategy:
Input (merged into a single message):
[0] Hello world
[1] This is a test.
[2] Good morning!
LLM Output (mapped by number):
[0] 你好世界
[1] 这是一个测试。
[2] 早上好!
The script maps translation results back to corresponding DOM nodes by number, enabling batch translation.
When the LLM API call fails (network error, quota exhausted, timeout, etc.), the script automatically switches to the MyMemory Translation API as a fallback, ensuring basic translation functionality remains available at all times.
All translation requests prefer GM_xmlhttpRequest (Tampermonkey's cross-origin request capability) to bypass the browser same-origin policy; it falls back to native fetch only when GM_xmlhttpRequest is unavailable. Combined with rate-limit backoff retries (429/5xx exponential backoff), it improves stability on weak networks.
Inspired by the event-queue design of "Immersive Translate", compatible with Android multi-touch:
touch points are detected simultaneously, a timer starts; translation fires once the delay threshold is reachedtouchmove / touchend clear the timer, avoiding accidental triggers and swipe interferencedocument and document.documentElement targets to improve compatibilityFollowing how "Immersive Translate" handles GitHub: when using AI translation on github.com / gist.github.com / *.github.io / *.github.dev, the script automatically switches to GitHub mode:
DEFAULT_GITHUB_PROMPT, instructing the model to translate only the prose (README / Issues / PRs / comments) and NOT translate code, terminal commands, file paths, URLs, package names, API names, or programming identifiers, while preserving Markdown / HTML structure and formatting.<pre> and <code> are automatically added to the skip set (GITHUB_SKIP), so code blocks are never sent to the translator — consistent with Immersive Translate's behavior..react-directory-filename-cell, legacy table.files td.content), so file names are never translated while commit messages, dates, etc. are still translated as normal.githubActive runtime flag is set in doTranslate() based on "githubAuto enabled + current domain is GitHub + AI engine", and a toast is shown; it can also be toggled off via the "GitHub Auto Mode" switch in the settings panel.To address slow/cold-start models where "the whole batch must finish generating before anything returns, easily hitting the 60s timeout", LLM requests now send stream: true by default (toggleable in settings):
data: {json} / data: [DONE] lines via GM_xmlhttpRequest onprogress, accumulating choices[0].delta.content in real time — the first token arrives immediately, and the progress bar shows "received N chars" live.split('\n') leaves a trailing empty segment (or half-line); it must be deferred until the next data arrives (otherwise the cursor skips past newly arriving data). Implemented and self-checked accordingly.stream parameter).XMLHttpRequest.timeout is an idle timeout, so continuous data arrival never falsely triggers a timeout.| Issue | Status | Description |
|---|---|---|
| Depends on Tampermonkey environment | 🟡 By design | Cross-webpage saving relies on GM_setValue/GM_getValue, so it must run inside Tampermonkey / similar managers (Violentmonkey etc.); running as a plain script reverts to defaults. |
touchstart event blocked on some webpages |
🟡 Partially compatible | Some dynamic webpages block event bubbling, causing the four-finger gesture to be unresponsive. The script registers on both document and documentElement to mitigate this. |
| Huawei device three/four-finger screenshot gesture conflict | 🟡 Partially compatible | System-level screenshot gestures send touchcancel; the script has fault-tolerant handling, but interception by the system is still possible. It is recommended to temporarily disable the system multi-finger screenshot gesture. |
The version number format for this project is: Year.Iteration.Month
| Field | Meaning | Example |
|---|---|---|
| Year | Two-digit year (2026 → 26) | 26 |
| Iteration | Major version iteration; +1 on architectural changes | 2 |
| Month | Release month (1–12) | 8 |
Current version: 26.2.8 (Year 2026, Generation 2, Month 8; Tampermonkey port)
Ported from TransLite v26.1.6 (Via script), with the following main improvements:
GM_setValue/GM_getValue, fully resolving the original's inability to persist config across domainsGM_xmlhttpRequest to bypass same-origin restrictionsGM storageHARDCODED config block (no longer needed; all config goes through GM storage)TransLite+.js trailing comment block, with an @license declaration in the script header/chat/completions, it is no longer appended twice; timeout / network errors now include the hostname for easier diagnosisdots3-note-prev preview) can take over 60s on the first generation — after tuning, most requests pass on the first attemptCtrl+Alt+T, works with desktop keyboards / mobile external keyboards) and an optional "double-click blank page area to translate" — both configurable in the settings panel[N]-numbered + {{targetLang}} formatstream:true with incremental SSE parsing — first token arrives immediately, and the progress bar shows received-char counts live; auto-falls back to non-streaming when unsupported; toggleable in settings\n\n) parsing, compatible with CRLF and incremental chunks; if incremental content is empty on onload, it re-parses the full response text as SSE and then falls back to full JSON; if still empty, it logs the first 300 chars of the response as a diagnostic.react-directory-filename-cell, legacy table.files td.content), while commit messages, dates, etc. are still translated as normalThis project is open-sourced under AGPL-3.0 (GNU Affero General Public License v3.0).
See the LICENSE file in the project root (or AGPL-3.0 full text). The TransLite+.js script header carries an @license declaration and the full AGPL-3.0 text is embedded in a trailing comment block within the script file itself.
Last updated: 2026-08-26