您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
Replace Chinese text with English text on any website
// ==UserScript== // @name 配置网页具体中文转换为英文 // @namespace https://github.com/Whiskey-Liu // @version 0.2 // @description Replace Chinese text with English text on any website // @author Your Name // @match *://*/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // 替换文本映射 const translationMap = { '你好': 'Hello', '世界': 'World', '料号': 'model', // 添加更多的替换项 }; // 替换函数 function replaceText(node) { let text = node.nodeValue; for (let [chinese, english] of Object.entries(translationMap)) { let regex = new RegExp(chinese, 'g'); text = text.replace(regex, english); } node.nodeValue = text; } // 遍历所有文本节点 function walk(node) { let child, next; switch (node.nodeType) { case 1: // Element case 9: // Document case 11: // Document fragment child = node.firstChild; while (child) { next = child.nextSibling; walk(child); child = next; } break; case 3: // Text node replaceText(node); break; } } // 初始替换 walk(document.body); // 观察 DOM 变化以处理动态内容 const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { for (let node of mutation.addedNodes) { walk(node); } }); }); observer.observe(document.body, { childList: true, subtree: true }); })();