MediaWiki:Monstercalc.js

//Script for adding small calculators to infoboxes.

//First a function to add commas to numbers, credit to http://www.mredkj.com/javascript/numberFormat.html#addcommas function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); }	return x1 + x2; } //---

//First the things that should happen when entering something in the inputs

function killkeyup { var warn = ; var warn2 =  if ($('input#monsterCalc').val.search(/[^0-9]/) != '-1') {warn = ''; warn2 = ' '} if ($('input#monsterCalc').val.replace(/[^0-9]/g, '').length == 0) { $('#monsterCalcResult').html(warn + $('#killXP .fightXP').html + ' xp (and ' + $('#killXP .constXP').html + ' Constitution experience)' + warn2) } else { $('#monsterCalcResult').html(warn + $('input#monsterCalc').val.replace(/[^0-9]/g, ) * $('#killXP .fightXP').html + ' xp (and ' + $('input#monsterCalc').val.replace(/[^0-9]/g, ) * $('#killXP .constXP').html + ' Constitution experience)' + warn2) } }

function slaykeyup { var warn = ; var warn2 =  if ($('input#slayerCalc').val.search(/[^0-9]/) != '-1') {warn = ''; warn2 = ' '} if ($('input#slayerCalc').val.replace(/[^0-9]/g, '').length == 0) { $('#slayerCalcResult').html(warn + $('#slayXP .slayXP').html + warn2) } else { $('#slayerCalcResult').html(warn + $('input#slayerCalc').val.replace(/[^0-9]/g, '') * $('#slayXP .slayXP').html + warn2) } }

//Monster killing XP calc

$(document).ready(function{	if ($('span#killXP').length != 0) {		$('span#killXP span').attr('style', 'display:none;')		$('span#killXP').append(' ' + $('#killXP .fightXP').html + ' xp (and ' + $('#killXP .constXP').html + ' Constitution experience) ')		$('input#monsterCalc').keyup(killkeyup)		if ($('span#slayXP').length != 0) {			$('#killXP').prepend('')			if ($('#communicateBox').is(':checked')) { 				$('#monsterCalc').keyup(function{ $('#slayerCalc').val($('#monsterCalc').val) })				$('#monsterCalc').keyup(slaykeyup)			}		}		$('input#monsterCalc').focus(function{ $('input#monsterCalc').select })	} })

//Slayer XP calc

$(document).ready(function{	if ($('span#slayXP').length != 0) {		$('span#slayXP span').attr('style', 'display:none;')		$('span#slayXP').append(' ' + $('#slayXP .slayXP').html + ' ')		$('input#slayerCalc').keyup(slaykeyup)		if ($('span#killXP').length != 0) {			if ($('#communicateBox').is(':checked')) { 				$('#slayerCalc').keyup(function{ $('#monsterCalc').val($('#slayerCalc').val) })				$('#slayerCalc').keyup(killkeyup)			}		}		$('input#slayerCalc').focus(function{ $('input#slayerCalc').select })	} })

//GE price calc

$(document).ready(function{	if ($('span#GEPrice').length != 0) {		$('span.GEItem span').attr('style', 'display:none;')		if ($('span.GEItem span').attr('class')) {			var i = 1			$('span.GEItem').each(function{ $(this).prepend(' ' + $('span.GEItem span.' + i).html + ' ') $('input#GEPriceCalc' + i).keyup(function{					var warn = ; var warn2 = 					if ($(this).val.search(/[^0-9]/) != '-1') {warn = ''; warn2 = ' '}					if ($(this).val.replace(/[^0-9]/g, ).length == 0) {						$('#GEPCalcResult' + $(this).attr('class')).html(warn + $('span.GEItem span.' + $(this).attr('class')).html + warn2)					} else {						$('#GEPCalcResult' + $(this).attr('class')).html(warn + addCommas($(this).val.replace(/[^0-9]/g, ) * $('span.GEItem span.' + $(this).attr('class')).html.replace(/[^0-9]/g, '')) + warn2)					}				}) i++ })		} else {			$('span.GEItem').append(' ' + $('span.GEItem span').html + ' ')		}		$('input#GEPriceCalc').keyup(function{ var warn = ; var warn2 =  if ($('input#GEPriceCalc').val.search(/[^0-9]/) != '-1') {warn = ''; warn2 = ' '} if ($('input#GEPriceCalc').val.replace(/[^0-9]/g, '').length == 0) { $('#GEPCalcResult').html(warn + $('span.GEItem span').html + warn2) } else { $('#GEPCalcResult').html(warn + addCommas($('input#GEPriceCalc').val.replace(/[^0-9]/g, ) * $('span.GEItem span').html.replace(/[^0-9]/g, )) + warn2) }		})		$('input[id^="GEPriceCalc"]').focus(function{ $(this).select })	} })