MWI - Hide Chinese Chat Messages

Hides only new chat messages containing Chinese characters, without affecting the rest of the page.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MWI - Hide Chinese Chat Messages
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Hides only new chat messages containing Chinese characters, without affecting the rest of the page.
// @author       Epsilon
// @match        https://www.milkywayidle.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Chinese character Unicode blocks
    const CHINESE_REGEX = /[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]/;

    // Check text content only
    function containsChineseText(text) {
        return CHINESE_REGEX.test(text);
    }

    // Hide a node if it only contains Chinese text (or includes it)
    function hideIfChinese(node) {
        if (node.nodeType === Node.TEXT_NODE && containsChineseText(node.textContent)) {
            const parent = node.parentElement;
            if (parent) {
                parent.style.display = 'none';
            }
        }
    }

    // Observe only additions of text nodes in the DOM
    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeType === Node.TEXT_NODE) {
                    hideIfChinese(node);
                } else if (node.nodeType === Node.ELEMENT_NODE) {
                    node.querySelectorAll('*').forEach(child => {
                        child.childNodes.forEach(hideIfChinese);
                    });
                }
            }
        }
    });

    // Start observing the entire document, but only for small text updates
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();