TransLite v26.1.6
TransLite
🇨🇳 中文
📖 简介
TransLite 是一款轻量级 Userscript,专为在移动端浏览器(尤其是 Via 浏览器)上使用而设计。它利用大语言模型的翻译能力,配合 MyMemory 公开 API 作为兜底,实现高质量网页翻译。
核心设计哲学:在 Android WebView 的严苛环境下保持稳健运行。
✨ 功能特性
| 功能 | 说明 |
|---|---|
| LLM 批量翻译 | 将页面段落编号后合并为单条消息发送,大幅减少 API 调用次数 |
| MyMemory 兜底 | LLM 调用失败时自动切换至 MyMemory API,保证基础翻译可用性 |
| 多翻译引擎 | 支持 LLM / Baidu / MyMemory / 自定义 API 四种引擎 |
| 三指长按翻译 | 在屏幕上三指长按 500ms 即可触发翻译,采用防抖触控状态机,兼容 Android 多点触控 |
| 可拖动设置按钮 | 设置按钮可自由拖动并自动吸附屏幕边缘,不挡页面内容 |
| 自动翻译 | 检测页面语言,非目标语言时自动翻译 |
| 双语模式 | 支持「直接替换」和「双语对照」两种翻译模式 |
| HARDCODED 全局配置 | 在脚本内硬编码 API Key 等参数,解决 Via 浏览器无法跨域存储的问题 |
📦 安装
- 安装 Userscript 管理器(如 Tampermonkey 或 Via 浏览器内置脚本管理器)
- 点击安装链接:脚本猫 | GreasyFork(投稿中)
- 或直接复制
TransLite26.1.6.js的完整代码,粘贴至脚本管理器
🔧 使用方法
一、配置 API Key(重要)
由于 Via 浏览器的限制(见「已知问题」),推荐直接在脚本代码内硬编码配置:
- 用文本编辑器打开
TransLite26.1.6.js - 找到第 27~35 行的
HARDCODED配置区:
var HARDCODED = {
engine: 'llm', // 翻译引擎
apiBase: 'https://api.qnaigc.com/v1', // API Base URL
apiKey: '', // ← 在此填写你的 API Key
model: 'z-ai/glm-4.5-air-free', // 模型名称
targetLang: 'Simplified Chinese', // 目标语言
translateMode: 'replace' // 'replace' 或 'bilingual'
};
- 填写
apiKey后保存,重新安装/导入脚本即可
💡 提示:
HARDCODED中的值在所有网页上作为「全局默认值」生效。网页内设置面板的修改仅对当前域名生效,切换域名后回退至HARDCODED的值。
二、使用设置面板
- 点击页面上的设置按钮(可拖动,默认吸附右侧)
- 在面板中切换翻译引擎、修改 Prompt、调整界面参数等
- 点击「保存设置」
⚠️ 在 Via 浏览器中,通过面板保存的设置无法跨域名持久化(见已知问题)。建议在
HARDCODED中直接配置常用参数。
三、三指长按翻译
- 在页面上同时用三根手指长按(无需完全同时,脚本有分批容错)
- 保持按压约 500ms,翻译自动触发
- 手指滑动容忍阈值 50px,不用担心手抖误触
四、自动翻译
在设置面板中开启「自动翻译非目标语言页面」,脚本会自动检测页面语言并翻译。
🔬 技术实现简介
1. LLM 批量翻译(编号合并)
传统翻译脚本每段单独调用 API,效率低且容易触发速率限制。本脚本采用编号合并策略:
输入(合并为单条消息):
[0] Hello world
[1] This is a test.
[2] Good morning!
LLM 输出(按编号对应):
[0] 你好世界
[1] 这是一个测试。
[2] 早上好!
脚本按编号将翻译结果映射回对应 DOM 节点,实现批量翻译。
2. 三指长按防抖触控状态机
Android WebView 中 touch 事件极其脆弱(系统手势截获、touchcancel 频发、手指分批到达)。本脚本采用借鉴「沉浸式翻译」的事件队列设计:
- 使用
Touch.identifier追踪每根手指(而非数组索引) activePoints对象累积触控点,手指分批到达不影响判定- 分轴 50px 移动阈值,容忍光滑屏幕上的微小手抖
touchcancel事件只清理触控点,不强行中断脚本
3. HARDCODED 全局配置模式
Via 浏览器普通脚本无法使用 GM_setValue(无 Tampermonkey API),而 localStorage 受同源策略限制,切换域名后配置全部丢失。
解决方案:将核心参数直接硬编码在脚本头部 HARDCODED 对象中,作为所有域名的全局默认值。网页内设置面板保存的内容仅作为当前域名的独立覆写(Override)。
配置合并优先级:UI 保存的配置 > HARDCODED > DEFAULT_CONFIG
4. MyMemory 兜底机制
当 LLM API 调用失败(网络错误、配额耗尽、超时等)时,脚本自动切换至 MyMemory Translation API 作为兜底,保证基本翻译功能始终可用。
⚠️ 已知问题
| 问题 | 状态 | 说明 |
|---|---|---|
| Via 浏览器中设置无法跨网页保存 | 🔴 未修复 | Via 不支持 GM_setValue,localStorage 受同源策略限制。目前只能通过 HARDCODED 硬编码解决。欢迎 PR 提供更好的方案。 |
部分网页 touchstart 事件被拦截 |
🟡 部分兼容 | 某些动态网页(如百度首页)会阻止事件冒泡,导致三指长按无响应。可尝试修改 registerThreeFingerLongPress 的绑定目标为 document.documentElement 或 window。 |
| 华为荣耀设备三指截屏手势冲突 | 🟡 部分兼容 | 华为荣耀系统级三指截屏会发出 touchcancel,脚本已做容错处理,但仍有概率被系统截获。建议暂时关闭系统三指截屏手势。 |
📝 版本号规则
本项目的版本号格式为:年份.迭代数.月份
| 字段 | 含义 | 示例 |
|---|---|---|
| 年份 | 两位年份(2026 → 26) | 26 |
| 迭代数 | 大版本迭代,架构级变更时 +1 | 1 |
| 月份 | 发布月份(1~12) | 6 |
当前版本:26.1.6(2026年,第1代,6月)
📝 更新日志
26.1.6(2026-06-05)— 首次发布
本次发布基于开发阶段 v12.0~v12.6 的全部功能合并,主要改进:
- 🔧 重构三指长按翻译逻辑为「防抖触控状态机」(
touchStatus统一状态管理) - 🔧 移动判定从欧几里得距离改为分轴 50px 独立判定,更容忍自然手抖
- ✅ 修复
Object.assign合并顺序错误导致 UI 设置被HARDCODED覆盖 - ✅ 修复三指分批到达时旧版误清
threeFingerMap导致无法触发的问题 - ✅ 新增
HARDCODED全局配置区,解决 Via 浏览器跨域存储问题 - ✨ 完整功能:LLM 批量翻译、MyMemory 兜底、可拖动设置按钮、三指长按翻译、自动翻译、双语模式
点击展开开发阶段历史(v12.x)
v12.6(2026-06-05)
- 🔧 重构三指长按翻译逻辑为防抖触控状态机
v12.5(2026-06-05)
- ✅ 修复
Object.assign合并顺序错误 - ✅ 修复
cancelThreeFingerTimer误清 Map 的问题
v12.4(2026-06-05)
- ✅ 新增
HARDCODED全局配置区 - ✅ 使用
Touch.identifier重写三指长按追踪逻辑
v12.3(2026-06-04)
- ✅ 修复设置面板无法保存非 LLM 选项的问题
- ✅ 修复「每个网页使用相同设置」作用域未生效的问题
v12.1(2026-06-03)
- ✅ 修复设置按钮点击后无法弹出设置面板的问题(引入 5px 拖拽阈值)
v12.0(2026-06-02)
- ✨ 新增:设置作用域管理、可拖动按钮、三指长按翻译、自动翻译、七牛云 API 描述超链接
📄 开源协议
本项目以 AGPL-3.0(GNU Affero General Public License v3.0) 开源。
- ✅ 自由使用、修改、分发
- ✅ 用于个人和商业用途
- ⚠️ 若修改后继续通过网络提供服务,必须开源修改版本
- ⚠️ 必须保留原作者署名
详见项目根目录的 LICENSE 文件(或 AGPL-3.0 全文)。
🙏 致谢
- 沉浸式翻译 — 三指触控事件队列设计参考
- MyMemory Translation API — 免费翻译兜底服务
- Via 浏览器 — 轻量级 Android 浏览器
💬 反馈 & 贡献
- 问题反馈:请在 脚本猫 Issue 页面 或 GreasyFork 脚本页面 留言
- 代码贡献:Fork 本仓库,提交 PR
最后更新:2026-06-05
🇬🇧 English
📖 Introduction
TransLite is a lightweight Userscript designed for use on mobile browsers (especially Via Browser). It leverages Large Language Model translation capabilities, with the MyMemory public API as a fallback, to deliver high-quality webpage translation.
Core design philosophy: remain robust and stable in the harsh environment of Android WebView.
✨ Features
| Feature | Description |
|---|---|
| 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 |
| Three-Finger Long-Press Translation | Trigger translation by long-pressing with three fingers on the screen for 500ms; uses a debounced touch state machine, compatible with Android multi-touch |
| Draggable Settings Button | The settings button can be freely dragged and auto-snaps to the screen edge, without blocking page content |
| Auto Translation | Detects the page language and automatically translates pages not in the target language |
| Bilingual Mode | Supports both "direct replacement" and "bilingual side-by-side" translation modes |
| HARDCODED Global Config | Hardcode API keys and other parameters directly in the script, solving the cross-origin storage issue in Via Browser |
📦 Installation
- Install a Userscript manager (e.g. Tampermonkey or the built-in script manager in Via Browser)
- Click the install link: ScriptCat | GreasyFork (under review)
- Alternatively, copy the full code of
TransLite26.1.6.jsand paste it into your script manager
🔧 Usage
1. Configure API Key (Important)
Due to limitations in Via Browser (see "Known Issues"), it is recommended to hardcode the configuration directly in the script file:
- Open
TransLite26.1.6.jswith a text editor - Locate the
HARDCODEDconfiguration block at lines 27–35:
var HARDCODED = {
engine: 'llm', // Translation engine
apiBase: 'https://api.qnaigc.com/v1', // API Base URL
apiKey: '', // ← Fill in your API Key here
model: 'z-ai/glm-4.5-air-free', // Model name
targetLang: 'Simplified Chinese', // Target language
translateMode: 'replace' // 'replace' or 'bilingual'
};
- Fill in your
apiKey, save the file, then reinstall/import the script
💡 Tip: Values in
HARDCODEDtake effect as "global defaults" on all webpages. Modifications made via the in-page settings panel only apply to the current domain; switching domains reverts toHARDCODEDvalues.
2. Using the Settings Panel
- Tap the settings button on the page (draggable, snaps to the right edge by default)
- Switch translation engines, modify prompts, adjust UI parameters, etc. in the panel
- Tap "Save Settings"
⚠️ In Via Browser, settings saved via the panel cannot persist across domains (see Known Issues). It is recommended to configure common parameters directly in
HARDCODED.
3. Three-Finger Long-Press Translation
- Long-press with three fingers simultaneously on the page (exact simultaneity is not required; the script tolerates sequential finger arrival)
- Hold for approximately 500ms, and translation triggers automatically
- The finger movement tolerance threshold is 50px, so minor hand tremors will not cause accidental cancellation
4. Auto Translation
Enable "Auto-translate pages not in target language" in the settings panel; the script will automatically detect the page language and translate.
🔬 Technical Implementation
1. 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.
2. Three-Finger Long-Press Debounced Touch State Machine
touch events in Android WebView are extremely fragile (system gesture interception, frequent touchcancel, sequential finger arrival). This script adopts an event queue design inspired by "Immersive Translate":
- Uses
Touch.identifierto track each finger individually (rather than array indices) - The
activePointsobject accumulates touch points; sequential finger arrival does not affect judgement - Per-axis 50px movement threshold tolerates minor hand tremors on smooth screens
- The
touchcancelevent only clears touch points, without forcibly interrupting the script
3. HARDCODED Global Configuration Mode
Ordinary scripts in Via Browser cannot use GM_setValue (no Tampermonkey API), whilst localStorage is limited by the same-origin policy, causing all configuration to be lost after switching domains.
Solution: hardcode core parameters directly in the HARDCODED object at the script header, serving as global default values for all domains. Content saved via the in-page settings panel only acts as an independent override for the current domain.
Configuration merge priority: UI-saved config > HARDCODED > DEFAULT_CONFIG
4. 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.
⚠️ Known Issues
| Issue | Status | Description |
|---|---|---|
| Settings cannot be saved across pages in Via Browser | 🔴 Unfixed | Via does not support GM_setValue; localStorage is limited by the same-origin policy. Currently only solvable via HARDCODED hardcoding. PRs with better solutions are welcome. |
touchstart event blocked on some webpages |
🟡 Partially compatible | Some dynamic webpages (e.g. Baidu homepage) block event bubbling, causing three-finger long-press to be unresponsive. Try changing the binding target of registerThreeFingerLongPress to document.documentElement or window. |
| Huawei/Honor device three-finger screenshot gesture conflict | 🟡 Partially compatible | Huawei/Honor system-level three-finger screenshot sends touchcancel; the script has fault-tolerant handling, but there is still a chance of interception by the system. It is recommended to temporarily disable the system three-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 | 1 |
| Month | Release month (1–12) | 6 |
Current version: 26.1.6 (Year 2026, Generation 1, Month 6)
📝 Changelog
26.1.6 (2026-06-05) — Initial Release
This release merges all features from the development stage v12.0~v12.6, with the following main improvements:
- 🔧 Refactored three-finger long-press translation logic into a "debounced touch state machine" (
touchStatusunified state management) - 🔧 Changed movement judgement from Euclidean distance to per-axis 50px independent judgement, better tolerating natural hand tremors
- ✅ Fixed
Object.assignmerge order error causing UI settings to be overwritten byHARDCODED - ✅ Fixed the issue where the old version incorrectly cleared
threeFingerMapwhen fingers arrived sequentially, preventing triggering - ✅ Added
HARDCODEDglobal configuration block, solving the cross-origin storage issue in Via Browser - ✨ Complete features: LLM batch translation, MyMemory fallback, draggable settings button, three-finger long-press translation, auto translation, bilingual mode
Click to expand development stage history (v12.x)
v12.6 (2026-06-05)
- 🔧 Refactored three-finger long-press translation logic into debounced touch state machine
v12.5 (2026-06-05)
- ✅ Fixed
Object.assignmerge order error - ✅ Fixed
cancelThreeFingerTimerincorrectly clearing Map
v12.4 (2026-06-05)
- ✅ Added
HARDCODEDglobal configuration block - ✅ Rewrote three-finger long-press tracking logic using
Touch.identifier
v12.3 (2026-06-04)
- ✅ Fixed settings panel unable to save non-LLM options
- ✅ Fixed "Use same settings for all webpages" scope not taking effect
v12.1 (2026-06-03)
- ✅ Fixed settings button click not opening the settings panel (introduced 5px drag threshold)
v12.0 (2026-06-02)
- ✨ Added: settings scope management, draggable button, three-finger long-press translation, auto translation, Qiniu Cloud API description hyperlink
📄 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).
🙏 Acknowledgements
- Immersive Translate — Three-finger touch event queue design reference
- MyMemory Translation API — Free translation fallback service
- Via Browser — Lightweight Android browser
💬 Feedback & Contributions
- Bug reports: Please leave a comment on the ScriptCat Issue page or the GreasyFork script page
- Code contributions: Fork this repository and submit a PR
Last updated: 2026-06-05