解除网页限制工具(复制、切屏、全屏)-By丁大大

解除网页对切屏、复制和全屏的限制

// ==UserScript==
// @name         解除网页限制工具(复制、切屏、全屏)-By丁大大
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  解除网页对切屏、复制和全屏的限制
// @author       丁大大18643100778
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 解除复制限制
    function enableCopy() {
        // 移除禁止复制的事件监听
        document.addEventListener('copy', function(e) {
            e.stopPropagation();
        }, true);

        document.addEventListener('cut', function(e) {
            e.stopPropagation();
        }, true);

        document.addEventListener('paste', function(e) {
            e.stopPropagation();
        }, true);

        // 移除禁用选择的CSS和属性
        document.querySelectorAll('*').forEach(el => {
            el.style.userSelect = 'text !important';
            el.style.webkitUserSelect = 'text !important';
            el.style.MozUserSelect = 'text !important';
            el.style.msUserSelect = 'text !important';
            el.style.webkitTouchCallout = 'default !important';
            el.onselectstart = null;
            el.oncontextmenu = null;
        });

        // 移除禁用选择的属性
        if (document.body) {
            document.body.style.userSelect = 'text';
            document.body.style.webkitUserSelect = 'text';
            document.body.onselectstart = null;
        }
    }

    // 解除切屏/标签页切换检测
    function disableBlurDetection() {
        window.addEventListener('blur', function(e) {
            e.stopImmediatePropagation();
        }, true);

        Object.defineProperty(document, 'hidden', {
            get: function() { return false; }
        });

        Object.defineProperty(document, 'visibilityState', {
            get: function() { return 'visible'; }
        });

        // 覆盖可能存在的检测函数
        if (window.addEventListener) {
            const originalAddEventListener = window.addEventListener;
            window.addEventListener = function(type, listener, options) {
                if (type === 'visibilitychange' || type === 'blur' || type === 'focus') {
                    return;
                }
                originalAddEventListener.call(window, type, listener, options);
            };
        }
    }

    // 解除全屏限制
    function enableFullscreen() {
        // 覆盖全屏API检查
        if (Element.prototype.requestFullscreen) {
            const originalRequestFullscreen = Element.prototype.requestFullscreen;
            Element.prototype.requestFullscreen = function() {
                return originalRequestFullscreen.call(this);
            };
        }

        // 覆盖webkit全屏API
        if (Element.prototype.webkitRequestFullscreen) {
            const originalWebkitRequestFullscreen = Element.prototype.webkitRequestFullscreen;
            Element.prototype.webkitRequestFullscreen = function() {
                return originalWebkitRequestFullscreen.call(this);
            };
        }

        // 移除全屏变化事件监听
        document.addEventListener('fullscreenchange', function(e) {
            e.stopImmediatePropagation();
        }, true);

        document.addEventListener('webkitfullscreenchange', function(e) {
            e.stopImmediatePropagation();
        }, true);
    }

    // 执行所有解除限制的函数
    function removeAllRestrictions() {
        enableCopy();
        disableBlurDetection();
        enableFullscreen();
    }

    // 页面加载完成后执行
    window.addEventListener('load', function() {
        removeAllRestrictions();
    });

    // 立即执行一次
    removeAllRestrictions();

    // 使用MutationObserver监测DOM变化,持续解除限制
    const observer = new MutationObserver(function(mutations) {
        removeAllRestrictions();
    });

    observer.observe(document, {
        childList: true,
        subtree: true,
        attributes: true,
        characterData: true
    });
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。