TransLite+
TransLite+
🇨🇳 中文
📖 简介
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 多并发限流」并立即停止当前翻译任务(清除计时与进度) |
📦 安装
- 安装浏览器扩展 Tampermonkey(Chrome / Edge / Firefox 等主流浏览器均支持)
- 打开
TransLite+.js,全选复制,在 Tampermonkey 中「添加新脚本」并粘贴保存;或直接将.js文件拖入 Tampermonkey 扩展以导入 - 刷新任意网页,默认显示 🌐 悬浮翻译按钮;⚙️ 设置按钮默认隐藏(打开设置可走 Tampermonkey 菜单「⚙️ TransLite+ 设置」,或在设置面板中开启悬浮设置按钮)
🔧 使用方法
一、配置 LLM 服务(仅首次)
TransLite+ 的 LLM 引擎为 OpenAI 兼容接口,不内置任何默认服务商——API 地址、Key、模型名称均由你自己填写。首次使用前请配置:
- 点击页面右下角 ⚙️ 设置按钮,或在 Tampermonkey 菜单中选择「TransLite+ 设置」
- 在「LLM 配置」中填写(三项均必填):
- API 地址:填写你自己的 OpenAI 兼容接口地址(含
/v1,如https://你的域名/v1) - API Key:填写你所用服务的 API Key
- 模型名称:填写你所用服务的模型名称
- 目标语言:默认
Simplified Chinese
- API 地址:填写你自己的 OpenAI 兼容接口地址(含
- 点击「保存设置」
💡 可参考的免费模型(需自行填写对应服务的地址与 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
三、使用设置面板
- 点击 ⚙️ 设置按钮(可拖动,默认吸附右下角)
- 切换翻译引擎、修改 Prompt、调整界面参数等
- 点击「保存设置」即时生效
四、四指手势翻译(触摸屏)
- 在页面上 同时用四根手指按下 并保持约 300ms
- 翻译自动触发(手势延迟可在设置中调整)
五、悬浮翻译按钮(默认开启)
🌐 悬浮翻译按钮默认开启(右下角),点击即可直接翻译当前页面;按钮可拖动,位置会被持久化。如需关闭,在设置面板「界面与快捷操作」中取消「悬浮翻译按钮」开关。
六、翻译角色(系统提示词预设)
在设置面板「LLM 配置」中可选用「翻译角色」:
- 内置 9 个预设:默认通用、科技编程、医学论文、机械论文、新闻媒体、法律译者、小说译者、游戏译者、论文通用。选择预设会自动填充系统提示词。
- 自定义角色:修改提示词后点击「💾 保存为新角色」,输入名称即可保存;自定义角色显示为「自定义:名称」,可随时删除,跨网页持久化(存于 GM 存储)。
- 格式要求:自定义角色请按「默认通用」预设的格式修改——保持
[N]编号与{{targetLang}}占位符,指示模型输出 ONLY[N]行。
七、快捷键(迅速触发翻译)
在设置面板「快捷键」区可配置:
- 键盘快捷键(默认
Ctrl+Alt+T,默认开启):点击「🎬 录制」→ 按下你想要的组合键(如Ctrl+Shift+L)→ 保存设置即可生效。电脑键盘与移动端外接(蓝牙)键盘均有效;在输入框/文本框内输入时不会误触发。 - 双击页面空白区域翻译(默认关闭):开启后,在页面空白处(非链接/按钮/输入框,且未选中文字)双击即可触发翻译,适合鼠标操作。
💡 取消翻译:翻译进行中,再次按下翻译快捷键或再次点击 🌐 悬浮按钮(菜单命令/手势/双击同理)即可取消当前任务,进度条与计时随之清除。已翻译的段落会保留,未翻译的段落保持原文。
🔬 技术实现简介
1. 跨网页配置保存(核心机制)
原版 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>(按域名隔离)
这实现了真正的「跨网页保存」——无论在哪个域名下配置,只要作用域为全局,其他网页都会自动继承。
2. LLM 批量翻译(编号合并)
传统翻译脚本每段单独调用 API,效率低且容易触发速率限制。本脚本采用编号合并策略:
输入(合并为单条消息):
[0] Hello world
[1] This is a test.
[2] Good morning!
LLM 输出(按编号对应):
[0] 你好世界
[1] 这是一个测试。
[2] 早上好!
脚本按编号将翻译结果映射回对应 DOM 节点,实现批量翻译。
3. MyMemory 兜底机制
当 LLM API 调用失败(网络错误、配额耗尽、超时等)时,脚本自动切换至 MyMemory Translation API 作为兜底,保证基本翻译功能始终可用。
4. CORS 无忧网络层
所有翻译请求优先使用 GM_xmlhttpRequest(Tampermonkey 提供的跨域请求能力),可绕过浏览器同源策略限制;仅在 GM_xmlhttpRequest 不可用时回退到原生 fetch。配合限流退避重试(429/5xx 指数退避),提升弱网稳定性。
5. 四指手势触控状态机
参考「沉浸式翻译」的事件队列设计,兼容 Android 多点触控:
- 同时检测到 4 个
touch点时启动计时,达到延迟阈值触发翻译 touchmove/touchend会清空计时,避免误触与滑动干扰- 在
document与document.documentElement双目标注册,提升兼容性
6. GitHub 自动模式(参考沉浸式翻译原理)
参考「沉浸式翻译」对 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 自动模式」开关关闭。
7. 流式输出(LLM)
针对慢模型/冷启动导致「整批生成完才返回、极易 60s 超时」的问题,LLM 请求默认开启 stream: true(可在设置中关闭):
- 增量解析 SSE:通过
GM_xmlhttpRequest的onprogress逐行解析data: {json}/data: [DONE],choices[0].delta.content实时累积——首 token 到达即开始,进度条实时显示「已接收 N 字符」。 - 增量解析防坑:
split('\n')以换行结尾时末位是空段/半行,必须留到下次数据到达再处理(游标越过后新数据会落空),已按此实现并自检。 - 自动回退:服务端不支持流式(400/415/501)时自动改发非流式一次;流式内容为空时回退解析完整 JSON(服务端可能忽略
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 移植版)
📝 更新日志
26.2.8(2026-08-26)— Tampermonkey 移植版
由 TransLite v26.1.6(Via 脚本)移植而来,主要改进:
- ✨ 跨网页配置保存:改用 Tampermonkey
GM_setValue/GM_getValue,彻底解决原版配置无法跨域名持久化的问题 - ✨ 全局 / 单站双作用域:新增配置作用域切换,支持按域名隔离配置
- ✨ CORS 无忧网络层:优先
GM_xmlhttpRequest,绕过同源限制 - ✨ Tampermonkey 菜单命令:支持从脚本菜单直接打开设置、翻译页面、恢复原文
- ✨ 可拖动 + 位置持久化:设置按钮与悬浮翻译按钮位置写入
GM存储 - 🔧 四指手势触发(替代原版三指,适配更多触摸屏)
- 🔧 移除
HARDCODED硬编码配置区(不再需要,配置全部走GM存储) - ✨ GitHub 自动模式:参考沉浸式翻译原理,访问 github.com / *.github.io 等域名使用 AI 翻译时自动切换,保留代码/命令/链接不翻译,仅译正文(可在设置面板开关)
- ✨ 协议内嵌:完整 AGPL-3.0 许可证文本已写入
TransLite+.js文件末尾注释块,并在脚本头部声明@license - 🔧 移除全部内置默认服务商:删除七牛云 / 小红书点点 / OpenAI 兜底等一切内置 API 地址与模型名,LLM 的 API 地址、Key、模型名称一律由用户自行填写;配置中残留的旧服务商值会自动清空
- 🔧 配置自动清理(一次性迁移):仅当存储配置版本落后时,将等于历史内置默认值(qnaigc / openai 地址、glm-4.5-air-free 模型)的字段清空一次并打上版本标记;用户实际使用的服务(如 askdiandian + dots3-note-prev)不会被触碰,清理永不重复执行
- 🔧 修复配置保存被清空:修复旧清理逻辑每次加载都把用户已填写的 API 地址 / 模型名抹掉的问题——现在 api / key / 模型名称与开关、超时等设置一样可持久保存
- 🔧 401/403 明确报错:API Key 无效或未填写时给出清晰指引(检查 LLM 配置中的地址 / Key / 模型名称)
- 🔧 新增「测试连接」按钮:设置面板内一键发送最小请求,15 秒内显示 HTTP 状态 / 耗时 / 主机名,快速定位网络或鉴权问题
- 🔧 地址自动纠偏:API 地址若已含
/chat/completions则不再重复拼接;超时 / 网络错误提示附带主机名便于排查 - 🔧 请求超时可配置:新增「请求超时(秒)」项,弱网或大文档翻译时可调大(默认 120s)
- 🔧 超时与批量调优:默认请求超时 60s→120s;单批字符上限 8000→4000;最大 Token 上限 8192→4096(旧配置自动降级)。慢模型(如
dots3-note-prev预览版)首次生成可能超过 60s,调优后大多一次通过 - 🔧 进度条显示等待秒数:翻译中实时显示已等待时长,避免误以为卡死
- ✨ 自定义快捷键:新增可录制的翻译快捷键(默认
Ctrl+Alt+T,支持电脑键盘/移动端外接键盘)与可选的「双击页面空白区域翻译」,均可在设置面板配置 - ✨ 翻译角色(系统提示词预设):内置 9 个角色(默认通用 / 科技编程 / 医学论文 / 机械论文 / 新闻媒体 / 法律译者 / 小说译者 / 游戏译者 / 论文通用),支持自定义多个角色(名称+提示词)并跨网页持久化,均遵循「默认通用」的
[N]编号 +{{targetLang}}格式 - 🔧 悬浮翻译按钮默认开启:🌐 默认显示(可在设置中关闭)
- 🔧 ⚙️ 设置按钮默认隐藏:设置入口走 Tampermonkey 菜单「⚙️ TransLite+ 设置」;🌐 与 ⚙️ 两个悬浮按钮均可在设置面板「界面与快捷操作」中自行开关
- ✨ 流式输出(默认开启):LLM 请求默认
stream:true,SSE 增量解析、首 token 秒回、进度条实时显示已接收字符;服务端不支持流式时自动回退非流式;可在设置中关闭 - 🔧 流式解析健壮性:改为事件块(
\n\n)解析,兼容 CRLF 与增量分块;onload时若增量内容为空,会对完整响应文本做全量 SSE 解析再兜底完整 JSON,仍为空则打印响应前 300 字符诊断日志 - 🔧 429 限流保护:429 重试次数可自定义(默认 3,设置面板可改);多次重试失败自动弹窗「429 多并发限流,请稍候重试」并立即停止当前翻译任务(清除计时与进度),不再无限降级重试
- 🔧 翻译可取消:翻译进行中再次按快捷键 / 点击 🌐 悬浮按钮(菜单命令、手势、双击同理)即取消当前任务,进度与计时清除,已译段落保留、其余保持原文
- 🔧 GitHub 模式跳过文件名单元格:文件/目录名不翻译(
.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 许可证文本。
🙏 致谢
- TransLite(原版) — 本移植版的功能蓝本
- 沉浸式翻译 — 多指触控事件队列设计参考
- MyMemory Translation API — 免费翻译兜底服务
- Tampermonkey — 脚本运行与管理环境
💬 反馈 & 贡献
- 反馈:在仓库 Issue 区留言,或直接联系作者
- 贡献:Fork 本仓库,提交 PR
最后更新:2026-08-26
🇬🇧 English
📖 Introduction
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.
✨ Features
| 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) |
📦 Installation
- Install the Tampermonkey browser extension (available for Chrome / Edge / Firefox and other major browsers)
- Open
TransLite+.js, select all and copy, then "Add New Script" in Tampermonkey and paste to save; or simply drag the.jsfile into the Tampermonkey extension to import it - Refresh any webpage — the 🌐 floating translation button is shown by default; the ⚙️ settings button is hidden by default (open settings via the Tampermonkey menu "⚙️ TransLite+ Settings", or enable the floating settings button in the settings panel)
🔧 Usage
1. Configure Your LLM Service (first time only)
The 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:
- Click the ⚙️ settings button at the bottom-right of the page, or choose "TransLite+ Settings" from the Tampermonkey menu
- In the "LLM Configuration" section, fill in (all three are required):
- API Base URL: enter your own OpenAI-compatible endpoint (include
/v1, e.g.https://your-domain/v1) - API Key: enter the API Key of your service
- Model name: enter the model name of your service
- Target language: default
Simplified Chinese
- API Base URL: enter your own OpenAI-compatible endpoint (include
- Click "Save Settings"
💡 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.
2. Choose a Configuration Scope
In the "Configuration Scope" section at the top of the settings panel:
- Global (shared across all webpages) — configurations are stored under a single
GMkey and apply to all webpages. This is the standard mode for "cross-webpage saving". - Current site only — configurations are isolated per current domain and apply only to that site, overriding the global config. Useful when a specific site needs special settings.
Configuration merge priority: UI-saved config > GM-persisted config > DEFAULT_CONFIG
3. Using the Settings Panel
- Tap the ⚙️ settings button (draggable, snaps to the bottom-right by default)
- Switch translation engines, modify prompts, adjust UI parameters, etc.
- Tap "Save Settings" to apply immediately
4. Four-Finger Gesture Translation (touchscreen)
- Press four fingers simultaneously on the page and hold for about 300ms
- Translation triggers automatically (gesture delay is adjustable in settings)
5. Floating Translation Button (enabled by default)
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".
6. Translation Roles (system prompt presets)
In the "LLM Configuration" section of the settings panel, use "Translation Role":
- 9 built-in presets: Default General, Tech & Programming, Medical Papers, Mechanical Papers, News Media, Legal Translator, Novel Translator, Game Translator, Academic Papers. Selecting a preset auto-fills the system prompt.
- Custom roles: modify the prompt and click "💾 Save as new role", then enter a name to save; custom roles appear as "Custom: " and can be deleted anytime — persisted across webpages (stored via GM).
- Format requirement: follow the "Default General" preset format when customizing — keep the
[N]numbering and the{{targetLang}}placeholder, and instruct the model to output ONLY[N]lines.
7. Shortcuts (quickly trigger translation)
In the "Shortcuts" section of the settings panel:
- Keyboard shortcut (default
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. - Double-click blank page area to translate (off by default): once enabled, double-clicking on blank page areas (not links/buttons/inputs, and when no text is selected) triggers translation — great for mouse users.
💡 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.
🔬 Technical Implementation
1. Cross-Webpage Configuration Saving (core mechanism)
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:
- Read:
getEffectiveConfig()mergesDEFAULT_CONFIG→ globalGMconfig → (if scope is per-site) site-levelGMconfig - Write:
saveConfig()writes to the correspondingGMkey based on the current scope - Storage keys:
translite_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.
2. LLM Batch Translation (Numbered Merging)
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.
3. MyMemory Fallback Mechanism
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.
4. CORS-Free Network Layer
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.
5. Four-Finger Gesture Touch State Machine
Inspired by the event-queue design of "Immersive Translate", compatible with Android multi-touch:
- When 4
touchpoints are detected simultaneously, a timer starts; translation fires once the delay threshold is reached touchmove/touchendclear the timer, avoiding accidental triggers and swipe interference- Registered on both
documentanddocument.documentElementtargets to improve compatibility
6. GitHub Auto Mode (inspired by Immersive Translate)
Following 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:
- Dedicated prompt: uses
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. - Skip code blocks: while collecting translatable text,
<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. - Skip file-name cells: only the file/directory name cells are skipped (new UI
.react-directory-filename-cell, legacytable.files td.content), so file names are never translated while commit messages, dates, etc. are still translated as normal. - Auto-activation: the
githubActiveruntime flag is set indoTranslate()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.
7. Streaming Output (LLM)
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):
- Incremental SSE parsing: parses
data: {json}/data: [DONE]lines viaGM_xmlhttpRequestonprogress, accumulatingchoices[0].delta.contentin real time — the first token arrives immediately, and the progress bar shows "received N chars" live. - Incremental-parsing pitfall: when text ends with a newline,
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. - Auto fallback: if the server rejects streaming (400/415/501), it retries once without streaming; if the streamed content is empty, it falls back to parsing the full JSON (the server may have ignored the
streamparameter). - Timeout-friendly: the browser
XMLHttpRequest.timeoutis an idle timeout, so continuous data arrival never falsely triggers a timeout.
⚠️ Known Issues
| 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. |
📝 Version Numbering Rules
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)
📝 Changelog
26.2.8 (2026-08-26) — Tampermonkey Port
Ported from TransLite v26.1.6 (Via script), with the following main improvements:
- ✨ Cross-webpage config saving: switched to Tampermonkey
GM_setValue/GM_getValue, fully resolving the original's inability to persist config across domains - ✨ Global / per-site dual scope: added scope switching, supporting per-domain isolated configuration
- ✨ CORS-free network layer: prefers
GM_xmlhttpRequestto bypass same-origin restrictions - ✨ Tampermonkey menu commands: open settings, translate the page, or restore original text directly from the script menu
- ✨ Draggable + position persistence: settings and floating buttons' positions are written to
GMstorage - 🔧 Four-finger gesture trigger (replacing the original three-finger, adapting to more touchscreens)
- 🔧 Removed the
HARDCODEDconfig block (no longer needed; all config goes throughGMstorage) - ✨ GitHub Auto Mode: inspired by Immersive Translate; when using AI translation on github.com / *.github.io etc., it auto-switches to keep code/commands/links untranslated and translate only the prose (toggleable in settings)
- ✨ License embedded: the full AGPL-3.0 text is written into the
TransLite+.jstrailing comment block, with an@licensedeclaration in the script header - 🔧 Removed all built-in default providers: deleted every built-in API base URL and model name (Qiniu Cloud / Xiaohongshu Diandian / OpenAI fallback); the LLM API base URL, Key, and model name are now filled in solely by the user; legacy provider values in saved configs are auto-cleared
- 🔧 Config auto-cleanup (one-time migration): only when the stored config version lags behind, fields equal to historical built-in defaults (qnaigc / openai base URLs, glm-4.5-air-free model) are blanked once and a version marker is written; services the user actually uses (e.g. askdiandian + dots3-note-prev) are never touched, and cleanup never repeats
- 🔧 Fixed saved config being wiped: fixed the issue where the old cleanup logic erased the user's filled-in API base URL / model name on every page load — API / Key / model name now persist just like toggles and the timeout setting
- 🔧 Clear 401/403 errors: an invalid or missing API Key now shows a clear message telling the user to check the LLM config (base URL / Key / model name)
- 🔧 Added a "Test Connection" button: sends a minimal request from the settings panel and shows the HTTP status / elapsed time / hostname within 15 seconds, to quickly locate network or auth issues
- 🔧 Smart URL handling: if the API base URL already ends with
/chat/completions, it is no longer appended twice; timeout / network errors now include the hostname for easier diagnosis - 🔧 Configurable request timeout: added a "Request timeout (seconds)" option — raise it for weak networks or large-document translation (default 120s)
- 🔧 Timeout & batching tuning: default request timeout raised from 60s to 120s; per-batch char cap lowered from 8000 to 4000; max tokens cap lowered from 8192 to 4096 (legacy configs auto-downgraded). Slow models (e.g. the
dots3-note-prevpreview) can take over 60s on the first generation — after tuning, most requests pass on the first attempt - 🔧 Progress shows elapsed seconds: the in-progress indicator now displays how long it has been waiting, so it no longer looks frozen
- ✨ Custom shortcuts: added a recordable translation shortcut (default
Ctrl+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 - ✨ Translation Roles (system prompt presets): 9 built-in roles (Default / Tech & Programming / Medical Papers / Mechanical Papers / News Media / Legal / Novel / Game / Academic), plus unlimited user-defined roles (name + prompt) persisted across webpages — all following the "Default General"
[N]-numbered +{{targetLang}}format - 🔧 Floating translation button enabled by default: 🌐 now shows by default (can be turned off in settings)
- 🔧 ⚙️ Settings button hidden by default: settings are opened via the Tampermonkey menu "⚙️ TransLite+ Settings"; both floating buttons (🌐 and ⚙️) can be toggled in the settings panel under "Interface & Shortcuts"
- ✨ Streaming output (enabled by default): LLM requests now send
stream:truewith 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 - 🔧 Robust streaming parsing: switched to event-block (
\n\n) parsing, compatible with CRLF and incremental chunks; if incremental content is empty ononload, 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 - 🔧 429 rate-limit protection: customizable 429 retry count (default 3, adjustable in settings); after repeated failures it pops up "429 rate limited, please retry later" and immediately stops the current translation task (clears the timer and progress) instead of degrading into endless retries
- 🔧 Cancelable translation: while translating, press the shortcut or tap the 🌐 floating button again (menu command / gesture / double-click work the same) to cancel the current task — the progress and timer are cleared, already-translated paragraphs stay, and the rest keep the original text
- 🔧 GitHub mode skips file-name cells: file/directory names are not translated (
.react-directory-filename-cell, legacytable.files td.content), while commit messages, dates, etc. are still translated as normal
📄 License
This project is open-sourced under AGPL-3.0 (GNU Affero General Public License v3.0).
- ✅ Free to use, modify, and distribute
- ✅ May be used for personal and commercial purposes
- ⚠️ If modified and subsequently provided as a network service, the modified version must be open-sourced
- ⚠️ Original author attribution must be retained
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.
🙏 Acknowledgements
- TransLite (original) — the functional basis of this port
- Immersive Translate — Multi-finger touch event queue design reference
- MyMemory Translation API — Free translation fallback service
- Tampermonkey — Script runtime and management environment
💬 Feedback & Contributions
- Feedback: Leave a comment in the repository Issues section, or contact the author directly
- Contributions: Fork this repository and submit a PR
Last updated: 2026-08-26