Greasy Fork

Greasy Fork is available in English.

全局解除选中、复制与右键限制

解除所有站点的选中/复制/右键限制

当前为 2025-05-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         全局解除选中、复制与右键限制
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  解除所有站点的选中/复制/右键限制
// @author       yui酱
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 1. 覆盖全局 CSS,恢复文本选中与复制
    const style = document.createElement('style');
    style.textContent = `
        * {
            -webkit-user-select: auto !important;
            -moz-user-select: auto !important;
            -ms-user-select: auto !important;
            user-select: auto !important;
        }
    `;
    document.head.appendChild(style);

    // 2. 解绑可能阻止复制、选中、右键的事件
    const blockEvents = ['copy', 'cut', 'selectstart', 'mousedown'];
    blockEvents.forEach(evt => {
        document.addEventListener(evt, e => e.stopPropagation(), true);
        document[`on${evt}`] = null;
    });

    // 3. 恢复右键菜单
    document.addEventListener('contextmenu', e => e.stopPropagation(), true); // 放行 contextmenu 事件 :contentReference[oaicite:0]{index=0}
    document.body.oncontextmenu = null;
    document.documentElement.oncontextmenu = null;
    document.querySelectorAll('*').forEach(el => {
        if (el.hasAttribute('oncontextmenu')) {
            el.removeAttribute('oncontextmenu');
        }
    });

    // 4. 定义遮罩层清理函数(排除 Bilibili)
    function removeOverlays() {
        // 如果是 Bilibili 视频站点,直接跳过清理,保留弹幕层
        if (/\.bilibili\.com$/.test(location.hostname)) {
            return;
        }
        document.querySelectorAll('body *').forEach(el => {
            const st = window.getComputedStyle(el);
            if ((st.position === 'fixed' || st.position === 'absolute')
                && st.zIndex !== 'auto'
                && st.pointerEvents === 'none'    // 仅移除 pointer-events:none 的遮罩 :contentReference[oaicite:1]{index=1}
                && (st.backgroundColor === 'rgba(0, 0, 0, 0)' || parseFloat(st.opacity) < 0.1)) {
                el.remove();
            }
        });
    }

    // 5. 在页面加载与滚动时触发清理
    window.addEventListener('load', removeOverlays, true);
    window.addEventListener('scroll', removeOverlays, true);
})();