Zaikantos / PurgeGordon

// ==UserScript==
// @name      PurgeGordon
// @description  No more gordon messages after the initial load of messages
// @version    1.00
// @match      http://*.minethings.com/miners/list_miners
// @grant        none
// @author       Zaikantos
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==


(function() {
    'use strict';
    //make JQuery work
    jQuery.noConflict();

    
    //stop chat updater
    pex.stop();

    //chat updater script in page
    //see source of *.minethings.com/miners/list_miners
    var script = document.getElementById("fullcenter").childNodes[1].childNodes[7].innerHTML;
        
    //grab user's numerical ID, as this is used in the updater to not print your own messages
    var index = script.indexOf("chat.minerId !=")+16;
    var stringWithIndex = script.substring(index);
    var userID = stringWithIndex.substring(0, stringWithIndex.indexOf(")"));

    
    //We use this instead of a JQuery call in the PeriodicalExecuter
    var chatsDiv = document.getElementById("ChatsDiv");
    
    //new PeriodicalExecuter
    //mostly identical to the one found in the source of the HTML, with an extra if statement to check for gordon and no more jquery
    var chat = new PeriodicalExecuter(function(pe) { 
        new Ajax.Request("/php/getChats.php?lastChatId="+lastChatId, {
            asynchronous:true, evalScripts:true, onComplete:function(request, json) {
                //We don't use evalJSON because greasemonkey doesn't like it
                data = jQuery.parseJSON(request.responseText)
                if (lastChatId != data.lastChatId)	
                    for (var i = 0; i < data.chats.length; i++) {		
                        chat = data.chats[i];		
                        //new line, removes gordonstretch from chat
                        if(chat.minerName != "gordonstretch") {
                            if (lastChatId == 0 || chat.minerId != userID) { //uses userID
                                if (chatIgnores.indexOf(chat.minerName) == -1)	
                                    chatsDiv.insert(chat.text);			
                                else				
                                    chatsDiv.insert("<div style=\"display:inline;font-size:6px;\">[ignored] </div>");		
                            }	
                        }
                    }
                if (data.timestamp != undefined)	
                    timestamp = data.timestamp;
                lastChatId = data.lastChatId;
                UpdateTimestamp("timestamp");
                if (atBottom) 	
                    new Effect.Tween("ChatsDiv", chatsDiv.scrollTop, chatsDiv.scrollHeight, {duration: 1.0}, "scrollTop");
            }
        }); 					
        atBottom = (lastChatId == 0 || chatsDiv.scrollTop >= (chatsDiv.scrollHeight - 510));}, 3);

    //run PeriodicalExecuter
    chat.execute();
})();