andrizz / TM_Enhanced_Tranfer_List

// ==UserScript==
// @name         TM_Enhanced_Tranfer_List
// @description  Adds to the transfer list: Routine; Months in column "Age"; latest SI and TI (if a player is transferlisted before the day of training).
// @version      1.1
// @downloadURL  https://openuserjs.org/install/andrizz/TM_Enhanced_Tranfer_List.user.js
// @updateURL    https://openuserjs.org/meta/andrizz/TM_Enhanced_Tranfer_List.meta.js
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @author       andrizz aka banana aka jimmy il fenomeno (based on a script by Jhonatan Bianchi)
// @include      http://trophymanager.com/transfer/*
// @include      https://trophymanager.com/transfer/*
// @grant        all
// @license      MIT
// ==/UserScript==

unsafeWindow.jQuery(document).ajaxComplete(function(event, pippo, settings)
{   
    rebindClicks();
    
    if (settings.url === "/ajax/transfer.ajax.php")
    {
        moreInfos();
    }
});

function rebindClicks()
{
    $.each($('#pages').find('span'), function(index, span) 
    {
        var clickAntigo = $(span).attr('onclick');
		$(span).removeAttr('onclick');
        $(span).off('click');
        $(span).on('click', function()
                   {
                       eval(clickAntigo);
                       moreInfos();
                       rebindClicks();
                   });
	});
}

function moreInfos()
{
    $(".asi2 .routine").remove();
    $("th.align_center").after("<th class='asi2' title='ASI e TI after the training' style='width: 40px; cursor: pointer;''><nobr>ASI 2 (TI)</nobr></th>");
    $("tr.header").append("<th class='routine' title='Routine' style='width: 40px; cursor: pointer;''>Rou</th>");
    var params = "";
	$("div.player_name > a").each(function(e, player)
    {
		params = "player_id="+$(player).attr("player_link"); //player_id=2014919etc..
                    
		var pippo = new XMLHttpRequest(); 
		pippo.open("POST", "https://trophymanager.com/ajax/tooltip.ajax.php", true);
		pippo.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		pippo.onreadystatechange = function()
		{ 
			if (pippo.readyState == 4)
			{
				var risultato = JSON.parse(pippo.responseText);
                
                var testoAsi = $("tr#player_row_" + risultato.player.player_id + " td.align_center.align_right").text();
                var asiInt = testoAsi.replace ("," , "");
                var asi2Int = risultato.player.skill_index.replace ("," , "");
                
                var ruolo = $("tr#player_row_" + risultato.player.player_id + " span.favposition.short.nowrap").text();
                if  (ruolo == "Gk") { 
                    var sk1 =  Math.pow(asiInt * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7)/14*11;
                    var sk2 = Math.pow(asi2Int * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7)/14*11; 
                } else {    
                    var sk1 = Math.pow(asiInt * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7);
                    var sk2 = Math.pow(asi2Int * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7);
                }
                var TI = Math.round((sk2 - sk1)*10);
                
                $("tr#player_row_" + risultato.player.player_id + " td.left + td.align_center").closest("td").append("."+risultato.player.months);
                $("a[player_link=" + risultato.player.player_id + "]").closest("tr").append("<td class='right align_right routine' style='padding-right:5px;'><span>" + risultato.player.routine + "</span></td>");
                if (asi2Int == asiInt) {
                    $("td[id=time_" + risultato.player.player_id + "]").before("<td class='right align_center asi2' style='padding-right:5px;color:gold;'><span>&nbsp;-&nbsp;-&nbsp;-&nbsp;</span></td>");
                } else {
                    $("td[id=time_" + risultato.player.player_id + "]").before("<td class='right align_center asi2' style='padding-right:5px;color:gold;'><span>&nbsp;" + risultato.player.skill_index + " (<b>" +TI+"</b>)</span></td>");
                }
            }
         }
		pippo.send(params);
    });	
  }