MWI - Hide Chinese Chat Messages

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
    });

})();