playerx / Skill Index Calculator

// ==UserScript==
// @name       Skill Index Calculator
// @namespace  http://playerx.hitwicket.com/
// @version    4.1
// @description  Script to calculate skill index of team (total and top 11)
// @include      http*://*hitwicket.com/transfer/index*
// @include	   http*://*hitwicket.com/premium/players/index*
// @include	   http*://*hitwicket.com/players/index*
// @copyright  2012+, PlayerX
// ==/UserScript==

function interceptAjax () {
    var playerList = [];
    
    function getPlayerList() {
        $(".tutorial_player").each(function() {
            
        });
    }
    
    function updateSkillIndexCalculation() {
        if($("#skillPoints").size() == 0) {
            var element = $("div#players_list").first();
            $("<div class='row-fluid clearfix'><div class='col-md-12'><div id='skillPoints'><span id='points' style='background-color:#f93;color:#fff;padding:10px;margin-right:10px;width:230px;font-size:1.4em;'></span><span id='top11points' style='background-color:#428bca;color:#fff;padding:10px;width:230px;font-size:1.4em;'></span></div></div></div>").prependTo(element);    
        }
       
        var totalSkillIndex = 0;
        var skillIndexArray = [];
        var top11TotalSkillIndex = 0;
        $( "div.new_player_card" ).each(function() {
            var elementSkillIndex = $(this).find("div.skill_value span")[0];
            /*
            var skillIndexNumber = 2;
            if(elementSkillIndex.size() == 0) {
                elementSkillIndex = $(this).find(".side-skills,.dark").first();
                skillIndexNumber = 3;
            }*/
            //var skillIndex = $($(elementSkillIndex).find("strong")[skillIndexNumber]).html();            
            var skillIndex = $(elementSkillIndex).html();
            skillIndex = skillIndex.split(",");
            skillIndex = skillIndex[0] + skillIndex[1];
            //console.debug("Skill Index:" + skillIndex)
            skillIndexArray.push(parseInt(skillIndex));
            totalSkillIndex += parseInt(skillIndex);            
        });
        skillIndexArray.sort(function(a, b){return b-a});
		skillIndexArray = skillIndexArray.slice(0,11);
        $.each( skillIndexArray, function( index, value ) {
			top11TotalSkillIndex += value;
		});
        $("#points").html("Total Skill Index: " + totalSkillIndex.toLocaleString() );
        $("#top11points").html("Top 11 Skill Index: " + top11TotalSkillIndex.toLocaleString() );
        
    }

    $("body").ajaxSuccess (
        function (event, requestData)
        {
            updateSkillIndexCalculation();
        }
    );
    updateSkillIndexCalculation();
}

function addJS_Node (text, s_URL, funcToRun) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    scriptNode.type                         = "text/javascript";
    if (text)       scriptNode.textContent  = text;
    if (s_URL)      scriptNode.src          = s_URL;
    if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';

    var targ    = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}

addJS_Node ("updateSkillIndexCalculation", null, interceptAjax);
interceptAjax();