Claude.ai 汉化

自动翻译claude.ai网页内的内容,并且支持自动翻译title

  1. // ==UserScript==
  2. // @name Claude.ai 汉化
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description 自动翻译claude.ai网页内的内容,并且支持自动翻译title
  6. // @match https://claude.ai/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // 翻译映射
  15. const translations = {
  16. "NEW" : "新功能",
  17. "Collab with Claude in your codebase" : "在您的代码库中与Claude协作",
  18. "Get AI pair programming right in your terminal with Claude Code" : "在终端中使用Claude Code进行AI配对编程",
  19. "Ship better code faster, and understand complex codebases with ease" : "更快地发布更好的代码,轻松理解复杂的代码库",
  20. "Available through the research preview and billed through your Anthropic Console account based on API usage" : "通过研究预览版本提供,并根据API使用情况通过您的Anthropic Console账户计费",
  21. "Team up with Claude" : "与Claude组建团队",
  22. "Create Team Account" : "创建团队账户",
  23. "Everything in Pro" : "包含Pro版的所有功能",
  24. "Higher usage limits" : "更高的使用限制",
  25. "Early access to new collaboration features" : "抢先体验新协作功能",
  26. "Central billing and administration" : "集中计费与管理",
  27. "Color mode" : "颜色模式",
  28. "Chat font" : "聊天字体",
  29. "Log out of all devices" : "在所有设备上注销",
  30. "Delete your account" : "删除您的账户",
  31. "Get 5x more usage with Claude Pro" : "通过Claude Pro获得5倍更多使用次数",
  32. "Subscribe to Pro" : "订阅Pro版",
  33. "More usage than Free" : "比免费版有更多使用次数",
  34. "Organize documents and chats with Projects" : "通过项目组织文档和聊天",
  35. "Access additional Claude models" : "访问额外的Claude模型",
  36. "Use Claude 3.7 Sonnet with extended thinking mode" : "使用Claude 3.7 Sonnet并启用扩展思维模式",
  37. "Connected accounts" : "关联账户",
  38. "Analysis tool" : "分析工具",
  39. "Feature preview" : "功能预览",
  40. "Artifacts" : "产物",
  41. "Claude capabilities" : "Claude的基本能力",
  42. "Anthropic’s guidelines" : "Anthropic的指导原则",
  43. "Learn about preferences" : "了解更多关于偏好的信息。",
  44. "Your preferences will apply to all conversations, within" : "您的偏好设置将适用于所有对话,并遵循",
  45. "Usage policy" : "使用政策",
  46. "Privacy policy" : "隐私政策",
  47. "How can I help you today?": "我今天能帮你做些什么?",
  48. "Fastest model for daily tasks": "日常任务中最快的模型",
  49. "Our most intelligent model yet": "我们迄今为止最智能的模型",
  50. "Upgrade": "升级",
  51. "What’s new": "最近怎样",
  52. "Beta": "测试",
  53. "BETA": "测试",
  54. "Language": "语言",
  55. "Download Claude for Windows": "下载 Claude Windows 版",
  56. "Log out": "登出",
  57. "Free plan": "免费用户",
  58. "Chats": "历史对话",
  59. "Start new chat": "开始新对话",
  60. "Start New Chat": "开始新对话",
  61. "New chat": "新对话",
  62. "Star chat": "星标对话",
  63. "Projects": "项目",
  64. "Starred": "已加星标",
  65. "Unpin sidebar": "取消固定侧边栏",
  66. "Pin sidebar": "固定侧边栏",
  67. "Star projects and chats you use often": "为您经常使用的项目和对话加星标",
  68. "Your recent chats": "您最近的对话",
  69. "View all": "查看全部",
  70. "How can Claude help you today?": "今天Claude能为您做些什么?",
  71. "Use a project": "使用项目",
  72. "Add content": "添加内容",
  73. "Upload docs or images": "上传文档或者图片",
  74. "Max 5, 30mb each": "最多5个,每个30MB",
  75. "Summarize meeting notes": "总结会议记录",
  76. "Extract insights from report": "从报告中提取见解",
  77. "Generate interview questions": "生成面试问题",
  78. "Professional Plan": "专业版计划",
  79. "Good morning": "早上好",
  80. "Help & support": "帮助与支持",
  81. "Claude currently cannot access the internet or reference links": "Claude目前无法访问互联网或参考链接",
  82. "Use shift + return for new line": "用 Shift + 回车键换行",
  83. "Send message": "发送消息",
  84. "Rename": "重命名",
  85. "Delete": "删除",
  86. "Copy": "复制",
  87. "Claude can make mistakes. Please double-check responses.": "Claude可能会犯错。请仔细检查回复。",
  88. "Edit": "编辑",
  89. "Retry": "重试",
  90. "Share positive feedback": "分享正面反馈",
  91. "Report issue": "报告问题",
  92. "Recents": "最近",
  93. "Select": "选择",
  94. "You have {n} previous chats with Claude": "您与Claude有{n}个以前的对话",
  95. "Last message": "最后消息",
  96. "Capture screenshot":"截图",
  97. "Your chat history":"您的对话历史",
  98. "selected chats":"已选对话",
  99. "Select all":"全选",
  100. "Cancel":"取消",
  101. "Delete selected":"删除已选",
  102. "Clear Cache": "清除缓存",
  103. "Are you sure you want to clear the translation cache?": "您确定要清除翻译缓存吗?",
  104. "Yes": "是",
  105. "No": "否",
  106. "Settings": "设置",
  107. "Appearance": "外观",
  108. "Feature Preview": "功能预览",
  109. "Learn more": "了解更多",
  110. "API Console": "API 控制台",
  111. "Help & Support": "帮助与支持",
  112. "Log Out": "退出登录(不可用)",
  113. "System": "系统",
  114. "Light": "浅色",
  115. "Dark": "深色",
  116. "Profile": "个人资料",
  117. "Billing": "账单",
  118. "Account": "账户",
  119. "Full name": "全名",
  120. "What should we call you?": "我们应该如何称呼您?",
  121. "Update Name": "更新名称",
  122. "What best describes your work?": "什么最能描述您的工作?",
  123. "Select your work function": "选择您的工作职能",
  124. "Show prompt suggestions": "显示提示建议",
  125. "We’ll show examples of starter prompts you can use based on your role": "我们将根据您的角色显示您可以使用的起始提示示例",
  126. "Enable artifacts": "启用智能工件",
  127. "Ask Claude to generate content like code snippets, text documents, or website designs, and Claude will create an Artifact that appears in a dedicated window alongside your conversation.": "要求 Claude 生成代码片段、文本文档或网站设计等内容,Claude 将创建一个人工制品,显示在您对话旁边的专用窗口中。",
  128. "Subscribed to Pro": "已订阅专业版",
  129. "Thanks for being a Pro, BaiYa": "感谢您成为专业版用户,BaiYa",
  130. "Level up your Claude usage with 5x more usage versus Free plan": "相比免费计划,您的 Claude 使用量提升了 5 倍",
  131. "Access to Claude 3 Haiku, our fastest model, and Claude 3 Opus": "可以使用 Claude 3 Haiku(我们最快的模型)和 Claude 3 Opus",
  132. "Create Projects to work with Claude around a set of docs, code, or files": "创建项目,使用 Claude 处理一组文档、代码或文件",
  133. "Priority access during high-traffic periods": "在高流量期间享有优先访问权",
  134. "Early access to new features": "抢先体验新功能",
  135. "Payment": "支付",
  136. "Link by Stripe": "Stripe 链接",
  137. "Update": "更新",
  138. "Invoices": "发票",
  139. "Date": "日期",
  140. "Total": "总计",
  141. "Status": "状态",
  142. "Actions": "操作",
  143. "Paid": "已支付",
  144. "View": "查看",
  145. "Cancellation": "取消订阅",
  146. "Cancel plan": "取消计划",
  147. "Export data": "导出数据",
  148. "Export Data": "导出数据",
  149. "Delete account": "删除账户",
  150. "Contact Support": "联系支持",
  151. "About Anthropic": "关于 Anthropic",
  152. "Consumer Terms": "用户条款",
  153. "Usage Policy": "使用政策",
  154. "Privacy Policy": "隐私政策",
  155. "Your Privacy Choices": "您的隐私选择",
  156. "Provide stakeholder perspective": "提供利益相关者视角",
  157. "Generate excel formulas": "生成 Excel 公式",
  158. "Try this prompt": "试试这个提示",
  159. "Polish your prose": "润色您的文笔",
  160. "Write a memo": "写一份备忘录",
  161. "Use projects to organize chats and give Claude knowledge context": "使用项目组织对话并给Claude知识上下文",
  162. "Reload suggestions": "重新加载提示",
  163. "Hide suggestions": "隐藏提示",
  164. "Good afternoon": "下午好",
  165. "Chat controls": "对话控制",
  166. "Claude 3.5 Sonnet": "Claude 3.5 Sonnet",
  167. "Most intelligent model": "最智能的模型",
  168. "Content": "内容",
  169. "Add images, PDFs, docs, spreadsheets, and more to summarize, analyze, and query content with Claude.": "添加图片、PDF、文档、电子表格等,以便使用 Claude 总结、分析和查询内容。",
  170. "Chat styles": "对话样式",
  171. "Font": "字体",
  172. "Default": "默认",
  173. "Match system": "匹配系统",
  174. "Dyslexic friendly": "适合阅读障碍者",
  175. "Click to open document": "点击打开文档",
  176. "Refresh": "刷新",
  177. "Download to file": "下载到文件"
  178. };
  179.  
  180. let translationCache = {};
  181.  
  182. // 修改翻译函数
  183. function translateText(node) {
  184. if (node.nodeType === Node.TEXT_NODE) {
  185. const trimmedText = node.textContent.trim();
  186. if (translations[trimmedText]) {
  187. node.textContent = node.textContent.replace(trimmedText, translations[trimmedText]);
  188. } else if (node.parentElement &&
  189. (node.parentElement.classList.contains('truncate') ||
  190. node.parentElement.classList.contains('font-tiempos') ||
  191. node.parentElement.classList.contains('text-sm') ||
  192. (node.parentElement.closest('.group') && node.parentElement.classList.contains('break-words')))) {
  193. // 检查缓存
  194. if (translationCache[trimmedText]) {
  195. node.textContent = translationCache[trimmedText];
  196. } else {
  197. translateWithGoogleAPI(trimmedText).then(translatedText => {
  198. node.textContent = translatedText;
  199. translationCache[trimmedText] = translatedText;
  200. });
  201. }
  202. }
  203. } else if (node.nodeType === Node.ELEMENT_NODE) {
  204. ['placeholder', 'aria-label', 'title'].forEach(attr => {
  205. if (node.hasAttribute(attr)) {
  206. let original = node.getAttribute(attr);
  207. if (translations[original]) {
  208. node.setAttribute(attr, translations[original]);
  209. }
  210. }
  211. });
  212. // 处理链接文本
  213. if (node.tagName === 'A' && node.textContent.trim() in translations) {
  214. node.textContent = translations[node.textContent.trim()];
  215. }
  216. }
  217. }
  218.  
  219. // 使用Google Translate API进行翻译
  220. async function translateWithGoogleAPI(text) {
  221. if (translationCache[text]) {
  222. return translationCache[text];
  223. }
  224.  
  225. const apiUrl = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=zh-CN&dt=t&q=${encodeURIComponent(text)}`;
  226. try {
  227. const response = await fetch(apiUrl);
  228. const data = await response.json();
  229. const translatedText = data[0][0][0];
  230. translationCache[text] = translatedText;
  231. return translatedText;
  232. } catch (error) {
  233. console.error('Translation error:', error);
  234. return text; // 如果翻译失败,返回原文
  235. }
  236. }
  237.  
  238. // 修改翻译页面函数
  239. function translatePage() {
  240. const walker = document.createTreeWalker(
  241. document.body,
  242. NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,
  243. {
  244. acceptNode: function(node) {
  245. if (node.nodeType === Node.ELEMENT_NODE &&
  246. (node.getAttribute('contenteditable') === 'true' ||
  247. node.tagName === 'TEXTAREA' ||
  248. node.tagName === 'INPUT' ||
  249. (node.closest('.font-claude-message') &&
  250. !node.classList.contains('truncate') &&
  251. !node.classList.contains('font-tiempos') &&
  252. !node.classList.contains('break-words')))) {
  253. return NodeFilter.FILTER_REJECT;
  254. }
  255. return NodeFilter.FILTER_ACCEPT;
  256. }
  257. },
  258. false
  259. );
  260.  
  261. let node;
  262. while(node = walker.nextNode()) {
  263. translateText(node);
  264. }
  265.  
  266. translateSpecificElements();
  267. }
  268.  
  269. // 添加对特定元素的翻译
  270. function translateSpecificElements() {
  271. document.querySelectorAll('.font-styrene .break-words.text-sm.font-medium.leading-tight').forEach(element => {
  272. translateElementContent(element);
  273. });
  274.  
  275. document.querySelectorAll('.sticky .font-tiempos.truncate').forEach(element => {
  276. translateElementContent(element);
  277. });
  278. }
  279.  
  280. function translateElementContent(element) {
  281. const originalText = element.textContent.trim();
  282. if (originalText && !translationCache[originalText]) {
  283. translateWithGoogleAPI(originalText).then(translatedText => {
  284. element.textContent = translatedText;
  285. translationCache[originalText] = translatedText;
  286. });
  287. } else if (translationCache[originalText]) {
  288. element.textContent = translationCache[originalText];
  289. }
  290. }
  291.  
  292. // 监听输入框内容变化
  293. const editableElements = document.querySelectorAll('[contenteditable="true"], textarea');
  294. editableElements.forEach(element => {
  295. element.addEventListener('input', (event) => {
  296. handleTranslationUpdate(event.target);
  297. });
  298. });
  299.  
  300. // 更新编辑框的翻译
  301. function handleTranslationUpdate(element) {
  302. const updatedText = element.value || element.textContent;
  303. updateTranslationForElement(element, updatedText);
  304. }
  305.  
  306. function updateTranslationForElement(element, text) {
  307. if (translationCache[text]) {
  308. element.textContent = translationCache[text];
  309. } else {
  310. translateWithGoogleAPI(text).then(translatedText => {
  311. element.textContent = translatedText;
  312. translationCache[text] = translatedText;
  313. });
  314. }
  315. }
  316.  
  317. // 强制更新编辑框内容
  318. setTimeout(() => {
  319. editableElements.forEach(element => {
  320. element.dispatchEvent(new Event('input'));
  321. });
  322. }, 50);
  323.  
  324. // 监听DOM变化
  325. const observer = new MutationObserver((mutations) => {
  326. mutations.forEach((mutation) => {
  327. if (mutation.type === 'childList') {
  328. mutation.addedNodes.forEach((node) => {
  329. if (node.nodeType === Node.ELEMENT_NODE) {
  330. const walker = document.createTreeWalker(
  331. node,
  332. NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,
  333. {
  334. acceptNode: function(node) {
  335. if (node.nodeType === Node.ELEMENT_NODE &&
  336. (node.getAttribute('contenteditable') === 'true' ||
  337. node.tagName === 'TEXTAREA' ||
  338. node.tagName === 'INPUT' ||
  339. (node.closest('.font-claude-message') && !node.classList.contains('truncate') && !node.classList.contains('font-tiempos')))) {
  340. return NodeFilter.FILTER_REJECT;
  341. }
  342. return NodeFilter.FILTER_ACCEPT;
  343. }
  344. },
  345. false
  346. );
  347.  
  348. let childNode;
  349. while(childNode = walker.nextNode()) {
  350. translateText(childNode);
  351. }
  352.  
  353. translateSpecificElements();
  354. }
  355. });
  356. }
  357. });
  358. });
  359.  
  360. observer.observe(document.body, { childList: true, subtree: true });
  361.  
  362. // 定时翻译检查
  363. let translationInterval = setInterval(() => {
  364. translatePage();
  365. if (document.readyState === 'complete') {
  366. clearInterval(translationInterval);
  367. setInterval(translateSpecificElements, 5000);
  368. }
  369. }, 1000);
  370.  
  371. // 初始翻译
  372. translatePage();
  373. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址