GuangCaiYiYi / 我的世界官网中国区弹窗移除器

// ==UserScript==

// @name         我的世界官网中国区弹窗移除器

// @version      2.1.1

// @description  我的世界官网网易版弹窗剃出

// @author       GuangCaiYiYi

// @match        https://www.minecraft.net/*

// @match        https://minecraft.net/*

// @grant        none

// @run-at       document-start

// @license      MIT

// ==/UserScript==

(function() {

    'use strict';

    // 弹窗元素特征库

    const POPUP_SELECTORS = [

        'div[class*="popup"]',

        'div[class*="modal"]',

        'div[id*="popup"]',

        'div[id*="modal"]',

        'div[class*="overlay"]'

    ];

    // 原生DOM监听方案

    const observer = new MutationObserver(mutations => {

        mutations.forEach(mutation => {

            mutation.addedNodes.forEach(node => {

                if (node.nodeType === 1) {

                    POPUP_SELECTORS.forEach(selector => {

                        if (node.matches(selector)) {

                            node.remove();

                            return;

                        }

                        const elements = node.querySelectorAll(selector);

                        elements.forEach(element => element.remove());

                    });

                }

            });

        });

    });

    // 启动防御系统

    observer.observe(document.documentElement, {

        childList: true,

        subtree: true

    });

    // 主动防御机制

    document.addEventListener('DOMContentLoaded', () => {

        POPUP_SELECTORS.forEach(selector => {

            document.querySelectorAll(selector).forEach(element => {

                element.remove();

            });

        });

    });

    // 实时监控CSS变化

    const styleObserver = new MutationObserver(mutations => {

        mutations.forEach(mutation => {

            if (mutation.type === 'attributes' && mutation.attributeName === 'style') {

                const computedStyle = window.getComputedStyle(mutation.target);

                if (computedStyle.display === 'block' && computedStyle.zIndex > 1000) {

                    mutation.target.remove();

                }

            }

        });

    });

    // 启动CSS监控

    document.querySelectorAll('*').forEach(element => {

        styleObserver.observe(element, { attributes: true });

    });

})();