Chat Spam Filter For fishtank.live

Remove repeating parts of spam messages in chat window

目前為 2024-11-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Chat Spam Filter For fishtank.live
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Remove repeating parts of spam messages in chat window
// @author       Blungs
// @match        https://*.fishtank.live/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fishtank.live
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to remove repeated phrases
    function removeRepeatedText(text) {
        const words = text.split(' ');
        const seen = {};
        const result = [];

        words.forEach(word => {
            const lowerWord = word.toLowerCase();
            if (!seen[lowerWord]) {
                seen[lowerWord] = true;
                result.push(word);
            }
        });

        return result.join(' ');
    }

    // Function to process and modify chat messages
    function processChatMessage(messageSpan) {
        if (messageSpan && messageSpan.tagName === 'SPAN') {
            const originalText = messageSpan.textContent.trim();
            const filteredText = removeRepeatedText(originalText);

            // Only log if the message has been changed
            if (filteredText !== originalText) {
                messageSpan.textContent = filteredText; // Update the text content
                console.log(`Message changed: "${originalText}" to "${filteredText}"`);
            }
        } else {
            console.warn("Message span is undefined or not a span element.");
        }
    }

    // Function to start observing the chat messages container
    function startObserving() {
        const chatMessagesDiv = document.getElementById('chat-messages');
        if (chatMessagesDiv) {
            const observer = new MutationObserver((mutations) => {
                mutations.forEach((mutation) => {
                    mutation.addedNodes.forEach((node) => {
                        if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'SPAN') {
                            processChatMessage(node); // Process new chat message
                        } else if (node.nodeType === Node.ELEMENT_NODE) {
                            // Check for spans within added elements
                            const spans = node.querySelectorAll('span');
                            spans.forEach(span => {
                                processChatMessage(span);
                            });
                        }
                    });
                });
            });

            observer.observe(chatMessagesDiv, { childList: true, subtree: true });
        } else {
            setTimeout(startObserving, 2000); // Retry every 2 seconds
        }
    }

    // Start the observation process
    startObserving();
})();

QingJ © 2025

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