您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
点击复制文本,自定义弹窗提示 + 保存历史 + 按钮增强
当前为
// ==UserScript== // @name 智能复制助手 Pro(自定义弹窗 + 历史 + 按钮) // @namespace http://tampermonkey.net/ // @version 2.5 // @description 点击复制文本,自定义弹窗提示 + 保存历史 + 按钮增强 // @author ChatGPT // @match *://*/* // @grant GM_setClipboard // @grant GM_addStyle // ==/UserScript== (function () { 'use strict'; const historyLimit = 10; let copyHistory = []; // 样式注入:按钮 + 弹窗 GM_addStyle(` .copy-btn { position: absolute; right: 0; top: 0; background: #4CAF50; color: white; border: none; padding: 2px 6px; font-size: 12px; cursor: pointer; border-radius: 4px; z-index: 10000; } .copy-container { position: relative; display: inline-block; } .copy-toast { position: fixed; top: 20px; right: 20px; background: #323232; color: #fff; padding: 12px 18px; border-radius: 6px; box-shadow: 0 0 10px rgba(0,0,0,0.3); z-index: 10000; opacity: 0; transition: opacity 0.4s ease, transform 0.4s ease; transform: translateY(-10px); font-family: Arial; } .copy-toast.show { opacity: 1; transform: translateY(0); } `); // 创建弹窗 DOM const toast = document.createElement('div'); toast.className = 'copy-toast'; document.body.appendChild(toast); const showToast = (text) => { toast.innerText = `✅ 已复制:${text}`; toast.classList.add('show'); setTimeout(() => { toast.classList.remove('show'); }, 2000); }; const addToHistory = (text) => { if (copyHistory.includes(text)) return; copyHistory.unshift(text); if (copyHistory.length > historyLimit) copyHistory.pop(); console.log('📋 当前复制历史:', copyHistory); }; const copyToClipboard = (text) => { if (!text || !text.trim()) return; if (navigator.clipboard) { navigator.clipboard.writeText(text).catch(console.error); } else { GM_setClipboard(text); } showToast(text); addToHistory(text); }; const getCopyText = (el) => { const tag = el.tagName.toLowerCase(); if (tag === 'input' || tag === 'textarea') return el.value; return el.innerText || el.textContent; }; const injectCopyButtons = () => { const tags = ['p', 'span', 'div', 'li', 'td', 'pre']; tags.forEach(tag => { const elements = document.querySelectorAll(tag); elements.forEach(el => { if (el.dataset.copyBound) return; el.dataset.copyBound = '1'; const wrapper = document.createElement('span'); wrapper.classList.add('copy-container'); el.parentNode.insertBefore(wrapper, el); wrapper.appendChild(el); const btn = document.createElement('button'); btn.className = 'copy-btn'; btn.innerText = '复制'; btn.addEventListener('click', (e) => { e.stopPropagation(); const text = getCopyText(el); copyToClipboard(text); }); wrapper.appendChild(btn); }); }); }; // 初始化 injectCopyButtons(); setInterval(injectCopyButtons, 3000); // 快捷键 Ctrl+Shift+H 显示历史 document.addEventListener('keydown', (e) => { if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'h') { alert('📋 最近复制内容:\n' + copyHistory.join('\n')); } }); })();