// ==UserScript== // @name Telegram 简体中文化 UI ( 网页版 ) - 动态正则增强版 // @namespace http://tampermonkey.net/ // @version 1.15 // @description 将 Telegram Web UI 界面翻译成简体中文( 支持 Web A/K,补充 Connected websites 及动态网站数量翻译 ) // @author 小安 (Gemini 简体修改版) // @match https://web.telegram.org/* // @license MIT // @grant none // @run-at document-idle // @downloadURL https://update.greasyfork.icu/scripts/574126/Telegram%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%E5%8C%96%20UI%20%28%20%E7%BD%91%E9%A1%B5%E7%89%88%20%29%20-%20%E5%8A%A8%E6%80%81%E6%AD%A3%E5%88%99%E5%A2%9E%E5%BC%BA%E7%89%88.user.js // @updateURL https://update.greasyfork.icu/scripts/574126/Telegram%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%E5%8C%96%20UI%20%28%20%E7%BD%91%E9%A1%B5%E7%89%88%20%29%20-%20%E5%8A%A8%E6%80%81%E6%AD%A3%E5%88%99%E5%A2%9E%E5%BC%BA%E7%89%88.meta.js // ==/UserScript== (function () { 'use strict'; // 静态词典映射 const translationMap = { // --- 侧边栏/主菜单/快捷菜单 --- "My Profile": "我的个人资料", "All": "全部", "Add Account": "添加账户", "Saved Messages": "收藏夹", "Archived Chats": "已归档的聊天", "Contacts": "联系人", "My Stories": "我的快拍", "Settings": "设置", "Night Mode": "夜间模式", "Enable Dark Mode": "开启深色模式", "Animations": "动画", "Disable Animations": "禁用动画", "New Group": "新建群组", "Telegram Features": "Telegram 特性", "Report a Bug": "报告问题", "Report Bug": "报告问题", "Switch to K Version": "切换到 K 版本", "Switch to A Version": "切换到 A 版本", "Switch to A version": "切换到 A 版本", "Install App": "安装应用", "More": "更多", // --- 个人资料/状态 --- "Iast seen minute ago": "最近上线", "online": "在线", "Phone": "手机号码", "Username": "用户名", "Bio": "个人简介", "Date of Birth": "出生日期", "Birthday": "生日", "Invite Friends": "邀请好友", "Log Out": "退出登录", "Search": "搜索", "Edit profile": "编辑个人资料", // --- 聊天面板 & 频道/群组操作 --- "Message": "发消息", "Silent Broadcast": "无声广播", "Photo or Video": "照片或视频", "Photo": "照片", "File": "文件", "select messages": "选择消息", "Select messages": "选择消息", "Select Messages": "选择消息", "send a Gift": "赠送礼物", "Delete chat": "删除聊天", "Delete All Cloud Drafts": "删除所有云端草稿", "Shared Media": "共享媒体", "Channel Info": "频道信息", "Mute": "静音", "Unmute": "取消静音", "Edit": "编辑", "Start Video chat": "发起视频通话", "Start Video Chat": "发起视频通话", "View Discussion": "查看讨论", "Boosts": "助力", "Statistics": "统计数据", "Boost Channel": "助力频道", "Leave Channel": "退出频道", "Delete and Exit": "删除并退出", "Chats": "聊天", "Posts": "帖子", "Story Archive": "快拍归档", "Media": "媒体", "Files": "文件", "Links": "链接", "Music": "音乐", "Voice": "语音", "Poll": "投票", "Pinned message": "置顶消息", "Pinned message #": "置顶消息 #", "": "", // --- 顶部横幅及弹窗提示 --- "Never miss a message! 🔔": "不错过任何消息!🔔", "Enable notifications to stay updated.": "启用通知以保持更新。", "Something went wrong": "出错了", "You can’t logout other sessions if less than 24 hours have passed since you logged on the current session": "如果在当前设备登录未满 24 小时,您将无法注销其他会话。", "Telegram": "Telegram", "For security reasons, you can't set up a passkey from a device that you've just connected. Please use an earlier connection or wait for a few hours.": "出于安全原因,您无法在刚刚连接的设备上设置通行密钥。请使用之前连接过的设备,或者等待几个小时。", "Protect your account": "保护您的账户", "Log in safely and keep your account secure.": "安全登录并保障您的账户安全。", "Create a Passkey": "创建通行密钥", "Make a passkey to log in easily and safely.": "创建通行密钥,让登录更轻松、更安全。", "Make a passkey to sign in easily and safely.": "创建通行密钥,让登录更轻松、更安全。", "Log in with Face ID": "使用面容 ID 登录", "Use Face ID, Touch ID, or your passcode to log in.": "使用面容 ID、触控 ID 或设备密码进行登录。", "Log in with face recognition": "使用面部识别登录", "Use your face, fingerprint, or passcode to sign in.": "使用面容、指纹或设备密码进行登录。", "Store Passkey Securely": "安全存储通行密钥", "Store Passkey securely": "安全存储通行密钥", "Your passkey is safely kept in your iCloud Keychain.": "您的通行密钥会安全地保存在 iCloud 钥匙串中。", "Your passkey is stored safely in the cloud service you choose.": "您的通行密钥会安全地保存在您选择的云服务中。", "CREATE PASSKEY": "创建通行密钥", "Create Passkey": "创建通行密钥", "Create passkey": "创建通行密钥", "SKIP": "跳过", "Skip": "跳过", "OK": "确定", // --- 通用设置 (包含 Web A & Web K) --- "General Settings": "通用设置", "General": "通用", "Message Font Size": "消息字体大小", "Message Text Size": "消息字体大小", "Chat Wallpaper": "聊天背景", "Theme": "主题", "Color theme": "颜色主题", "Light": "浅色", "Day": "白天", "Drak": "深色", "Dark": "深色", "Night": "夜间", "System": "跟随系统", "System Default": "跟随系统", "Time format": "时间格式", "Time Format": "时间格式", "12-hour": "12小时制", "24-hour": "24小时制", "Keyboard": "键盘", "Send with Enter": "按 Enter 键发送", "Send by Enter": "按 Enter 键发送", "Press Shift + Enter for new line": "按 Shift + Enter 换行", "New line by Shift + Enter": "按 Shift + Enter 换行", "Send with Ctrl+Enter": "按 Ctrl+Enter 发送", "Send by Ctrl + Enter": "按 Ctrl+Enter 发送", "Send by ⌘ + Enter": "按 ⌘ + Enter 发送", "Send with Cmd+Enter": "按 Cmd+Enter 发送", "Press Enter for new line": "按 Enter 键换行", "New line by Enter": "按 Enter 键换行", "UI Features": "界面功能", // --- 动画与性能 --- "Animations and Performance": "动画与性能", "Animation Level": "动画等级", "Choose the desired animations amount.": "选择所需的动画数量。", "Power Saving": "省电模式", "Power Saving Mode": "省电模式", "Enable Animations": "启用动画", "Nice and Fast": "快速", "Lots of Stuff": "丰富", "Custom": "自定义", "Resource-Intensive Processes": "资源密集型进程", "Interface Animations": "界面动画", "Page Transitions": "页面过渡", "Message Sending Animation": "消息发送动画", "Media Viewer Animations": "媒体查看器动画", "Message Composer Animations": "消息输入框动画", "Context Menu Animation": "上下文菜单动画", "Context Menu Blur": "上下文菜单模糊", "Right Column Animation": "右侧栏动画", "Dust-effect deletion": "粉碎删除效果", // --- 贴纸与表情 --- "Stickers and Emoji": "贴纸与表情", "Stickers": "贴纸", "Emoji": "表情符号", "Allow Animated Emoji": "允许动画表情", "Loop Animated Stickers": "循环播放动画贴纸", "Animated stickers will play continuously in chats.": "动画贴纸将在聊天中连续播放。", "Reaction Effects": "回应效果", "Sticker Effects": "贴纸效果", "Suggest stickers by emoji": "根据表情符号推荐贴纸", "Suggest Stickers by Emoji": "根据表情符号推荐贴纸", "Suggest Emoji": "推荐表情符号", "Large Emoji": "大表情", "All Sets": "所有贴纸包", "Custom Emoji": "自定义表情", "Quick Reaction": "快速回应", "Dynamic Pack Order": "动态贴纸包排序", "Recently used sticker sets will be displayed above the older ones.": "最近使用的贴纸包将显示在旧贴纸包上方。", "Automatically place recently used sticker packs at the front of the panel.": "自动将最近使用的贴纸包放置在面板最前面。", "My sticker sets": "我的贴纸包", // --- 媒体自动下载与缓存 --- "Media Autoplay": "媒体自动播放", "Autoplay GIFs": "自动播放 GIF", "Autoplay Videos": "自动播放视频", "Data and Storage": "数据与存储", "Automatic media download": "自动下载媒体", "Auto-Download Media": "自动下载媒体文件", "Auto-download photos": "自动下载照片", "Auto-download videos and GIFs": "自动下载视频和 GIF", "Auto-download files": "自动下载文件", "Photos": "照片", "Videos": "视频", "Voice messages are tiny, so they're always downloaded automatically.": "语音消息很小,因此始终会自动下载。", "On in all chats": "在所有聊天中开启", "Other Private Chats": "其他私聊", "Group Chats": "群聊", "Maximum file size": "最大文件大小", "Reset Auto-Download Settings": "重置自动下载设置", "up to 1 MB": "最大 1 MB", "up to 5 MB": "最大 5 MB", "up to 10 MB": "最大 10 MB", "up to 50 MB": "最大 50 MB", "up to 100 MB": "最大 100 MB", "up to 500 MB": "最大 500 MB", "Clear Media Cache": "清除媒体缓存", "Deletes locally cached media for this account": "删除此帐户在本地缓存的媒体文件", "Estimated storage quota": "预计存储配额", "Cached files": "缓存文件", "Clear": "清除", "Clear All": "全部清除", "Images": "图片", "Video files": "视频文件", "Stickers and emojis": "贴纸和表情符号", "Cached video stream chunks": "缓存的视频流块", "Clear cache older than": "清除旧缓存超过", "Cache size limit": "缓存大小限制", "Auto": "自动", "Note that cache required for the app to function properly will not be cleared.": "请注意,应用正常运行所需的缓存不会被清除。", // --- 通知与声音 --- "Notifications": "通知", "Notifications and Sounds": "通知和声音", "Web Notifications": "网页通知", "Show notifications": "显示通知", "Show offline notifications": "显示离线通知", "Enabled": "已启用", "Disabled": "已禁用", "Offline Notifications": "离线通知", "Not supported": "不支持", "All Accounts": "所有账户", "Enable Notifications": "启用通知", "Give Telegram permission to send notifications. You may need to refresh the page to see the changes.": "允许 Telegram 发送通知。您可能需要刷新页面才能查看更改。", "Sound": "声音", "Notification Sound": "通知声音", "Sound Volume": "音量", "Sound volume": "音量", "Drag and release or click to test the volume.": "拖放或点击以测试音量。", "Sound Effects": "音效", "Message Sent": "消息已发送", "Private Chats": "私聊", "Notifications for private chats": "私聊通知", "Message Preview": "消息预览", "Groups": "群组", "Notifications for groups": "群组通知", "Channels": "频道", "Notifications for channels": "频道通知", "Other": "其他", "Contact joined Telegram": "联系人加入了 Telegram", // --- 隐私与安全 --- "Privacy and Security": "隐私与安全", "Blocked Users": "已屏蔽用户", "Passcode Lock": "密码锁定", "Two-Step Verification": "两步验证", "Passkeys": "通行密钥", "Active Websites": "活跃网站", "Connected websites": "已连接的网站", "Login Email": "登录邮箱", "Auto-delete messages": "自动删除消息", "On": "开启", "Off": "关闭", "Privacy": "隐私", "Who can see my phone number?": "谁能看到我的手机号码?", "Who can see my last seen time?": "谁能看到我的最近上线时间?", "Who can see my Last Seen time?": "谁能看到我的最近上线时间?", "Who can see my profile photos?": "谁能看到我的头像?", "Who can see my bio?": "谁能看到我的个人简介?", "Who can see my birthday?": "谁能看到我的生日?", "Who can see my saved music?": "谁能看到我保存的音乐?", "Gifts": "礼物", "Who can add a link to my account when forwarding my messages?": "谁能在转发我的消息时添加指向我账户的链接?", "Who can call me?": "谁能给我打电话?", "Who can send me voice or video messages?": "谁能给我发语音或视频消息?", "Who can send me messages?": "谁能给我发消息?", "Who can add me to group chats?": "谁能把我拉进群聊?", "Who can add me?": "谁能添加我?", "Change who can send you messages.": "更改谁可以给您发送消息。", "Nobody": "没有人", "Everybody": "所有人", "My Contacts": "我的联系人", "Sensitive content": "敏感内容", "Sensitive Content": "敏感内容", "Show 18+ Content": "显示 18+ 内容", "Disable filtering": "禁用过滤", "Do not hide media that contains content suitable only for adults.": "不要隐藏仅适合成年人的媒体内容。", "Window title bar": "窗口标题栏", "Show chat name": "显示聊天名称", "Payments": "付款", "Clear Payment and Shipping Info": "清除付款和发货信息", "You can delete your shipping info and instruct all payment providers to remove your saved credit cards. Note that Telegram never stores your credit card data.": "您可以删除发货信息,并指示所有支付提供商移除已保存的信用卡。注意:Telegram 从不存储您的信用卡数据。", // --- 账户/会话生命周期 --- "Delete my account": "删除我的账户", "If away for": "如果离开超过", "1 week": "1 周", "1 month": "1 个月", "3 months": "3 个月", "6 months": "6 个月", "1 year": "1 年", "24 month": "24 个月", "24 months": "24 个月", "Active Sessions": "活跃设备", "Manage your sessions on all your devices.": "管理您在所有设备上的会话。", "Devices": "设备", "THIS DEVICE": "此设备", "This device": "此设备", "Active sessions": "活跃会话", "Terminate All Other Sessions": "终止所有其他会话", "Automatically terminate old sessions": "自动终止旧会话", "If inactive for": "如果不活跃超过", // --- 聊天分组 --- "Chat Folders": "聊天文件夹", "Create folders for different groups of chats and quickly switch between them.": "为不同的聊天群组创建文件夹以便快速切换。", "Create New Folder": "新建文件夹", "Create Folder": "新建文件夹", "Folders": "文件夹", "All Chats": "所有聊天", "All unarchived chats": "所有未归档的聊天", "Recommended Folders": "推荐文件夹", "Unread": "未读", "New messages from all chats.": "所有聊天中的新消息。", "Personal": "个人", "Only messages from personal chats.": "仅包含私聊消息。", "Add": "添加", "Show Folder Tags": "显示文件夹标签", "Display folder names for each chat in the chat list.": "在聊天列表中显示每个聊天的文件夹名称。", "Tabs View": "标签页视图", "Tabs on the left": "左侧标签页", "Tabs at the top": "顶部标签页", "Folders view": "文件夹视图", "Folders on the Left": "左侧文件夹", "Folders above chats": "聊天上方文件夹", // --- 语言 --- "Language": "语言", "Show Translate Button": "显示翻译按钮", "Translate Entire Chats": "翻译整个聊天", "Do Not Translate": "不翻译", "The 'Translate' button will appear in the context menu of messages containing text.": "“翻译”按钮将出现在包含文本的消息的上下文菜单中。", "Interface Language": "界面语言", // --- 其他 --- "Telegram Premium": "Telegram 会员", "My Stars": "我的星星", "Send a Gift": "赠送礼物", "Ask a Question": "提问", "Telegram FAQ": "Telegram 常见问题解答", "Privacy Policy": "隐私政策" }; // 动态正则替换函数:更严格的匹配,仅在数字紧跟目标词汇时替换 function translateDynamicText(text) { let newText = text; // 使用正则检测字符串中是否包含以数字开头的这些组合 if (/\d+\s+(chats?|channels?|groups?|subscribers?|websites?)/i.test(newText)) { newText = newText .replace(/(\d+)\s*channels?/gi, "$1 个频道") .replace(/(\d+)\s*groups?/gi, "$1 个群组") .replace(/(\d+)\s*chats?/gi, "$1 个聊天") .replace(/(\d+)\s*subscribers?/gi, "$1 个订阅者") .replace(/(\d+)\s*websites?/gi, "$1 个网站") .replace(/\band\b/g, "和"); } return newText; } function translateTextNodes() { const xpath = "//text()[normalize-space(.) != '']"; const textNodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (let i = 0; i < textNodes.snapshotLength; i++) { const node = textNodes.snapshotItem(i); const originalText = node.nodeValue.trim(); // 1. 先尝试完全匹配静态字典 if (translationMap[originalText]) { node.nodeValue = translationMap[originalText]; } else { // 2. 如果字典里没有,尝试动态正则替换 const dynamicTranslated = translateDynamicText(originalText); if (dynamicTranslated !== originalText) { node.nodeValue = dynamicTranslated; } } } } function observerCallback() { translateTextNodes(); } const observer = new MutationObserver(observerCallback); observer.observe(document.body, { childList: true, subtree: true }); translateTextNodes(); })();