// ==UserScript== // @name 防止未经授权的自动复制 // @version 5 // @description 在将内容复制到剪贴板之前提示用户以防止未经授权的自动复制。 // @grant GM_setClipboard // @run-at document-start // @match *://*/* // @namespace https://greasyfork.org/users/452911 // @downloadURL none // ==/UserScript== (function() { 'use strict'; let hasCopied = false; let allowCopy = true; const handleCopy = function(event) { if (!allowCopy) return; event.preventDefault(); const selection = window.getSelection().toString(); const shouldCopy = hasCopied ? true : confirm('是否复制?\n' + selection); if (shouldCopy) { hasCopied = true; GM_setClipboard(selection); } else { document.execCommand = function() { return true; }; } }; const handleSelectionChange = function() { allowCopy = false; setTimeout(() => { allowCopy = true; }, 300); const selection = window.getSelection().toString(); if (selection.length > 0) { document.removeEventListener('copy', handleCopy); } else { document.addEventListener('copy', handleCopy); } }; document.addEventListener('selectionchange', handleSelectionChange); document.addEventListener('copy', handleCopy); })();