双击复制选中文本
// ==UserScript==
// @name 双击复制选中文本
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 双击时复制选中的文本到剪贴板,并在网页右下角显示复制成功提示,尝试绕过复制限制,选中链接则在新页面打开。
// @author Even
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAFfBJREFUeF7tXV+IXkcVP/fb9EFIgpJaAkntLqL0IQ+KmLZCybdtkYIv2yI0PrSbBYuilSqotIV0Nw3+Kb5YWsFSIZsitEIlqz4J2t1Q1DZ96UPAvu0XsktD2mhJAr5kv+s3d7+b3r13Zs6ZuXO/O3fmfG/Jzt9zzu+eP3PmTAL8YwowBZQUSJg2TAGmgJoCDBCWDqaAhgIMEBYPpgADhGWAKWBHAdYgdnTjXpFQgAESCaN5m3YUYIDY0Y17RUIBBkgkjOZt2lGAAWJHN+4VCQUYIJEwmrdpRwEGiB3duFckFGCARMJo3qYdBRggdnTjXpFQgAESCaN5m3YUYIDY0Y17RUIBBkgkjOZt2lGAAWJHN+4VCQUYIJEwmrdpRwEGiB3duFckFGCARMJo3qYdBRggdnTT9lrqr08DwPQWwHQCcIdonPRgepiC+H9IAKZTgEEvgYH4dzqEQQpwYQq2/720NrPWwLJ4SAsKMEAsiFbuIgAxBJhPE+gnAH0HQ4ohBkkCa8MhnD25NrPsaEwexpACDBBDguXNc1BAAseEtrAchtpNaJgBpHB6CmBtaW0m0zT8a54CDBADGhdAsWTQrYmmAizLPYDTDJYmyPvJmAwQAn0FMLYSOOXQfCLMSmqSAeW5tZkTpNbcyJgCDBANyQQw0h4spmlmRtX9ZWZS7pgXHXYHJhoDpS53FP0ZIBLC1DClMkEtRKQGVBOoGPnKlpTAvIXGYqA4BgoDpETQZ/vri6M4rImPkfsDZ12HZzPTDqDf68ERQy026KWw4Ho9jmWvE8MxQMZsMvQzJu4kW4ElhSX2T+rhkAEyot9Sf70/TGCVQEovTBgTEzBJYPnEmzMLhL1xEwk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QtjnA83tNAQaI1+zhxbVNAQZI2xzg+b2mAAPEa/bw4tqmAAOkbQ7w/F5TgAHiNXt4cW1TgAHSNgd4fq8pwADxmj28uLYpwABpmwM8v9cU+D/tdPybhvxEDgAAAABJRU5ErkJggg==
// @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('click', function (e) {
var selectedText = window.getSelection().toString().trim();
// 判断选中的文本是否为URL
if (selectedText && /^(http|https):\/\/[^\s]+$/.test(selectedText)) {
// 如果是URL,则在新标签页中打开
window.open(selectedText, '_blank');
}
});
// 监听双击事件
document.addEventListener('dblclick', function (e) {
var selectedText = window.getSelection().toString().trim();
// 双击复制文本
GM_setClipboard(selectedText);
showToast('复制成功:' + selectedText);
});
// 显示提示信息
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);
}
})();