lingyaobr / Bloqueio automático de flood no novo chat UOL

// ==UserScript==
// @name         Bloqueio automático de flood no novo chat UOL
// @namespace    http://www.yao-chat.ml
// @version      1.0
// @description  Bloqueia automáticamente usuários que floodam o chat
// @author       Ling Yao
// @match        http://batepapo.uol.com.br/beta/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

// Your code here...

var blockAutoFlood = function(){
	angular.element($('#main_content')).injector().invoke(['$stateParams', 'RoomSocketFactory', function(stateParams, RoomSocketFactory) {
		var userCountFlood = {};
		var secondsToFlood = 30;
		var messagesToFlood = 5;
		var millisecondsToFlood = secondsToFlood * 1000;

		var socket = RoomSocketFactory.get({tab: stateParams.node_id}).connection;
		var originalOnSuccess = socket.onSuccess;
		socket.onSuccess = function(response){
			originalOnSuccess(response);
			var message = JSON.parse(response);
			if(message.messageClass == "ChatMessage"){
				if(!userCountFlood.hasOwnProperty(message.senderNick)){
					userCountFlood[message.senderNick] = {
						count: 1,
						firstMessage: message.date
					};
				} else {
					userCountFlood[message.senderNick].count++;
					if(userCountFlood[message.senderNick].count >= messagesToFlood){
						if(userCountFlood[message.senderNick].firstMessage + millisecondsToFlood > message.date){
							console.log('bloqueando usuário ' + message.senderNick);
							angular.element($('.usernick[title="' + message.senderNick + '"]').next('div').find('.actionBlock')).scope().toggleBlock();
							delete userCountFlood[message.senderNick];
						}
					}
				}
			}
		};
	}]);
}

var autoFloodInterval = setInterval(function(){
	if(document.querySelector('#chatMessageSend')){
        blockAutoFlood();
        clearInterval(autoFloodInterval);
    }
}, 100);