TransLite(Via 专版)
TransLite
🇨🇳 中文
📖 简介
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 跨域存储问题 |
📦 安装
Via 专版(推荐 Via 浏览器)
- 打开 Via 浏览器 → 设置 → 脚本(或「简易脚本」)→ 新建脚本
- 全选复制
TransLite26.1.6.js的完整代码,粘贴保存;或直接导入文件 - 刷新任意网页,右下角出现 🌐 悬浮翻译按钮
Tampermonkey 增强版(TransLite+)
- 安装 Tampermonkey
- 全选复制
TransLite+/TransLite+.js粘贴为「新脚本」保存,或拖入扩展导入 - 详见 TransLite+/README.md
🔧 使用方法(Via 专版)
一、源码配置区(重要)
Via 浏览器无法跨域存储配置,因此 Via 专版把所有设置都放在脚本源码中,直接修改即可生效:
- 用文本编辑器打开
TransLite26.1.6.js - 找到文件头部的 「★★★ 源码配置区」(
DEFAULT_CONFIG,约第 40~95 行):全部 50+ 个可调字段集中于此,直接改true/false、改数字、改字符串 - 高频字段(
apiBase/apiKey/model)建议同时写死在HARDCODED区(约第 20~40 行)——切换域名时作为全局兜底
var HARDCODED = {
apiBase: '', // ← 在此填写 API Base URL(OpenAI 兼容,含 /v1)
apiKey: '', // ← 在此填写你的 API Key
model: '' // ← 在此填写模型名称
};
💡 配置优先级:设置面板保存的内容 > 源码配置区 > 默认值。 若之前在设置面板保存过配置,面板值会覆盖源码。让源码改动立即生效:打开设置面板 → 点「🔄 恢复默认配置(改用源码配置区)」。
二、使用设置面板
- 点击页面上的 ⚙️ 设置按钮(可拖动,默认吸附右侧)
- 在面板中切换引擎、选择翻译角色、调整流式/超时/429/快捷键等
- 点击「保存设置」
三、快捷键与取消翻译
- 默认
Ctrl+Alt+T触发翻译;可在设置面板「快捷键」区点「🎬 录制」自定义 - 翻译进行中再次按快捷键或点击 🌐 即取消当前任务
四、三指长按翻译
页面上三指同时长按约 500ms 即触发翻译(分轴 50px 容错,支持手指分批到达)。
五、自动翻译
在设置面板开启「自动翻译非目标语言页面」,脚本自动检测并翻译。
🔬 技术实现简介
1. LLM 批量翻译(编号合并)
将页面段落编号后合并为单条消息,LLM 按 [N] 编号逐行返回,脚本按编号映射回 DOM 节点:
输入:[0] Hello world / [1] This is a test.
输出:[0] 你好世界 / [1] 这是一个测试。
2. 流式输出(XHR SSE)
Via 版用页面 XMLHttpRequest 的 onprogress 增量解析 SSE:按事件块(\n\n)切分、兼容 CRLF;请求完成时若增量内容为空,会对完整响应做全量解析兜底(覆盖 onprogress 未触发的情况),仍为空则打印响应前 300 字符诊断日志。服务端不支持流式(400/415/501)自动回退非流式重发。
3. GitHub 自动模式
isGitHubDomain() 匹配 github.com / *.github.io / *.github.dev;激活时切换专门提示词(保留代码/命令/路径/链接),采集文本时跳过 <pre>/<code> 代码块与文件/目录名单元格(.react-directory-filename-cell,兼容旧版 table.files td.content)。
4. 429 限流保护与翻译取消
rateLimitRetries(默认 3)控制 429/5xx 重试;耗尽后弹窗「429 多并发限流」并置停止标志,全部批次循环检查后立即停止(清除计时与进度)。翻译进行中再次触发入口即置 cancelRequested 取消任务。
5. 三指长按防抖触控状态机
用 Touch.identifier 追踪手指、分轴 50px 移动阈值、touchcancel 只清理触控点不中断脚本(参考沉浸式翻译)。
6. 源码配置区 + HARDCODED 全局兜底
Via 无 GM_setValue,localStorage 受同源限制。方案:全部设置集中在 DEFAULT_CONFIG 源码配置区(改源码即生效);HARDCODED 存跨域高频字段(apiBase/apiKey/model)作为所有域名全局默认值。合并优先级:UI 保存 > 源码配置区(HARDCODED+DEFAULT) > 默认值。
7. 翻译角色预设
内置 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 专版)
📝 更新日志
26.8.27(2026-08-27)— Via 专版(功能与 TransLite+ 对齐)
- ✨ 流式输出:XHR SSE 增量解析,首 token 秒回,进度条实时显示已接收字符(默认开启,可关闭)
- ✨ 翻译角色预设:内置 9 个角色 + 自定义多角色(localStorage 持久化),设置面板下拉选择
- ✨ 快捷键:可录制组合键(默认 Ctrl+Alt+T)+ 双击页面空白翻译
- ✨ GitHub 自动模式:代码块/命令/文件名不翻译,仅翻译正文
- ✨ 429 限流保护:重试次数可配(默认 3),多次失败弹窗提示并立即停止任务
- ✨ 翻译可取消:翻译中再次按快捷键/点 🌐 即取消
- ✨ 源码配置区:所有设置可在脚本源码直接修改(改 true/false、数字即生效),配「恢复默认配置」按钮
- 🔧 ⚙️/🌐 悬浮按钮双开关(⚙️ 默认显示,Via 无菜单命令需保证入口)
- 🔧 测试连接按钮、URL 自动纠偏、超时/错误提示带主机名
- 🔧 移除内置默认服务商(无七牛云/小红书点点默认),API 三项由用户自填;旧配置一次性迁移清除
- 🔧 调优:默认超时 120s、单批 4000 字符、max_tokens 4096
- 📄 内嵌 AGPL-3.0 许可证全文 +
@license声明
点击展开 26.1.6 原版历史
26.1.6(2026-06-05)— 首次发布(原作者 rewwoxv.)
- 🔧 重构三指长按翻译为防抖触控状态机
- ✅ 修复
Object.assign合并顺序错误 - ✅ 新增
HARDCODED全局配置区,解决 Via 跨域存储 - ✨ LLM 批量翻译、MyMemory 兜底、可拖动设置按钮、三指长按、自动翻译、双语模式
📄 开源协议
本项目以 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 全文)。
🙏 致谢
- 沉浸式翻译 — 触控事件队列与 GitHub 模式设计参考
- MyMemory Translation API — 免费翻译兜底服务
- Via 浏览器 — 轻量级 Android 浏览器
💬 反馈 & 贡献
- 问题反馈 / 代码贡献:GitHub 仓库提交 Issue 或 PR
最后更新:2026-08-27
🇬🇧 English
📖 Introduction
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.
✨ Features
| 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 |
📦 Installation
Via Edition (Via Browser recommended)
- Via Browser → Settings → Scripts → New Script
- Copy the full code of
TransLite26.1.6.js, paste and save; or import the file - Refresh any webpage — the 🌐 floating button appears bottom-right
Tampermonkey Edition (TransLite+)
- Install Tampermonkey
- Copy
TransLite+/TransLite+.jsand save as a "New Script", or drag the file into the extension - See TransLite+/README.md
🔧 Usage (Via Edition)
1. Source Config Area (Important)
Via cannot persist config across origins, so the Via Edition puts every setting in the script source — edit and it takes effect:
- Open
TransLite26.1.6.jswith a text editor - Locate the "★★★ 源码配置区" (
DEFAULT_CONFIG, roughly lines 40–95): all 50+ tunable fields live here — fliptrue/false, change numbers/strings directly - High-frequency fields (
apiBase/apiKey/model) should also be hardcoded in theHARDCODEDblock (roughly lines 20–40) as the cross-origin global fallback
var 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)".
2. Settings Panel
- Tap the ⚙️ settings button (draggable, snaps to the right by default)
- Switch engines, pick a translation role, adjust streaming / timeout / 429 / shortcuts
- Tap "Save Settings"
3. Shortcuts & Cancellation
- Default
Ctrl+Alt+Ttriggers translation; customize via "🎬 Record" in the Shortcuts section - While translating, press the shortcut or tap 🌐 again to cancel
4. Three-Finger Long-Press
Long-press with three fingers for ~500ms to trigger translation (50px per-axis tolerance, sequential finger arrival supported).
5. Auto Translation
Enable "Auto-translate pages not in target language" in the settings panel.
🔬 Technical Implementation
- LLM batch translation (numbered merge): paragraphs are numbered and merged into one message; the LLM replies with
[N]-prefixed lines, mapped back to DOM nodes. - Streaming (XHR SSE): Via Edition uses the page's
XMLHttpRequestonprogressto 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. - GitHub auto mode:
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, legacytable.files td.content) are skipped during collection. - 429 protection & cancellation:
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 setscancelRequested. - Three-finger debounced touch state machine: tracks fingers via
Touch.identifier, 50px per-axis movement tolerance,touchcancelonly clears points (inspired by Immersive Translate). - Source config area + HARDCODED fallback: Via has no
GM_setValueandlocalStorageis same-origin — all settings live in theDEFAULT_CONFIGsource config area;HARDCODEDholds cross-origin high-frequency fields. Merge priority:UI-saved > source config area > defaults. - Translation role presets: 9 built-in roles following the
[N]+{{targetLang}}format; custom roles persist inlocalStorage(current domain).
⚠️ Known Issues
| 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 |
📝 Versioning
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)
📝 Changelog
26.8.27 (2026-08-27) — Via Edition (feature-aligned with TransLite+)
- ✨ Streaming output (XHR SSE, first token immediate, live received-char progress; on by default)
- ✨ Translation role presets (9 built-in + custom roles persisted in localStorage)
- ✨ Recordable shortcuts (default Ctrl+Alt+T) + double-click blank area to translate
- ✨ GitHub auto mode (code/commands/file names kept, prose translated)
- ✨ 429 rate-limit protection (configurable retries, alert + stop after exhaustion)
- ✨ Cancelable translation (trigger again while translating)
- ✨ Source config area (all settings editable in the script source) + "Restore defaults" button
- 🔧 ⚙️/🌐 floating button toggles (⚙️ visible by default — Via has no menu commands)
- 🔧 Test-connection button, URL auto-fix, hostname in timeout/error messages
- 🔧 Removed built-in default providers (no Qiniu/Diandian defaults); API triple filled by the user; one-time migration clears legacy values
- 🔧 Tuning: default timeout 120s, batch cap 4000 chars, max_tokens 4096
- 📄 AGPL-3.0 license text embedded +
@licensedeclaration
Click to expand 26.1.6 original history
26.1.6 (2026-06-05) — Initial release (original author rewwoxv.)
- 🔧 Refactored three-finger long-press into a debounced touch state machine
- ✅ Fixed
Object.assignmerge order error - ✅ Added the
HARDCODEDglobal config block for Via cross-origin storage - ✨ LLM batch translation, MyMemory fallback, draggable settings button, three-finger long-press, auto translation, bilingual mode
📄 License
This project is open-sourced under AGPL-3.0 (GNU Affero General Public License v3.0), original author rewwoxv..
- ✅ Free to use, modify, and distribute
- ✅ May be used for personal and commercial purposes
- ⚠️ If modified and provided as a network service, the modified version must be open-sourced
- ⚠️ Original author attribution must be retained
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).
🙏 Acknowledgements
- Immersive Translate — touch event queue & GitHub mode design reference
- MyMemory Translation API — free translation fallback service
- Via Browser — lightweight Android browser
💬 Feedback & Contributions
- Issues / PRs via the GitHub repository.
Last updated: 2026-08-27