您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a translate button for character messages in the chat for beta.character.ai
当前为
// ==UserScript== // @name Translate Button for beta.character.ai // @namespace TranslateButtonForBetaCharacterAI // @version 1.0 // @description Adds a translate button for character messages in the chat for beta.character.ai // @icon https://characterai.io/static/favicon.ico // @match https://beta.character.ai/chat?char=* // @grant GM_xmlhttpRequest // @run-at document-end // @license MIT // ==/UserScript== function addButton() { var elements = document.getElementsByClassName("msg char-msg"); for (var i = 0; i < elements.length; i++) { const charMsg = elements[i]; if (charMsg.querySelector(".translate-button") === null) { var btn = document.createElement("button"); btn.innerHTML = "Tr"; btn.classList.add("translate-button"); btn.style.cssText = "width: 30px; height: 30px;"; // Add event listener for click event on translate button btn.addEventListener("click", function() { const pElements = charMsg.querySelectorAll('p, li'); for (var j = 0; j < pElements.length; j++) { const pElement = pElements[j]; const text = pElement.textContent; if (pElement.originalText != null) { console.log("Return original message text: " + text); pElement.textContent = pElement.originalText; pElement.originalText = null; continue; } console.log("Message text: " + text); pElement.originalText = text; // Use the user's language as the target language in the API request var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" + navigator.language + "&dt=t&q=" + encodeURIComponent(text); GM_xmlhttpRequest({ method: "GET", url: url, onload: function(response) { const translation = JSON.parse(response.responseText)[0][0][0]; // Log the translation console.log("Translated text: " + translation); // Replace the original text with the translated text pElement.textContent = translation; } }); } }); // Log the button being added console.log("Added translate button for element: " + elements[i]); charMsg.insertBefore(btn, charMsg.firstChild); } } } setInterval(addButton, 1000); // Check every second
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址