您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
translate from japanise to chinese use translate
// ==UserScript== // @name translatorTest // @namespace http://tampermonkey.net/ // @version 2024-10-06 // @description translate from japanise to chinese use translate // @author Rexkny // @license MIT // @match */1.RpgxViewer/index.html // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @require https://cdn.jsdelivr.net/npm/translate@1/translate.min.js // ==/UserScript== (function() { 'use strict'; const translatedTextBox = document.createElement("div") translatedTextBox.innerText = "翻译内容将在下方显示:" translatedTextBox.style.color = 'white' const translateSpan = document.createElement("span") translateSpan.style.display = 'block' const contentWrap = document.querySelector('#body-wrapper') contentWrap.appendChild(translatedTextBox) translatedTextBox.appendChild(translateSpan) const doTranslate = (strTobeTranslated, targetDom, sourceLanguage, targetLanguage) => { const options = {} options.engine = 'google'; // 使用Google翻译 options.from = sourceLanguage || 'ja'; // 源语言为日语 options.to = targetLanguage || 'zh'; // 目标语言为中文 options.cache = 2000; // 请求时长2000ms translate(strTobeTranslated, options).then(res => { translateSpan.innerText = res }) } // 获取场景父元素 var scenceView = document.querySelector('#scene-viewer') const config = { childList: true, subtree: true }; const callback = (mutationsList) => { // 父元素更新时获取对话框文本 const textBox = document.querySelector('.text-box-text') if (textBox && textBox.innerText) { const formattedText = textBox.innerText.replace(/[\r\n]+/g, '') doTranslate(textBox.innerText, textBox) } } const textBoxObserver = new MutationObserver(callback); textBoxObserver.observe(scenceView, config); document.addEventListener('beforeunload', () => { textBoxObserver.disconnect() }) })();