// ==UserScript== // @name Quick Search - 快速搜索 (修复版) // @namespace Violentmonkey Scripts // @version 1.9.6 // @author smallx (Optimized by Gemini) // @description 修复 Cloudflare验证无法通过。 // @license MIT // @homepageURL https://github.com/smallx/monkey-scripts/tree/master/quick-search // @icon data:image/x-icon;base64,AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhGhsAIRobACEaGwAhGhsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIRobACEaGwAhGhsAIRobACEaGwAhGhsAIRobAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEaGwAhGhsAIRobAyEaG0shGhtzIRobMSEaGwEhGhsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhGhsAIRobACEaGwQhGhtkIRob3CEaG/QhGhvLIRobGyEaGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIRobACEaGwAhGhsFIRobZSEaG9AhGhvhIRob6iEaG+AhGhsqIRobAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA // @match *://*/* // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/564919/Quick%20Search%20-%20%E5%BF%AB%E9%80%9F%E6%90%9C%E7%B4%A2%20%28%E4%BF%AE%E5%A4%8D%E7%89%88%29.user.js // @updateURL https://update.greasyfork.icu/scripts/564919/Quick%20Search%20-%20%E5%BF%AB%E9%80%9F%E6%90%9C%E7%B4%A2%20%28%E4%BF%AE%E5%A4%8D%E7%89%88%29.meta.js // ==/UserScript== (function () { 'use strict'; // --- 配置区域 --- const config = { iconSize: 24, // 图标大小 offsetY: 10, // 图标相对于鼠标的垂直偏移 engines: [ // --- 搜索引擎 --- { name: 'Google', url: 'https://www.google.com/search?q=%s', icon: 'https://www.google.com/favicon.ico' }, { name: 'Baidu', url: 'https://www.baidu.com/s?wd=%s', icon: 'https://www.baidu.com/favicon.ico' }, { name: 'Bing', url: 'https://www.bing.com/search?q=%s', icon: 'https://www.bing.com/favicon.ico' }, { name: 'DuckDuckGo', url: 'https://duckduckgo.com/?q=%s', icon: 'https://duckduckgo.com/favicon.ico' }, { name: 'Yandex', url: 'https://yandex.com/search/?text=%s', icon: 'https://yandex.com/favicon.ico' }, // --- 翻译引擎 --- { // 有道翻译 (大陆首选,速度快,图标稳定) name: 'Youdao Dict', url: 'https://dict.youdao.com/search?q=%s', icon: 'https://shared.ydstatic.com/images/favicon.ico' }, { name: 'Google Translate', url: 'https://translate.google.com/?sl=auto&tl=zh-CN&text=%s&op=translate', icon: 'https://translate.google.com/favicon.ico' }, // --- 其他 --- { name: 'GitHub', url: 'https://github.com/search?q=%s', icon: 'https://github.com/favicon.ico' } ] }; let iconContainer = null; let selectedText = ''; // 初始化 UI function initUI() { iconContainer = document.createElement('div'); iconContainer.id = 'qs-optimized-container'; iconContainer.style.cssText = ` position: absolute; display: none; z-index: 2147483647; background: white; padding: 4px; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.3); border: 1px solid #ccc; white-space: nowrap; font-size: 0; `; // 生成引擎图标 config.engines.forEach(engine => { let img = document.createElement('img'); img.src = engine.icon; img.title = 'Search/Translate with ' + engine.name; img.style.cssText = ` width: ${config.iconSize}px; height: ${config.iconSize}px; margin: 0 4px; cursor: pointer; vertical-align: middle; border-radius: 2px; object-fit: contain; `; // 点击直接新标签打开,避开 Cloudflare img.addEventListener('mousedown', (e) => { e.preventDefault(); e.stopPropagation(); if (selectedText) { let encodedText = encodeURIComponent(selectedText); const finalUrl = engine.url.replace('%s', encodedText); GM_openInTab(finalUrl, { active: true, insert: true }); hideIcons(); } }); // 悬停动画 img.addEventListener('mouseenter', () => { img.style.transform = 'scale(1.1)'; img.style.transition = '0.2s'; }); img.addEventListener('mouseleave', () => { img.style.transform = 'scale(1)'; }); iconContainer.appendChild(img); }); document.body.appendChild(iconContainer); } // 显示图标 function showIcons(x, y) { if (!iconContainer) initUI(); // 边界检测 const containerWidth = config.engines.length * (config.iconSize + 8); if (x + containerWidth > window.innerWidth) { x = window.innerWidth - containerWidth - 10; } iconContainer.style.left = x + 'px'; iconContainer.style.top = (y + config.offsetY) + 'px'; iconContainer.style.display = 'block'; } function hideIcons() { if (iconContainer) { iconContainer.style.display = 'none'; } } function getSelectionText() { let text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return text.trim(); } // 监听划词 document.addEventListener('mouseup', function (e) { if (iconContainer && iconContainer.contains(e.target)) return; setTimeout(() => { let text = getSelectionText(); if (text && text.length > 0) { selectedText = text; showIcons(e.pageX, e.pageY); } else { hideIcons(); } }, 10); }); document.addEventListener('mousedown', function (e) { if (iconContainer && !iconContainer.contains(e.target)) { hideIcons(); } }); initUI(); console.log('Quick Search (License Fixed) loaded.'); })();