Force Enable Selection & Right-Click

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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';
    });
})();