TransLite 是一款轻量级网页翻译 Userscript,专为移动端(尤其是 Via 浏览器)设计。它利用大语言模型的翻译能力,配合 MyMemory 公开 API 作为兜底,实现高质量网页翻译。
本仓库包含两个版本:
| 版本 | 文件 | 运行环境 | 说明 |
|---|---|---|---|
| Via 专版 v26.8.27 | TransLite26.1.6.js |
Via 浏览器内置脚本管理器(亦可装于 Tampermonkey) | 在原作者 v26.1.6 基础上全面增强:流式输出、翻译角色、快捷键、GitHub 模式、429 限流保护、源码配置区等 |
| Tampermonkey 增强版 TransLite+ | TransLite+/TransLite+.js |
Tampermonkey(Chrome / Edge / Firefox) | 基于 GM 存储实现跨网页配置保存,含完整设置面板;详见 TransLite+/README.md |
| 功能 | 说明 |
|---|---|
| LLM 批量翻译 | 将页面段落编号后合并为单条消息发送,大幅减少 API 调用次数 |
| 流式输出 | 默认 stream:true,首 token 到达即开始累积,进度条实时显示已接收字符(可在设置关闭) |
| 翻译角色预设 | 内置 9 个系统提示词角色(默认/科技编程/医学论文/机械论文/新闻媒体/法律/小说/游戏/论文通用),可自定义多个角色并持久化 |
| MyMemory 兜底 | LLM 调用失败时自动切换至 MyMemory API(429 停止/用户取消场景除外) |
| 多翻译引擎 | 支持 LLM / Baidu / MyMemory / 自定义 API 四种引擎 |
| 快捷键 | 可录制的翻译快捷键(默认 Ctrl+Alt+T,电脑/外接键盘均有效);可选「双击页面空白区域翻译」 |
| GitHub 自动模式 | 访问 github.com / *.github.io 等域名自动切换:保留代码/命令/路径/链接与文件名不翻译,仅翻译正文 |
| 429 限流保护 | 429 重试次数可自定义(默认 3);多次失败弹窗提示并立即停止当前翻译任务 |
| 翻译可取消 | 翻译进行中再次按快捷键或点击 🌐 即可取消,进度与计时随之清除 |
| 三指长按翻译 | 三指长按 500ms 触发翻译,防抖触控状态机,兼容 Android 多点触控 |
| 可拖动按钮 | 设置按钮(⚙️)与悬浮翻译按钮(🌐)可拖动吸附,位置持久化;两者均可开关 |
| 自动翻译 | 检测页面语言,非目标语言时自动翻译 |
| 双语模式 | 支持「直接替换」和「双语对照」两种翻译模式 |
| 源码配置区 | 所有设置均可直接在脚本源码中修改(改 true/false、改数字即生效),解决 Via 跨域存储问题 |
TransLite26.1.6.js 的完整代码,粘贴保存;或直接导入文件TransLite+/TransLite+.js 粘贴为「新脚本」保存,或拖入扩展导入Via 浏览器无法跨域存储配置,因此 Via 专版把所有设置都放在脚本源码中,直接修改即可生效:
TransLite26.1.6.jsDEFAULT_CONFIG,约第 40~95 行):全部 50+ 个可调字段集中于此,直接改 true/false、改数字、改字符串apiBase / apiKey / model)建议同时写死在 HARDCODED 区(约第 20~40 行)——切换域名时作为全局兜底var HARDCODED = {
apiBase: '', // ← 在此填写 API Base URL(OpenAI 兼容,含 /v1)
apiKey: '', // ← 在此填写你的 API Key
model: '' // ← 在此填写模型名称
};
💡 配置优先级:设置面板保存的内容 > 源码配置区 > 默认值。 若之前在设置面板保存过配置,面板值会覆盖源码。让源码改动立即生效:打开设置面板 → 点「🔄 恢复默认配置(改用源码配置区)」。
Ctrl+Alt+T 触发翻译;可在设置面板「快捷键」区点「🎬 录制」自定义页面上三指同时长按约 500ms 即触发翻译(分轴 50px 容错,支持手指分批到达)。
在设置面板开启「自动翻译非目标语言页面」,脚本自动检测并翻译。
将页面段落编号后合并为单条消息,LLM 按 [N] 编号逐行返回,脚本按编号映射回 DOM 节点:
输入:[0] Hello world / [1] This is a test.
输出:[0] 你好世界 / [1] 这是一个测试。
Via 版用页面 XMLHttpRequest 的 onprogress 增量解析 SSE:按事件块(\n\n)切分、兼容 CRLF;请求完成时若增量内容为空,会对完整响应做全量解析兜底(覆盖 onprogress 未触发的情况),仍为空则打印响应前 300 字符诊断日志。服务端不支持流式(400/415/501)自动回退非流式重发。
isGitHubDomain() 匹配 github.com / *.github.io / *.github.dev;激活时切换专门提示词(保留代码/命令/路径/链接),采集文本时跳过 <pre>/<code> 代码块与文件/目录名单元格(.react-directory-filename-cell,兼容旧版 table.files td.content)。
rateLimitRetries(默认 3)控制 429/5xx 重试;耗尽后弹窗「429 多并发限流」并置停止标志,全部批次循环检查后立即停止(清除计时与进度)。翻译进行中再次触发入口即置 cancelRequested 取消任务。
用 Touch.identifier 追踪手指、分轴 50px 移动阈值、touchcancel 只清理触控点不中断脚本(参考沉浸式翻译)。
Via 无 GM_setValue,localStorage 受同源限制。方案:全部设置集中在 DEFAULT_CONFIG 源码配置区(改源码即生效);HARDCODED 存跨域高频字段(apiBase/apiKey/model)作为所有域名全局默认值。合并优先级:UI 保存 > 源码配置区(HARDCODED+DEFAULT) > 默认值。
内置 9 个系统提示词角色,均遵循 [N] 编号 + {{targetLang}} 格式;自定义角色存 localStorage(当前域名),可随时保存/删除。
| 问题 | 状态 | 说明 |
|---|---|---|
| Via 中设置无法跨网页保存 | 🔴 受限于平台 | Via 无 GM_setValue,localStorage 同源限制。通过「源码配置区 + HARDCODED」解决:改源码即全局生效 |
| 自定义角色仅当前域名持久化 | 🟡 受限于平台 | Via localStorage 同源限制;跨域需在源码配置区 systemPrompt 中直接配置 |
部分网页 touchstart 被拦截 |
🟡 部分兼容 | 个别动态网页阻止事件冒泡导致三指长按无响应 |
| 华为设备三指截屏冲突 | 🟡 部分兼容 | 系统级三指截屏会发 touchcancel,脚本已容错,仍建议关闭系统手势 |
v26.8.27 起采用年份.月份.日期格式:
| 字段 | 含义 | 示例 |
|---|---|---|
| 年份 | 两位年份(2026 → 26) | 26 |
| 月份 | 发布月份(1~12) | 8 |
| 日期 | 发布日 | 27 |
历史版本 26.1.6 沿用原「年份.迭代数.月份」规则(2026 年,第 1 代,6 月)。
当前版本:26.8.27(Via 专版)
@license 声明26.1.6(2026-06-05)— 首次发布(原作者 rewwoxv.)
Object.assign 合并顺序错误HARDCODED 全局配置区,解决 Via 跨域存储本项目以 AGPL-3.0(GNU Affero General Public License v3.0) 开源,原作者 rewwoxv.。
TransLite26.1.6.js 头部已声明 @license AGPL-3.0-or-later,文件末尾注释块内嵌完整许可证文本;详见项目根目录 LICENSE(或 AGPL-3.0 全文)。
最后更新:2026-08-27
TransLite is a lightweight webpage translation Userscript designed for mobile browsers (especially Via Browser). It leverages Large Language Model translation, with the MyMemory public API as a fallback, for high-quality webpage translation.
This repository contains two versions:
| Version | File | Runtime | Description |
|---|---|---|---|
| Via Edition v26.8.27 | TransLite26.1.6.js |
Via built-in script manager (also works with Tampermonkey) | Fully enhanced on top of the original v26.1.6: streaming, translation roles, shortcuts, GitHub mode, 429 protection, source-config area |
| Tampermonkey Edition TransLite+ | TransLite+/TransLite+.js |
Tampermonkey (Chrome / Edge / Firefox) | Cross-site config saving via GM storage with a full settings panel; see TransLite+/README.md |
This is an enhanced fork: original author (rewwoxv.) is credited, maintained by GeorgeChou17, open-sourced under AGPL-3.0.
| Feature | Description |
|---|---|
| LLM Batch Translation | Number page paragraphs and merge into a single message, drastically reducing API calls |
| Streaming Output | stream:true by default — the first token arrives immediately, progress shows received chars live (toggleable) |
| Translation Role Presets | 9 built-in system-prompt roles (Default / Tech / Medical / Mechanical / News / Legal / Novel / Game / Academic), plus user-defined roles persisted locally |
| MyMemory Fallback | Automatically switches to MyMemory when LLM calls fail (except on 429-stop / user-cancel) |
| Multiple Engines | LLM / Baidu / MyMemory / Custom API |
| Shortcuts | Recordable translation shortcut (default Ctrl+Alt+T, works with desktop/external keyboards); optional double-click blank area to translate |
| GitHub Auto Mode | On github.com / *.github.io etc.: keeps code/commands/paths/links and file names untranslated, translates only prose |
| 429 Rate-Limit Protection | Customizable 429 retry count (default 3); pops up and stops the current task after repeated failures |
| Cancelable Translation | Press the shortcut or tap 🌐 again while translating to cancel |
| Three-Finger Long-Press | 500ms long-press triggers translation; debounced touch state machine, Android multi-touch compatible |
| Draggable Buttons | ⚙️ settings and 🌐 floating buttons drag & snap, position persists; both toggleable |
| Auto Translation | Detects page language and auto-translates non-target-language pages |
| Bilingual Mode | "Direct replace" and "bilingual side-by-side" modes |
| Source Config Area | All settings are directly editable in the script source (flip true/false, change numbers), solving Via cross-origin storage |
TransLite26.1.6.js, paste and save; or import the fileTransLite+/TransLite+.js and save as a "New Script", or drag the file into the extensionVia cannot persist config across origins, so the Via Edition puts every setting in the script source — edit and it takes effect:
TransLite26.1.6.js with a text editorDEFAULT_CONFIG, roughly lines 40–95): all 50+ tunable fields live here — flip true/false, change numbers/strings directlyapiBase / apiKey / model) should also be hardcoded in the HARDCODED block (roughly lines 20–40) as the cross-origin global fallbackvar HARDCODED = {
apiBase: '', // ← Your API Base URL (OpenAI-compatible, include /v1)
apiKey: '', // ← Your API Key
model: '' // ← Your model name
};
💡 Priority: settings saved via the panel > source config area > defaults. If you saved config via the panel before, panel values override the source. To make source changes take effect immediately: open the settings panel → tap "🔄 Restore defaults (use source config area)".
Ctrl+Alt+T triggers translation; customize via "🎬 Record" in the Shortcuts sectionLong-press with three fingers for ~500ms to trigger translation (50px per-axis tolerance, sequential finger arrival supported).
Enable "Auto-translate pages not in target language" in the settings panel.
[N]-prefixed lines, mapped back to DOM nodes.XMLHttpRequest onprogress to incrementally parse SSE by event blocks (\n\n, CRLF-tolerant); if the incremental content is empty on load, the full response is re-parsed as SSE, then as full JSON; if still empty, the first 300 chars are logged as a diagnostic. Servers rejecting streaming (400/415/501) fall back to a non-streaming retry.isGitHubDomain() matches github.com / *.github.io / *.github.dev; when active, a dedicated prompt keeps code/commands/paths/links untranslated, and <pre>/<code> blocks plus file/directory name cells (.react-directory-filename-cell, legacy table.files td.content) are skipped during collection.rateLimitRetries (default 3) governs 429/5xx retries; on exhaustion a "429 rate limited" alert stops the task (all batch loops check the stop flag, timers and progress cleared). Triggering translation again while running sets cancelRequested.Touch.identifier, 50px per-axis movement tolerance, touchcancel only clears points (inspired by Immersive Translate).GM_setValue and localStorage is same-origin — all settings live in the DEFAULT_CONFIG source config area; HARDCODED holds cross-origin high-frequency fields. Merge priority: UI-saved > source config area > defaults.[N] + {{targetLang}} format; custom roles persist in localStorage (current domain).| Issue | Status | Description |
|---|---|---|
| No cross-page config saving in Via | 🔴 Platform limit | Via has no GM_setValue; localStorage is same-origin. Solved via the source config area + HARDCODED — edit source and it works globally |
| Custom roles persist only on the current domain | 🟡 Platform limit | Via localStorage same-origin; configure systemPrompt in the source config area for cross-domain use |
touchstart blocked on some pages |
🟡 Partial | Some dynamic pages block event bubbling, breaking three-finger long-press |
| Huawei three-finger screenshot conflict | 🟡 Partial | System screenshot sends touchcancel; fault-tolerant handling exists, but disabling the system gesture is advised |
From v26.8.27 the project uses the Year.Month.Day format (e.g. 26 = 2026, 8 = August, 27 = day). The legacy 26.1.6 used "Year.Iteration.Month" (2026, generation 1, June).
Current version: 26.8.27 (Via Edition)
@license declaration26.1.6 (2026-06-05) — Initial release (original author rewwoxv.)
Object.assign merge order errorHARDCODED global config block for Via cross-origin storageThis project is open-sourced under AGPL-3.0 (GNU Affero General Public License v3.0), original author rewwoxv..
TransLite26.1.6.js declares @license AGPL-3.0-or-later in its header and embeds the full license text in a trailing comment block; see the LICENSE file in the project root (or AGPL-3.0 full text).
Last updated: 2026-08-27