jpk100 / AddTeamDetailsToLeaderBoard

// ==UserScript==
// @name        AddTeamDetailsToLeaderBoard
// @namespace   MultiDreamTeams
// @include     https://www.dreamteamfc.com/*
// @include     https://www.dreamteamfc.com/leaderboards/*
// @version     1.16
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==
$(document).ready(function () {
  //loadthe players
var eur="";
  		if  (location.pathname.split('/')[1] === 'europe') {
      			eur="/europe"}
   	if  (location.pathname.split('/')[1] === 'intl') {
      			eur="/intl"}
     
  var jsonP = (function () {
    var jsonP = null;
    $.ajax({
      'async': false,
      'global': false,
      'url': eur+'/json/players',
      'dataType': 'json',
      'success': function (data) {
        jsonP = data;
      }
    });
    return jsonP;
  }) ();
  function oPlayer() {
    this.name = '';
    this.team = 'UKN';
    this.value = 0;
    this.group = 'G';
    this.points = 0;
    this.pickedk = 0;
    this.status = 'RSSUSPEN';
    this.shortname = 'N';
    this.suspended = 'N';
  }
  var oPlayers = new Object;
  /* sets up or updates the player information */
  json_players = jsonP.players;
  json_team = jsonP.team;
  json_group = jsonP.group;
  var iGroupLen = json_group.length;
  while (iGroupLen--) {
    var sGroup = json_group[iGroupLen];
    var plaGroup = json_players[iGroupLen];
    var iPlaLen = plaGroup.length;
    while (iPlaLen--) {
      var currPlayer = plaGroup[iPlaLen];
      var newPlayer = new oPlayer;
      var season = currPlayer[0]
      newPlayer.name = season[1];
      newPlayer.team = json_team[season[2]];
      newPlayer.value = (season[3] / 10).toFixed(1);
      newPlayer.score = season[4];
      newPlayer.status = season[6];
      newPlayer.shortname = season[7];
      newPlayer.points = season[8];
      oPlayers[season[0]] = newPlayer;
    }
  }
  $('.sfdtTable.leagueTable.rowsClickable.sortable, .leagueTable').find('tr').each(function () {
    var url = $(this).attr('data-url'); // for third column
    var th = this
    $.ajax({
      url: url,
      dataType: 'html',
      success: function (response) {
        var p1 = jQuery(response).find('#icon1').attr('plaid')
        var p2 = jQuery(response).find('#icon2').attr('plaid')
        var p3 = jQuery(response).find('#icon3').attr('plaid')
        var p4 = jQuery(response).find('#icon4').attr('plaid')
        var p5 = jQuery(response).find('#icon5').attr('plaid')
        var p6 = jQuery(response).find('#icon6').attr('plaid')
        var p7 = jQuery(response).find('#icon7').attr('plaid')
        var p8 = jQuery(response).find('#icon8').attr('plaid')
        var p9 = jQuery(response).find('#icon9').attr('plaid')
        var p10 = jQuery(response).find('#icon10').attr('plaid')
        var p11 = jQuery(response).find('#icon11').attr('plaid')
        $(th).find('td').eq(2).append($('<div > ' + oPlayers[p1].shortname.split(',') [0] + ' ' + oPlayers[p2].shortname.split(',') [0] + ' ' + oPlayers[p3].shortname.split(',') [0] + ' ' + oPlayers[p4].shortname.split(',') [0] + ' ' + oPlayers[p5].shortname.split(',') [0] + ' '
        + oPlayers[p6].shortname.split(',') [0] + ' ' + oPlayers[p7].shortname.split(',') [0] + ' ' + oPlayers[p8].shortname.split(',') [0] + ' ' + oPlayers[p9].shortname.split(',') [0] + ' '
        + oPlayers[p10].shortname.split(',') [0] + ' ' + oPlayers[p11].shortname.split(',') [0] + '</div>').attr('style', 'font: 13px "Aptifer-Medium" !important'));
      }
    }); //ajax load
    if (url != undefined)
    {
      var viewurl = url.replace('public', 'view')
     // callViewteam(viewurl, th)
      var jsonurl = url.replace('team/public', 'json/history')
      $.ajax({
        url: jsonurl,
        dataType: 'json',
        success: function (response) {
          if (response.WINDOWS[4].TRANSFERS[8].INOUT == 'OUT')
          $(th).find('td').eq(0).append($('<img src=\'http://upload.wikimedia.org/wikipedia/commons/thumb/0/03/Green_check.svg/13px-Green_check.svg.png\'/>'));
         // if (response.WINDOWS[1].TRANSFERS.length != 0)
          //alert('helo')
          //  if(response.WINDOWS[1].TRANSFERS[0].INOUT=='OUT')
          //    $(th).find('td').eq(0).append($("<img src='http://upload.wikimedia.org/wikipedia/commons/thumb/0/03/Green_check.svg/13px-Green_check.svg.png'/>"));
        }
      }); //jsonload
    }
    //if

  }); //eacj
  function callViewteam(url, th) {
    $.ajax({
      url: url,
      dataType: 'html',
      success: function (response) {
        var nxturl = eur+'/team/transfersummary'
        callgetTran(nxturl, th);
      }
    });
  }
  function callgetTran(url, th) {
    $.ajax({
      url: url,
      dataType: 'html',
      success: function (response) {
        var pout = ''
        var pin = '<br>->'
        $(response).find('.pendingSection > .player-row.OUT').each(function (index)
        {
          pout += oPlayers[$(this).attr('plaid')].shortname.split(',') [0] + ','
        }
        )
        $(response).find('.pendingSection > .player-row.IN').each(function (index)
        {
          pin += oPlayers[$(this).attr('plaid')].shortname.split(',') [0] + ','
        }
        )
        if (pout != undefined) {
          $(th).find('td').eq(3).append($('<div > ' + pout + pin +' </div>').attr('style', 'font: 13px "Aptifer-Medium" !important'));
        }
      }
    });
  }
}); //onload