Discord 隐藏掉屏蔽别人后的提醒

移除 Discord 页面中屏蔽后别人信息的提醒 Remove the notification of blocked messages from others on the Discord page

// ==UserScript==
// @name         Discord 隐藏掉屏蔽别人后的提醒
// @description  移除 Discord 页面中屏蔽后别人信息的提醒 Remove the notification of blocked messages from others on the Discord page
// @version      1.0
// @author       Zola
// @match        https://discord.com/*
// @grant        none
// @run-at       document-end
// @license      MIT
// @namespace https://gf.qytechs.cn/users/789414
// ==/UserScript==

(function() {
    'use strict';

    // 判断元素类名是否包含指定前缀
    function hasClassPrefix(el, prefix) {
        if (!el.classList) return false;
        for (const c of el.classList) {
            if (c.startsWith(prefix)) return true;
        }
        return false;
    }

    // 判断元素内部是否包含某个类名前缀的子元素
    function containsChildWithClassPrefix(el, prefix) {
        const children = el.querySelectorAll('*');
        for (const child of children) {
            if (hasClassPrefix(child, prefix)) return true;
        }
        return false;
    }

    // 主函数,查找并移除目标元素
    function removeTargetElements() {
        // 选择所有 class 属性包含 groupStart__ 的 div
        const candidates = document.querySelectorAll('div[class*="groupStart__"]');
        for (const el of candidates) {
            if (containsChildWithClassPrefix(el, 'blockedMessageText__')) {
                el.remove();
                // 如果需要调试可取消注释
                // console.log('Removed element:', el);
            }
        }
    }

    // 初始运行一次
    removeTargetElements();

    // 监听 DOM 变化,动态处理新增元素
    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            if (mutation.addedNodes.length > 0) {
                removeTargetElements();
                break;
            }
        }
    });

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址