Twitch Chat Deretardifier

removes idiocy

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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;
    }
})();