Greasy Fork

【最强】【持续更新】解除禁止复制和粘贴限制并支持手动粘贴(全网页适用)

破解所有网站【禁止复制】和【禁止粘贴】限制,支持【模拟人工输入】。安装后,打开目标网页即可解除限制。若不生效,可以使用ctrl+m呼出浮动输入框进行模拟人工输入,详情请阅读下方说明。有疑问或者反馈都可以发我邮箱啊:[email protected]

目前为 2024-11-06 提交的版本。查看 最新版本

// ==UserScript==
// @name         【最强】【持续更新】解除禁止复制和粘贴限制并支持手动粘贴(全网页适用)
// @namespace    http://jiangning_sama/pojie_cpoy.net/
// @version      7.0.0
// @description  破解所有网站【禁止复制】和【禁止粘贴】限制,支持【模拟人工输入】。安装后,打开目标网页即可解除限制。若不生效,可以使用ctrl+m呼出浮动输入框进行模拟人工输入,详情请阅读下方说明。有疑问或者反馈都可以发我邮箱啊:[email protected]
// @author       江宁sama
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function unlockCopyPaste() {
        document.body.removeAttribute('onselectstart');
        document.body.style.userSelect = 'auto';
        document.documentElement.style.userSelect = 'auto';
        document.querySelectorAll('*').forEach((el) => {
            el.style.userSelect = 'auto';
            el.style.pointerEvents = 'auto';
            el.removeAttribute('oncopy');
            el.removeAttribute('oncut');
            el.removeAttribute('onpaste');
            el.removeAttribute('oncontextmenu');
            el.removeAttribute('onmousedown');
            el.removeAttribute('onselectstart');
            el.oncopy = null;
            el.oncut = null;
            el.onpaste = null;
            el.oncontextmenu = null;
            el.onmousedown = null;
            el.onselectstart = null;
            if (el.classList.contains('hljs-button') && el.dataset.title === "登录复制") {
                el.style.display = 'none';
            }
        });
        const eventTypes = ['copy', 'cut', 'paste', 'contextmenu', 'selectstart', 'mousedown'];
        eventTypes.forEach((eventType) => {
            document.addEventListener(eventType, (e) => e.stopPropagation(), true);
        });
        console.log("已解除页面的禁止复制和粘贴限制");
    }

    function init() {
        unlockCopyPaste();
    }
    setInterval(init, 3000);

    // 新增手动粘贴功能
    let targetElement = null;  

    document.addEventListener('keydown', function(event) {
        if (event.ctrlKey && event.key === 'm') {
            event.preventDefault();

       
            targetElement = document.activeElement;
            createFloatingInputBox();  
        }
    });

   
    function createFloatingInputBox() {
        if (document.getElementById('floatingInputBox')) return; 

        const floatingBox = document.createElement('div');
        floatingBox.id = 'floatingInputBox';
        floatingBox.style.position = 'fixed';
        floatingBox.style.top = '20px';
        floatingBox.style.right = '20px';
        floatingBox.style.width = '300px';
        floatingBox.style.padding = '10px';
        floatingBox.style.backgroundColor = 'white';
        floatingBox.style.border = '1px solid black';
        floatingBox.style.zIndex = '10000';

        const textarea = document.createElement('textarea');
        textarea.style.width = '100%';
        textarea.style.height = '80px';
        textarea.placeholder = '在此粘贴内容,然后按 Enter';
        textarea.addEventListener('keydown', function(e) {
            if (e.key === 'Enter') {
                e.preventDefault();
                const text = textarea.value;
                document.body.removeChild(floatingBox);
                if (targetElement) {
                    typeTextSlowly(targetElement, text);
                }
            }
        });

        floatingBox.appendChild(textarea);
        document.body.appendChild(floatingBox);
        textarea.focus();
    }

    // 逐字输出文本内容
    function typeTextSlowly(element, text) {
        let i = 0;

        function typeChar() {
            if (i < text.length) {
                insertChar(element, text[i]);
                i++;
                setTimeout(typeChar, 20);
            }
        }
        typeChar();
    }
    function insertChar(element, char) {
        if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
            const start = element.selectionStart;
            const end = element.selectionEnd;
            const value = element.value;

            element.value = value.substring(0, start) + char + value.substring(end);
            element.selectionStart = element.selectionEnd = start + 1;

            const inputEvent = new Event('input', { bubbles: true });
            element.dispatchEvent(inputEvent);
        } else if (element.isContentEditable) {
            const textNode = document.createTextNode(char);
            const selection = window.getSelection();
            const range = selection.getRangeAt(0);

            range.insertNode(textNode);
            range.setStartAfter(textNode);
            selection.removeAllRanges();
            selection.addRange(range);
        }
    }
})();