MediaWiki:Common.js/gemwupdate.js

/* Any JavaScript here will be loaded for all users on every page load. */ //

//Parts of this script are copied from User:Quarenon/gemwupdate.js. Credit goes to Quarenon for writing that code.

$(function {	$('#gemw_guide').html(' Update the price of this item: Update price })

function updateGEPrice(item) { var button = document.all.updateGEP button.disabled = true; $.getJSON('http://anyorigin.com/get?url=http%3A//services.runescape.com/m%3Ditemdb_rs/api/graph/'+$('#GEDBID').html+'.json&callback=?', function(data){		var pricelist = data.contents.daily;		var names = []		for (var name in pricelist) {			names.push(name);		}		var price = pricelist[names[names.length-1]];		var curprice = parseInt($('#GEPrice').html);		if (price == curprice) {			alert('The price is already the same as the price on the official GE database.');			button.disabled = false;			return false;		}		callAPI({ 'action': 'query', 'prop': 'info|revisions', 'intoken': 'edit', 'titles': wgPageName, 'rvprop': 'content', 'rvlimit': '1' }, 'GET', function(response) { var page = response.query.pages[response.query.pageids[0]]; var content = page.revisions[0]['*']; var cPrice = content.match(/\|Price\s*=\s*(\d+)/)[0].replace(/\|Price\s*=\s*/,''); if (price == parseInt(cPrice.replace(',',''))) { alert('The price is already the same as the price on the official GE database.'); button.disabled = false; return false; }			var lPrice = content.match(/\|Last\s*=\s*(\d+)/)[0].replace(/\|Last\s*=\s*/,''); var cDate = content.match(/\|Date\s*=\s*([^\|\n]+)/)[0].replace(/\|Date\s*=\s*/,''); var updated = content.replace(/\|Price\s*=\s*(\d+)/, '|Price='+addCommas(price)) .replace(/\|Last\s*=\s*(\d+)/, '|Last='+lPrice) .replace(/\|Date\s*=\s*([^\|\n]+)/, '|Date=') .replace(/\|LastDate\s*=\s*([^\|\n]+)/, '|LastDate='+cDate); callAPI({				'minor': 'yes',				'summary': 'Updated GEMW data via script on the exchange page.',				'action': 'edit',				'title': wgPageName,				'basetimestamp': page.revisions[0].timestamp,				'startimestamp': page.starttimestamp,				'token': page.edittoken,				'text': updated			}, 'POST', function(response) {				if (response.edit.result == 'Success') {					alert('Thank you for your submission! The page will now be reloaded.');					document.location.replace(wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=purge');				} else {					alert('An error occurred while submitting the edit.');					button.disabled = false;				}			}); });	}); }