MediaWiki:LeaderFinder

 Search Monster ID   (function LeaderFinder {   if (typeof jQuery == 'undefined') {        setTimeout(LeaderFinder, 100);        return;    }    if(typeof jQuery.tablesorter == 'undefined') {        setTimeout(LeaderFinder, 100);        return;    }    if (typeof mw == 'undefined') {        setTimeout(LeaderFinder, 100);        return;    }    if (typeof mw.user.anonymous == 'function');    else {        setTimeout(LeaderFinder, 100);        return;    }    if(mw.user.anonymous){$('#leader_finder_status').text('Please login to Wikia first');return;}    $.get('http://towerofsaviors.wikia.com/api.php',{ format: 'json', action: 'query', list: 'blocks', bkprop: 'user' },function(data){ var blockedUser = []; var tmp = data.query.blocks; for (var i = 0; i < tmp.length; i++) { if (typeof tmp[i] == 'object') blockedUser.push(tmp[i].user); }       if ($.inArray(mw.user.name, blockedUser) >= 0) { $('#leader_finder_status').text('Your account has been banned and cannot use this feature'); return; } var functionArray = []; Parse.initialize("AJr5JYqb39199iUwCFwiPxi2vTAY3hDnjV6u5GwC", "JlifJSRkyGtZ4iKPHPXcCzduboWbtkwxqGFlgipx"); function Count (level, maxLevel, base, max, race){ var tmp = 1; switch (race) { case 'God': case 'Elf': tmp = 1.5; break; case 'Beast': tmp = 2/3; break; }           return Math.floor(base + (max - base) * Math.pow(level / maxLevel, tmp)); }       function MonsterIdToString(id){ return (id<10)?('00'+id):((id<100)?('0'+id):(''+id)); }       function RefineLevelString(rlevel) { switch(rlevel){ case 0: return 'No'; case 1: return 'I'; case 2: return 'II'; case 3: return 'III'; case 4: return 'IV'; }       }        function commafy(num){ num = num + ''; var re = new RegExp(decodeURIComponent('(-%3F%5Cd%2B)(%5Cd%7B3%7D)')); while(re.test(num)){ num=num.replace(re,'$1,$2'); }             return  num;

}		function dateFormat(date){ date.setTime(date.getTime + 28800000); return date.getFullYear + 'Year' + (date.getMonth + 1) + 'Month' + date.getDate + 'Day ' + date.getHours + ':' + date.getMinutes + ':' + date.getSeconds; }       $.tablesorter.addParser({            id:'rlevelparser',            is:function(s){switch(s){case 'I':case 'II':case 'III':case 'IV':case 'No':return true;} return false;},            format:function(s){return s.replace(/No/,0).replace(/IV/,4).replace(/III/,3).replace(/II/,2).replace(/I/,1);},            type:'numeric'        });

$('#leader_finder_form').submit(function (e) {           e.preventDefault;            $('#leader_finder_form input[type=submit]').attr('disabled', 'disabled');            $('#leader_finder_status').text('Query');            $('.leader_finder_data_table:eq(1)').remove;            var Card = Parse.Object.extend('Card');            var query = new Parse.Query(Card);            var monsterId = parseInt($('#leader_finder_input').val);            query.equalTo('monsterId', monsterId);            query.descending('updatedAt');            query.limit(1000);            query.find({ success: function (cards) { if (cards.length <= 0) { $('#leader_finder_status').text('No Information'); $('#leader_finder_form input[type=submit]').removeAttr('disabled'); return; }                   $.get('http://towerofsaviors.wikia.com/api.php', {                        format: 'json',                        action: 'expandtemplates',                        text: decodeURI('%7B%7B' + MonsterIdToString(monsterId) + '%7Cinfo2%7D%7D')                    }, function (data) {                        var arr = data.expandtemplates['*'].split(',');                        var lvMax = parseInt(arr[0]);                        var baseHP = parseInt(arr[1]);                        var baseAtk = parseInt(arr[2]);                        var baseRoc = parseInt(arr[3]);                        var maxHP = parseInt(arr[4]);                        var maxAtk = parseInt(arr[5]);                        var maxRoc = parseInt(arr[6]);                        var race = arr[7];                        var skillCD = parseInt(arr[8]);                        var template = $('.leader_finder_data_table:eq(0)'); var newTable = template.clone; newTable.insertAfter(template); for (var i = 0; i < cards.length; i++) { var card = cards[i]; var newRow = $('                              '); var tds = newRow.children; var area = $('').attr('href','http://towerofsaviors.wikia.com/wiki/User:' + card.get('user')).attr('target','_blank'); area.text(commafy(card.get('UID'))); var wantString = ""; var want = card.get("want"); if(want) {                               for(var j = 0; j < 5; j++) if(want[j]) wantString += want[j] + ","; if(wantString.length) wantString = wantString.slice(0, -1); }                           tds.eq(0).append(area); tds.eq(1).text(card.get('name')); tds.eq(2).text(card.get('playerLevel')); var level = card.get('level'); tds.eq(3).text(level); tds.eq(4).text(card.get('slevel')); tds.eq(5).text(skillCD - card.get('slevel') + 1); tds.eq(6).text(Count(level, lvMax, baseHP, maxHP, race)); tds.eq(7).text(Count(level, lvMax, baseAtk, maxAtk, race)); tds.eq(8).text(Count(level, lvMax, baseRoc, maxRoc, race)); tds.eq(9).text(RefineLevelString(card.get('rlevel'))); tds.eq(10).text(card.get('main')?'○':'×'); tds.eq(11).text(card.get('main2')?'○':'×'); tds.eq(12).text(wantString); tds.eq(13).text(card.get('remark')); tds.eq(14).text(dateFormat(card.updatedAt)); newTable.children('tbody').append(newRow); }                       newTable.width(parseInt($('#WikiaMainContent').width) - 20); newTable.show; newTable.removeClass('jquery-tablesorter'); newTable.tablesorter; $('#leader_finder_status').text('Query completed'); $('#leader_finder_form input[type=submit]').removeAttr('disabled'); });               },                error: function  {                    alert('Query error, please try again');                    $('#leader_finder_form input[type=submit]').attr('disabled', false);                }            }); });       $('#leader_finder_input').on('input',function{ if (functionArray.length == 0) { functionArray.push(0); onInput; } else { functionArray.push(onInput); }       });        var currentId;        function onInput{            if (parseInt($('#leader_finder_input').val) == currentId || isNaN(parseInt($('#leader_finder_input').val))){                functionArray = [];                return;            }            currentId = parseInt($('#leader_finder_input').val);            $.get('http://towerofsaviors.wikia.com/api.php',{ format:'json', action:'parse', text:decodeURI('%7B%7BMonsterIcon%7C' + MonsterIdToString(parseInt($('#leader_finder_input').val)) + '%7C50%7D%7D') },function(data){ $('#leader_finder_image').children.remove; $(data.parse.text['*']).children.appendTo($('#leader_finder_image')); functionArray = functionArray.slice(1); if (functionArray.length == 0); else{ (functionArray[0]); }           });        }    },'json'); });