油猴脚本 - 破解网页输入框禁止粘贴进去内容

油猴脚本,同时使用6种方法进行破解,能破解网页中绝大多数禁止粘贴的输入框,只要再油猴里新建然后将代码复制进去即可。

@match 后面的是要生效的网址

// ==UserScript==
// @name         允许输入框粘贴内容
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在所有网页上允许输入框粘贴内容
// @author       您的名字
// @match        http://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 方法 1: 移除 oncopy, oncut, onpaste 事件
    document.body.setAttribute('oncopy', '');
    document.body.setAttribute('oncut', '');
    document.body.setAttribute('onpaste', '');

    // 方法 2: 移除所有元素的事件监听器
    const removeEventListeners = (el) => {
        el.removeAttribute('onpaste');
        el.removeAttribute('oncopy');
        el.removeAttribute('oncut');
    };

    // 遍历所有元素
    const allElements = document.querySelectorAll('*');
    allElements.forEach(el => removeEventListeners(el));

    // 方法 3: 使用事件捕获阶段来覆盖事件
    document.addEventListener('copy', (e) => { e.stopPropagation(); }, true);
    document.addEventListener('paste', (e) => { e.stopPropagation(); }, true);
    document.addEventListener('cut', (e) => { e.stopPropagation(); }, true);

    // 方法 4: 更改样式,尝试解除限制
    const styles = `*:not(input):not(textarea) {
        -webkit-user-select: text !important;
        -moz-user-select: text !important;
        -ms-user-select: text !important;
        user-select: text !important;
    }`;

    const styleSheet = document.createElement("style");
    styleSheet.type = "text/css";
    styleSheet.innerText = styles;
    document.head.appendChild(styleSheet);

    // 方法 5: 解除可能被设置的只读属性
    const inputs = document.querySelectorAll('input, textarea');
    inputs.forEach(input => {
        input.removeAttribute('readonly');
        input.removeAttribute('disabled');
    });

    // 方法 6: 使用定时器不断尝试解除限制
    setInterval(() => {
        allElements.forEach(el => removeEventListeners(el));
        inputs.forEach(input => {
            input.removeAttribute('readonly');
            input.removeAttribute('disabled');
        });
    }, 1000); // 每秒尝试一次

})();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值