playerx / Bot finder - 2

// ==UserScript==
// @name       Bot finder - 2
// @namespace  http://playerx.hitwicket.com/
// @version    1.1
// @description  Script to find bot in leagues
// @include      http://*hitwicket.com/discussionForum/91902*
// @copyright  2014+, PlayerX
// ==/UserScript==
 console.debug("loaded botfinderv.2");

$(".thread_content").html("");
$(".thread_content").append("<div>Finding bots in lower divisions (5, 6 and 7) takes more time, so please be patient.</div><div><br></div>" +

"<div>" +
  "<select id='divisionid'>" +
  "<option value='1'>Division 1</option>" +
  "<option value='2'>Division 2</option>" + 
  "<option value='3'>Division 3</option>" + 
  "<option value='4'>Division 4</option>" + 
  "<option value='5'>Division 5</option>" + 
  "<option value='6'>Division 6</option>" + 
  "<option value='7'>Division 7</option>" + 
 "</select>" +

  "<button id='findbots'>Find Bots</button>" + 
  "<div class='loader' style='display: none;text-align:center;' align='center'><img src='/images/ajax-loader.gif'></div>" + 
  "<br>" +
  "<div id='botinfo' style='font-size:18px;color:red;'></div>" + 
  "</div>"); 
var divisions = ["I","II","III","IV","V","VI","VII"];
    var division;
 var totalLeagues;
function startBotSearch() {
    $('#findbots').attr('disabled','disabled');
  var currentLeague = 1;
    	$("div#botinfo").html("");
  		division = $("#divisionid").val();
       totalLeagues = Math.pow(4,division-1);
    	console.debug($("#divisionid").val());
       findBots(currentLeague);
    }
    
    function findBots(currentLeague) {    
    console.debug("inside findBots");
    $(".loader").show();
    var url = "http://hitwicket.com/league/show/" ;   
    var currentLeagueName = divisions[division-1] + "-" + currentLeague;
    var leagueUrl = url + currentLeagueName;
    console.debug("before request");
    $.ajax({
      url: leagueUrl,
      cache: false,
        beforeSend: function( xhr ) {
            $(".loader").show();
        }
    })
      .done(function( html ) {          
          console.debug(currentLeagueName + ":" + $(html).find("a.bot_team_name").size());
    var count = $(html).find("a.bot_team_name").size();
    var disp =  "<a href='" + leagueUrl + "'>Go to " + currentLeagueName + "</a>" + ":  " + count + " bot(s)";
    if(count > 0) {
          var ele = "<div>" + disp + "</div>";
          $("div#botinfo").append(ele);
    }
          currentLeague++;
          if(currentLeague > totalLeagues) {
               $(".loader").hide();
             $('#findbots').removeAttr('disabled');
              return;
          }
          else {
           	findBots(currentLeague);   
          }
        
    });    
  }    
$("#findbots").click(function(event){
        startBotSearch();
    }
);