// ==UserScript== // @name 防止未经授权的自动复制 // @version 1 // @description 在将内容复制到剪贴板之前提示用户以防止未经授权的自动复制。 // @author ChatGPT定制 // @match *://*/* // @grant GM_setClipboard // @run-at document-start // @namespace https://greasyfork.org/users/452911 // @downloadURL none // ==/UserScript== (function() { // 匿名函数开启脚本 'use strict'; // 启用严格模式 const listener = function(event) { // 复制事件的监听器函数 event.preventDefault(); // 取消默认行为 const selection = window.getSelection().toString(); // 获取鼠标选取的内容 const shouldCopy = confirm("是否复制?\n" + selection); // 弹出提示窗口询问用户是否复制该文本 if (shouldCopy) { // 如果应该复制 GM_setClipboard(selection); // 使用 GM_setClipboard 函数将内容复制到剪贴板 } else { // 否则 document.execCommand('copy'); // 使用 Document.execCommand 函数复制内容 document.removeEventListener('copy', listener); // 移除复制事件监听器 document.execCommand = function() { // 重置执行该命令的函数 return true; }; } }; document.addEventListener('copy', listener); // 监听复制事件 })();