User:Yustus/common.js

/** Description: Improves the functionality of the champion infobox. Author: Jens Ingels Modified by: Emptylord Last updated 2014-04-02 @Version 0.1.2 (beta) ** /

//SEASON 2015 $( document ).ready(function {   if( $('#champion_info-lower-preseason').length ) {

//Prepare Arrays var name = ["Health","Health regeneration","Mana","Mana regeneration","Range","Attack damage","Attack speed","Armor","Magic resistance","Movement speed", "Energy", "Energy regeneration"];

//Add buttons $( "#levelselectcontainer").append( " Level: n 1-18 1 2 3 4 5 6 7 8 9 10 11 12 <option value='13'>13 <option value='14'>14 <option value='15'>15 <option value='16'>16 <option value='17'>17 <option value='18'>18  " );

//Prepare Functions callBase = function(value) { if( $( ".data-" + value ).length ) { mainVal = $( ".data-" + value ).contents.filter(function {            return this.nodeType == 3;            }).text; mainVal = parseFloat(mainVal); return mainVal; }         else {         }      };

callPlus = function(value) { plusVal = $( ".data-" +value+ " span" ).html; plusVal = plusVal.substring(1, plusVal.length-1) if(plusVal[plusVal.length - 1] === '%') { plusVal = parseFloat(plusVal); plusVal = plusVal/100; }         else {            plusVal = parseFloat(plusVal); }         return plusVal; };

callConvert = function(valBase, valPer, valLevel, valLength) { var value = valBase + valPer *  ((7 / 400) * Math.pow(valLevel,2) + (267 / 400) * valLevel - (137 / 200)); return value.toFixed(valLength); };

//Collect Data health = { base : callBase("health"), plus : callPlus("health"), backup : $( ".data-health" ).html };      health_regeneration = { base : callBase("health_regeneration"), plus : callPlus("health_regeneration"), backup : $( ".data-health_regeneration" ).html };      if( $('.data-mana').length ) {

mana = { base : callBase("mana"), plus : callPlus("mana"), backup : $( ".data-mana" ).html };             mana_regeneration = { base : callBase("mana_regeneration"), plus : callPlus("mana_regeneration"), backup : $( ".data-mana_regeneration" ).html };

}      if( $('.data-energy').length ) {

energy = { base : callBase("energy"), backup : $( ".data-energy" ).html };         energy_regeneration = { base : callBase("energy_regeneration"), backup : $( ".data-energy_regeneration" ).html };

}      range = { base : callBase("range"), backup : $( ".data-range" ).html };      attack_damage = { base : callBase("attack_damage"), plus : callPlus("attack_damage"), backup : $( ".data-attack_damage" ).html };      attack_speed = { base : callBase("attack_speed"), plus : callPlus("attack_speed"), backup : $( ".data-attack_speed" ).html };      armor = { base : callBase("armor"), plus : callPlus("armor"), backup : $( ".data-armor" ).html };      magic_resistance = { base : callBase("magic_resistance"), plus : callPlus("magic_resistance"), backup : $( ".data-magic_resistance" ).html };      movement_speed = { base : callBase("movement_speed"), backup : $( ".data-movement_speed" ).html };

callChange = function { getLevel = $("#lv").val; getLevel = parseInt(getLevel);

//LEVEL N         if ( getLevel == 19 ) { sendA = health.backup; sendB = health_regeneration.backup; if( $('.data-mana').length ) { sendC = mana.backup; sendD = mana_regeneration.backup; }            sendF = attack_damage.backup; sendG = attack_speed.backup; sendH = armor.backup; sendI = magic_resistance.backup; }         //LEVEL "1 - 18" else if ( getLevel == 0 ) { sendA = callConvert(health.base, health.plus, 1, 0) + " – " + callConvert(health.base, health.plus, 18, 0); sendB = callConvert(health_regeneration.base, health_regeneration.plus, 1, 1) + " – " + callConvert(health_regeneration.base, health_regeneration.plus, 18, 1); if( $('.data-mana').length ) { sendC = callConvert(mana.base, mana.plus, 1, 0) + " – " + callConvert(mana.base, mana.plus, 18, 0); sendD = callConvert(mana_regeneration.base, mana_regeneration.plus, 1, 1) + " – " + callConvert(mana_regeneration.base, mana_regeneration.plus, 18, 1); }            sendF = callConvert(attack_damage.base, attack_damage.plus, 1, 0) + " – " + callConvert(attack_damage.base, attack_damage.plus, 18, 0); sendG = attack_speed.base+" (+0% – "+(callConvert(0, attack_speed.plus, 18, 3)*100).toPrecision(3)+"%)"; if ( callConvert(armor.base, armor.plus, 1, 1) == callConvert(armor.base, armor.plus, 18, 1) ) { sendH = callConvert(armor.base, armor.plus, 1, 1); } else { sendH = callConvert(armor.base, armor.plus, 1, 1) + " – " + callConvert(armor.base, armor.plus, 18, 1); }            if ( callConvert(magic_resistance.base, magic_resistance.plus, 1, 1) == callConvert(magic_resistance.base, magic_resistance.plus, 18, 1) ) { sendI = callConvert(magic_resistance.base, magic_resistance.plus, 1, 1); } else { sendI = callConvert(magic_resistance.base, magic_resistance.plus, 1, 1) + " – " + callConvert(magic_resistance.base, magic_resistance.plus, 18, 1); }         }         //LEVEL DYNAMIC else { sendA = callConvert(health.base, health.plus, getLevel, 0); sendB = callConvert(health_regeneration.base, health_regeneration.plus, getLevel, 1); if( $('.data-mana').length ) { sendC = callConvert(mana.base, mana.plus, getLevel, 0); sendD = callConvert(mana_regeneration.base, mana_regeneration.plus, getLevel, 1); }            sendF = callConvert(attack_damage.base, attack_damage.plus, getLevel, 0); sendG = attack_speed.base+" (+"+(callConvert(0, attack_speed.plus, getLevel, 3)*100).toPrecision(3)+"%)"; sendH = callConvert(armor.base, armor.plus, getLevel, 1); sendI = callConvert(magic_resistance.base, magic_resistance.plus, getLevel, 1); }         $( ".data-health" ).html(sendA); $( ".data-health_regeneration" ).html(sendB); if( $('.data-mana').length ) { $( ".data-mana" ).html(sendC); $( ".data-mana_regeneration" ).html(sendD); }         $( ".data-attack_damage" ).html(sendF); $( ".data-attack_speed" ).html(sendG); $( ".data-armor" ).html(sendH); $( ".data-magic_resistance" ).html(sendI);

};

//On Change Calculation $( "#levelselectcontainer" ).click(function {         $( "#lv" ).change(callChange);      });

//Update default to show 1-18 var element = document.getElementById('lv'); element.value = 0; callChange; }

});