复制拦截

使用系统弹窗的复制控制方案

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         复制拦截
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  使用系统弹窗的复制控制方案
// @author       百合是人类文明的瑰宝
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_notification
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    
    // 存储配置
    const isAutoMode = GM_getValue('copyAutoMode', false);
    let copyLock = false;

    // 创建菜单项
    GM_registerMenuCommand('📱 切换自动复制', () => {
        const newMode = !GM_getValue('copyAutoMode', false);
        GM_setValue('copyAutoMode', newMode);
        GM_notification({
            text: `自动复制已${newMode ? '启用' : '关闭'}`,
            timeout: 2000
        });
    });

    // 解除事件限制
    const nativeAddEventListener = EventTarget.prototype.addEventListener;
    EventTarget.prototype.addEventListener = function(type, listener, options) {
        const blockEvents = ['copy','cut','contextmenu','selectstart','touchstart'];
        if(blockEvents.includes(type)){
            const wrapper = e => {
                e.stopImmediatePropagation();
                return listener(e);
            };
            return nativeAddEventListener.call(this, type, wrapper, options);
        }
        return nativeAddEventListener.apply(this, arguments);
    };

    // 处理复制操作
    document.addEventListener('copy', function(e) {
        if(copyLock || isAutoMode) return;
        
        e.preventDefault();
        const selection = window.getSelection().toString();
        
        // 三星原生弹窗交互
        const confirmCopy = confirm(`检测到复制操作\n\n"${selection.slice(0,30)}..."\n\n允许复制吗?`);
        
        if(confirmCopy) {
            copyLock = true;
            e.clipboardData.setData('text/plain', selection);
            setTimeout(() => copyLock = false, 500);
        }
    }, true);

    // 强制解除CSS限制
    const styleWatcher = setInterval(() => {
        ['user-select','-webkit-user-select'].forEach(prop => {
            document.body.style.setProperty(prop, 'auto', 'important');
        });
    }, 800);
    
    // 清理定时器
    document.addEventListener('DOMContentLoaded', () => {
        clearInterval(styleWatcher);
    }, {once: true});
})();