// ==UserScript== // @name 双击复制选中或段落文本 - 增强版 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 双击时复制选中的文本或段落文本到剪贴板,并在网页右下角显示复制成功提示,尝试绕过复制限制。 // @author Even // @match *://*/* // @grant GM_setClipboard // @grant GM_addStyle // ==/UserScript== (function() { 'use strict'; // 移除复制限制并允许文本选择 document.addEventListener('DOMContentLoaded', function() { GM_addStyle('* { user-select: text !important; }'); }); // 自定义提示样式 GM_addStyle(` .custom-copy-alert { position: fixed; bottom: 20px; right: 20px; padding: 10px 20px; background-color: #4CAF50; color: white; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.2); z-index: 10000; opacity: 0; transition: opacity 0.5s; } `); document.addEventListener('dblclick', function(e) { let text = ''; const selection = window.getSelection().toString(); // 检查是否有选中的文本 if (selection) { text = selection; } else if (e.target.tagName === 'P') { text = e.target.innerText; } if (text) { GM_setClipboard(text, 'text'); showToast('复制成功:' + text); } }); function showToast(message) { const alertBox = document.createElement('div'); alertBox.className = 'custom-copy-alert'; alertBox.textContent = message; document.body.appendChild(alertBox); // 渐显 setTimeout(() => { alertBox.style.opacity = 1; }, 10); // 几秒后消失 setTimeout(() => { alertBox.style.opacity = 0; setTimeout(() => { document.body.removeChild(alertBox); }, 600); // 等待渐隐动画完成 }, 3000); } })();