Twitch Chat Deretardifier

removes idiocy

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitch Chat Deretardifier
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  removes idiocy
// @author       hello_frenz
// @match        https://www.twitch.tv/*
// @grant        none
// ==/UserScript==

var censorCount = 0;
var debugMode = false;
var logMessages = false;

(function() {
    'use strict';

    var log;
    var interval = setInterval(function(){
        log = document.querySelectorAll('[role="log"]');
        if (log.length > 0){
            addListener(log[0]);
            clearInterval(interval);
        }
    }, 100);

    function addListener(log){
        var observer = new MutationObserver(checkMessage);
        observer.observe(log, {childList: true});
    }

    function checkMessage(mutation){
        for (var i = 0; i < mutation.length; i++){
            var newMessage = mutation[i].addedNodes[0];
            if (newMessage){
                if (containsSpam(newMessage.innerText.split(':')[1])){
                    censorCount++;
                    if (debugMode){
                        newMessage.style.border = "1px solid red";
                    }
                    else{
                        newMessage.style.display = "none";
                    }

                    if (logMessages){
                        console.log("message removed = " + newMessage.innerHTML);
                    }
                    console.log(censorCount + " messages removed");
                }
            }
        }
    }

    function containsSpam(text){
        var spamFound = false;
        if (text){
            spamFound = checkAllCaps(text);
        }
        return spamFound;
    }

    function checkAllCaps(text){
        var textLength = text.length;
        var amountUpperCaseInt = 0;
        for (var i = 0, len = textLength; i < len; i++) {
            var char = text[i];
            if(char === char.toUpperCase()){
                amountUpperCaseInt++;
            }
        }
        var percentageUpperCase = 100 - (textLength - amountUpperCaseInt) / textLength * 100;
        return percentageUpperCase >= 80;
    }
})();