imbt.one磁力按钮右键菜单

恢复https://imbt.one/磁力按钮右键菜单

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         imbt.one磁力按钮右键菜单
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  恢复https://imbt.one/磁力按钮右键菜单
// @author       superszy
// @match        https://dl.imbt.one/a/*
// @icon         https://imbt.one/favicon.ico
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 配置参数
    const targetSelector = '#magnet-link';
    const checkInterval = 500;

    // 解除右键限制
    function restoreRightClick() {
        const btn = document.querySelector(targetSelector);
        if (!btn) return;

        // 移除oncontextmenu事件绑定
        btn.oncontextmenu = null;

        // 解除事件监听器(使用捕获阶段覆盖)
        btn.addEventListener('contextmenu', e => {
            e.stopImmediatePropagation();
        }, true);
    }

    // 自动检测动态加载
    let timer = setInterval(() => {
        if (document.querySelector(targetSelector)) {
            restoreRightClick();
            clearInterval(timer);
        }
    }, checkInterval);

    // DOM变更监听
    const observer = new MutationObserver(mutations => {
        if (document.querySelector(targetSelector)) {
            restoreRightClick();
            observer.disconnect();
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // 初始执行
    window.addEventListener('load', restoreRightClick);
})();