欢迎访问!

Office学习网

您现在的位置是:主页 > 网络技术

网络技术

油猴脚本实现谷歌翻译接口划词翻译【接口来着

发布时间:2026-06-27网络技术评论
免费的小红心点起来本脚本集成了【zhurui】大佬提供的谷歌翻译接口,感谢大佬。如大佬接口不能使用,那本脚本也

x,url: url, windowWidth - tooltipWidth));const tooltipY = Math.max(0, y - tooltipHeight - 10);tooltip.style.left = tooltipX + 'px';tooltip.style.top = tooltipY + 'px';}// 隐藏气泡function hideTooltip() {const tooltip = document.getElementById('translation-tooltip');if (tooltip) {tooltip.remove();}}// 发送翻译请求function translateText(text) {const url = 'https://findmyip.net/api/translate.php?text=' + encodeURIComponent(text);GM_xmlhttpRequest({method: 'GET', y) {let tooltip = document.getElementById('translation-tooltip');if (!tooltip) {tooltip = createTooltip();document.body.appendChild(tooltip);}tooltip.innerHTML = text;// Add copy buttonconst copyButton = document.createElement('button');copyButton.textContent = '复制';copyButton.style.cssText = buttonStyle;copyButton.onclick = function() {// Decode HTML entities before copyingconst decodedText = decodeHtml(text);navigator.clipboard.writeText(decodedText).then(function() {// Show success messagecopyButton.textContent = '复制成功';setTimeout(function() {copyButton.textContent = '复制';},自动请求翻译并显示结果// @match*://*/*// @grantGM_xmlhttpRequest// ==/UserScript==(function() {'use strict';// Function to decode HTML entitiesfunction decodeHtml(html) {var txt = document.createElement(textarea);txt.innerHTML = html;return txt.value;}// 创建气泡样式const tooltipStyle = `position: absolute;z-index: 9999;background-color: #333;color: #fff;padding: 5px;font-size: 14px;border-radius: 3px;max-width: 450px;text-align: left;white-space: normal;word-wrap: break-word;pointer-events: auto;`;const buttonStyle = `background-color: #555;color: #fff;border: none;padding: 5px 10px;text-align: center;text-decoration: none;display: inline-block;font-size: 12px;margin: 5px 2px;cursor: pointer;border-radius: 2px;`;// 创建气泡元素function createTooltip() {const tooltip = document.createElement('div');tooltip.id = 'translation-tooltip';tooltip.style.cssText = tooltipStyle;return tooltip;}// 显示气泡function showTooltip(text,onerror: function(error) {console.error('翻译请求发生错误:', err);});};tooltip.appendChild(copyButton);// Adjust tooltip positionconst tooltipWidth = tooltip.offsetWidth;const tooltipHeight = tooltip.offsetHeight;const windowWidth = window.innerWidth;const windowHeight = window.innerHeight;const tooltipX = Math.max(0。

y);}},我试着改了下 [Asm] 纯文本查看 复制代码 // ==UserScript==// @name文本翻译脚本// @namespace https://example.com// @version1.0// @description 鼠标左键选中文本后,onload: function(response) {const Jresponse = JSON.parse(response.responseText);var translation = '内部接口错误。

error);}});}// 监听鼠标释放事件window.addEventListener('mouseup', 破解专用户 发表于 2023-12-8 08:40 我是不是应该回复。

Math.min(x - tooltipWidth / 2,您一定要坚挺啊!!! -------------------------- 同时我又自私的回复楼主 ... 你的建议不错, function() {createTooltip();});})(); , 2000);}。

请联系开发者'if(Jresponse.code==400){translation = Jresponse.error;}else{translation = Jresponse.data.translate_result;}const selection = window.getSelection();if (selection.rangeCount 0) {const range = selection.getRangeAt(0);const rect = range.getBoundingClientRect();const x = rect.left + window.pageXOffset + rect.width / 2;const y = rect.top + window.pageYOffset;showTooltip(translation, x,大佬挺住, function(err) {console.error('复制失败:', function(event) {if (event.button === 0) { // 鼠标左键const selection = window.getSelection();const selectedText = selection.toString().trim();if (selectedText !== '') {translateText(selectedText);} else {hideTooltip();}}});// 初始化气泡元素window.addEventListener('DOMContentLoaded',。

广告位

热心评论

评论列表