您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
对axiom的推文监控,代币内推文,扫链出现的推文进行翻译
当前为
// ==UserScript== // @name Axiom推文翻译 // @namespace http://tampermonkey.net/ // @version 3.0 // @author @Gufii_666 // @description 对axiom的推文监控,代币内推文,扫链出现的推文进行翻译 // @match https://axiom.trade/pulse* // @match https://axiom.trade/trackers* // @match https://axiom.trade/meme/* // @match https://axiom.trade/discover* // @license MIT // @grant none // ==/UserScript== (function() { 'use strict'; const TRANSLATION_BASE_URL = 'https://translate.googleapis.com/translate_a/single'; const CLIENT_PARAM = 'gtx'; const SOURCE_LANG = 'en'; const TARGET_LANG = 'zh-CN'; const DATA_TYPE = 't'; const TRANSLATED_TEXT_CLASS = 'localized-content-display'; const ORIGINAL_DATA_ATTR = 'data-translation-processed-status'; async function obtainLocalizedText(inputString) { if (!inputString || typeof inputString !== 'string') { return '[Translation Input Error]'; } const queryParams = new URLSearchParams({ client: CLIENT_PARAM, sl: SOURCE_LANG, tl: TARGET_LANG, dt: DATA_TYPE, q: inputString }); const fullUrl = `${TRANSLATION_BASE_URL}?${queryParams.toString()}`; try { const response = await fetch(fullUrl); const data = await response.json(); return data[0]?.map(segment => segment[0]).join('') || '[Translation Fetch Error]'; } catch (error) { console.error("Content localization failed:", error); return '[Failed to Localize]'; } } function injectLocalizedParagraph(targetElement, translatedContent, prepend = false) { if (!targetElement || !targetElement.parentElement) return; const newParagraph = document.createElement("p"); newParagraph.classList.add(TRANSLATED_TEXT_CLASS); newParagraph.textContent = translatedContent; Object.assign(newParagraph.style, { color: "#FFFFFF", backgroundColor: "#2E8B57", fontSize: "14px", fontWeight: "bold", padding: "8px 12px", borderRadius: "6px", margin: "8px 0", boxShadow: "0 2px 8px rgba(0, 0, 0, 0.3)", border: "1px solid #4CAF50", display: "block", lineHeight: "1.5", textShadow: "1px 1px 2px rgba(0,0,0,0.2)" }); if (prepend) { targetElement.parentElement.insertBefore(newParagraph, targetElement); } else { targetElement.parentElement.appendChild(newParagraph); } } async function handleContentBlockTranslation(parentContainer) { const textElement = parentContainer.querySelector("p.tweet-body_root__ChzUj") || parentContainer.querySelector("p.text-textSecondary.mt-1.whitespace-pre-wrap"); if (!textElement || textElement.getAttribute(ORIGINAL_DATA_ATTR)) return; const rawContent = textElement.innerText.trim(); if (!rawContent) return; const localizedContent = await obtainLocalizedText(rawContent); injectLocalizedParagraph(textElement, localizedContent, true); textElement.setAttribute(ORIGINAL_DATA_ATTR, 'true'); } async function handleProfileDescriptionTranslation(containerElement) { const descriptionElement = containerElement.querySelector("p.break-words"); if (!descriptionElement || descriptionElement.getAttribute(ORIGINAL_DATA_ATTR)) return; const textParts = Array.from(descriptionElement.querySelectorAll("span")); const combinedText = textParts.map(s => s.textContent).join('').trim(); if (!combinedText) return; const localizedContent = await obtainLocalizedText(combinedText); injectLocalizedParagraph(descriptionElement, localizedContent, false); descriptionElement.setAttribute(ORIGINAL_DATA_ATTR, 'true'); const parentWrapper = descriptionElement.closest("div[style], div.relative"); if (parentWrapper) { parentWrapper.style.maxHeight = "none"; parentWrapper.style.overflow = "visible"; const overlayGradient = parentWrapper.querySelector("div[class*='bg-gradient-to-b']"); if (overlayGradient) { overlayGradient.style.display = "none"; } } } function performFullPageScan() { document.querySelectorAll(`.${TRANSLATED_TEXT_CLASS}`).forEach(el => el.remove()); document.querySelectorAll(`[${ORIGINAL_DATA_ATTR}]`).forEach(el => el.removeAttribute(ORIGINAL_DATA_ATTR)); document.querySelectorAll("article.tweet-container_article__0ERPK").forEach(handleContentBlockTranslation); document.querySelectorAll(".hover\\:bg-primaryStroke\\/20.relative.group.text-\\[14px\\]").forEach(handleContentBlockTranslation); document.querySelectorAll("p.break-words").forEach(pElement => { const parentDiv = pElement.closest("div"); if (parentDiv) { handleProfileDescriptionTranslation(parentDiv); } }); } let lastPathname = window.location.pathname; const contentWatcher = new MutationObserver((mutations) => { if (window.location.pathname !== lastPathname) { lastPathname = window.location.pathname; setTimeout(performFullPageScan, 500); } for (const mutationRecord of mutations) { for (const addedDomNode of mutationRecord.addedNodes) { if (addedDomNode.nodeType !== 1 || !addedDomNode.querySelector) continue; addedDomNode.querySelectorAll("article.tweet-container_article__0ERPK").forEach(handleContentBlockTranslation); const newContentBlockParent = addedDomNode.querySelector(".hover\\:bg-primaryStroke\\/20.relative.group.text-\\[14px\\]"); if (newContentBlockParent) { handleContentBlockTranslation(newContentBlockParent); } const potentialBioElement = addedDomNode.querySelector("p.break-words"); if (potentialBioElement) { const bioContainer = potentialBioElement.closest("div"); if (bioContainer) { handleProfileDescriptionTranslation(bioContainer); } } } } }); contentWatcher.observe(document.body, { childList: true, subtree: true }); performFullPageScan(); })();