Force Enable Selection & Right-Click

Re-enables text selection and right-click on restrictive websites

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Force Enable Selection & Right-Click
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Re-enables text selection and right-click on restrictive websites
// @author       Your Name
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // ===== 1. FORCE ENABLE TEXT SELECTION =====
    const enableSelection = () => {
        const style = document.createElement('style');
        style.textContent = `
            * {
                user-select: auto !important;
                -webkit-user-select: auto !important;
                -moz-user-select: text !important;
                -ms-user-select: auto !important;
            }
        `;
        document.head.appendChild(style);
    };

    // ===== 2. REMOVE ANTI-SELECTION EVENT LISTENERS =====
    const removeBlockingListeners = () => {
        const events = ['selectstart', 'mousedown', 'dragstart', 'contextmenu', 'copy', 'cut'];
        events.forEach(event => {
            document.addEventListener(event, e => {
                e.stopPropagation();
                e.stopImmediatePropagation();
            }, true); // Use CAPTURING phase to block early
        });
    };

    // ===== 3. RE-ENABLE RIGHT-CLICK (CONTEXT MENU) =====
    const enableRightClick = () => {
        document.oncontextmenu = null;
        document.addEventListener('contextmenu', e => {
            e.stopPropagation();
        }, true);

        // Remove annoying "Right-click disabled" popups
        const removeNoClickPopups = () => {
            document.querySelectorAll('*').forEach(el => {
                if (getComputedStyle(el).cursor === 'none') {
                    el.style.cursor = 'auto !important';
                }
                if (el.oncontextmenu === false || el.hasAttribute('oncontextmenu')) {
                    el.removeAttribute('oncontextmenu');
                    el.oncontextmenu = null;
                }
            });
        };
        removeNoClickPopups();
    };

    // ===== 4. RUN IMMEDIATELY & AFTER PAGE LOAD =====
    enableSelection();
    removeBlockingListeners();
    enableRightClick();

    window.addEventListener('load', () => {
        enableSelection();
        enableRightClick();
    });

    // Continuously check for new elements (for SPAs like React/Angular)
    setInterval(() => {
        enableRightClick();
    }, 1000);
    // Remove iframes blocking selection (common in document viewers)
    document.querySelectorAll('iframe').forEach(iframe => {
        iframe.style.pointerEvents = 'auto !important';
    });
})();