User:Suppa chuppa/log.js

var ewGedbFetching = false; var ewItemIds = [];

//function ewFetchGEDB { //	ewGedbFetching = true; // //	$.ajax({ //		'url': 'http://query.yahooapis.com/v1/public/yql', //		'data': { //			'q': 'SELECT content FROM html WHERE url="http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' + ewItemIds[0] + '" AND xpath="//div[@id=\'item_additional\']/p"', //			'format': 'json', //			'_maxage': '900' //		}, //		'dataType': 'jsonp', //		'jsonp': 'callback', //		'jsonpCallback': 'ewJSONPCallback', //		'method': 'GET', //		'timeout': 10000 //	}); //}

//function ewJSONPCallback(response) { //	var itemId = ewItemIds.shift; // //	if (response.query.results) { //		var price = $.trim(response.query.results.p).split('\n').pop; //		$('#log_main td.rc_item_' + itemId).text(price); //	} else { //		$('#log_main td.rc_item_' + itemId).text('Network Error'); //	} // //	if (ewItemIds.length) { //		//ewFetchGEDB; //	} else { //		ewGedbFetching = false; //	} //}

$(function {	var reLastPrice = /^\|Last=(.*)$/m;	var rePrice = /^\|Price=(.*)$/m;	var reLastDate = /^\|LastDate=(.*)$/m;	var reDate = /^\|Date=(.*)$/m;	var reLowAlch = /^\|LowAlch=(.*)$/m;	var reHighAlch = /^\|HighAlch=(.*)$/m;	var reItemId = /^\|ItemId=\s*([0-9]+)\s*$/m;

var refreshTimer = null; var rcSince = null; var rcIds = [];

var loadingHtml = '';

function articleURL(article) { return wgArticlePath.replace('$1', encodeURI(article.replace(/ /g, '_'))); }

function scriptURL(article) { return wgScript + '?title=' + encodeURIComponent(article.replace(/ /g, '_')); }

function callAPI(data, method, callback) { data['format'] = 'json';

$.ajax({			data: data,			dataType: 'json',			url: wgScriptPath + '/api.php',			type: method,			success: function(response) {				if (response.error) {					alert('API error: ' + response.error.info);				} else {					callback(response);				}			},			error: function(xhr, error) { alert('AJAX error: ' + error); },			timeout: 10000		}); }

function reloadComplete { if ($('#logAutoRefresh:checked').length) { window.clearTimeout(refreshTimer); refreshTimer = window.setTimeout(reloadData, 5 *1000); }		$('#log_update img').hide; $('#logLastUpdate').text((new Date).toUTCString); }

function reloadData { $('#log_update img').show;

var rcQuery = { 'rclimit': '1', 'rcshow': '!bot', //$('#ewBotEdits:checked').length ? '' :			'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment', 'action': 'query', 'list': 'recentchanges', 'rcnamespace': '0' };

if (rcSince) { rcQuery['rcend'] = rcSince; }

callAPI(rcQuery, 'GET', function(response) {			var revs = [];			var curDate = '';

response.query.recentchanges.reverse;

for (var i in response.query.recentchanges) { var rc = response.query.recentchanges[i];

// Remove duplicates which may occur during autorefresh if ($.inArray(rc.rcid, rcIds) > -1) { continue; }				rcIds.push(rc.rcid);

// Remove any existing rows of the same page in the table... //if ($('#ewRecentRevOnly:checked').length) { //$('tr.rc_page_' + rc.pageid).remove; //}

revs.push(rc.revid); revs.push(rc.old_revid); var prefix = ''; var lenClass = 'even';

if (rc.newlen > rc.oldlen) { prefix = '+'; lenClass = 'pos'; } else if (rc.newlen < rc.oldlen) { lenClass = 'neg'; }

var date = rc.timestamp.substring(0, 10); var time = rc.timestamp.substring(11, 19); rcSince = rc.timestamp;

$('#logHeader').after( '' +	' ' + time + ' ' +	' ' +		'' + rc.title + ' ' +		'(edit)' +               ' (diff)' + 	' ' +	'' + prefix + (rc.newlen - rc.oldlen) + ' ' +	//' Cur ' +	'' + '' + rc.user + '' + ' ' +	//'? ' +	//'? ' +	//'? ' +	//'? ' +	//'<td class="rc_high_' + rc.revid + '">? ' + ' <tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_prev">' + '<td colspan="2" class="comment">' + rc.parsedcomment + ' ' + ' &raquo; ' + 'talk</a> &bull; ' + 'contribs</a> &bull; ' + 'undo</a> &bull; ' + '</a>' + //' Summary ' + //'<td class="rc_price_' + rc.old_revid + '">? ' +	//'<td class="rc_last_' + rc.old_revid + '">? ' +	//'<td class="rc_low_' + rc.old_revid + '">? ' +	//'<td class="rc_high_' + rc.old_revid + '">? ' + ' '				);			}

if (revs.length == 0) { reloadComplete; return; }

callAPI({				'revids': revs.join('|'),				'rvprop': 'user|timestamp|title|ids|sizes|parsedcomment',				'rvtoken': 'rollback',				'action': 'query',				'prop': 'revisions',			}, 'GET', function(response) {				reloadComplete;

for (var pageId in response.query.pages) { var page = response.query.pages[pageId]; for (var i in page.revisions) { var rev = page.revisions[i];

var content = rev['*'];

//var priceMatches = content.match(rePrice); //var lastPriceMatches = content.match(reLastPrice); //var lowAlchMatches = content.match(reLowAlch); //var highAlchMatches = content.match(reHighAlch); //var itemIdMatches = content.match(reItemId);

//var mark = !priceMatches || !lastPriceMatches || !lowAlchMatches || !highAlchMatches || !itemIdMatches; //if (!mark) { //var curPrice = priceMatches[1].replace(/,/g, ''); //var lastPrice = lastPriceMatches[1].replace(/,/g, '');

//if (curPrice < lastPrice * 0.8 || curPrice > lastPrice * 1.2) { //mark = true; //}						//}

//if (mark) { //$('#log_main tr.rc_rev_' + rev.revid).css('backgroundColor', '#FDD'); //}

//$('#log_main td.rc_price_' + rev.revid).text(priceMatches ? priceMatches[1] : 'ERROR'); //$('#log_main td.rc_last_' + rev.revid).text(lastPriceMatches ? lastPriceMatches[1] : 'ERROR'); //$('#log_main td.rc_low_' + rev.revid).text(lowAlchMatches ? lowAlchMatches[1] : 'ERROR'); //$('#log_main td.rc_high_' + rev.revid).text(highAlchMatches ? highAlchMatches[1] : 'ERROR');

$('#log_main td.rc_user_' + rev.revid).html('' + rev.user + '</a>');

//if (itemIdMatches) { //var itemId = itemIdMatches[1];

//if ($.inArray(itemId, ewItemIds) == -1) { //ewItemIds.push(itemId); //}

//if (!ewGedbFetching) { //ewFetchGEDB; //}

//$('#log_main td.rc_gedb_' + rev.revid).addClass('rc_item_' + itemId).html(loadingHtml); //} else { //$('#log_main td.rc_gedb_' + rev.revid).text('ERROR'); //}

var $rbLink = $('#log_main a.rc_rb_' + rev.revid); $rbLink.attr('href', $rbLink.attr('href') + encodeURIComponent(rev.rollbacktoken)).text('rollback'); }				}			});		});	}

if ((wgPageName == 'User:Quarenon/Scripts/Exchange_Watch' || wgPageName == 'User:Suppa_chuppa/RecentChangesHybrid') && (wgAction == 'view' || wgAction == 'purge')) { $('#WikiaRail').remove; $('body').addClass('oasis-one-column');

appendCSS(			'.rc_cur > td, .rc_cur > th { border-top: 2px solid #333 !important; }' +			'/*#log_msg { padding: 1em; margin: 1px; border: 1px solid black; }*/'		);

$('#log_options').empty.append( ' ' +	' ' +		' Recent Changes Watch options ' +		//'<input type="checkbox" id="ewRecentRevOnly" checked="checked" /> <label for="ewRecentRevOnly">Display only the most recent revision of each page ' +		'<input type="checkbox" id="rcAutoRefresh" checked="checked" /> <label for="rcAutoRefresh">Auto-refresh table ' +		//'<input type="checkbox" id="ewBotEdits" /> <label for="ewBotEdits">Show bot edits ' +	' ' + ' '		);

$('#log_update').html('Last update: ' + loadingHtml);

var $table = $(' ').addClass('wikitable').attr('id', 'ewData').css('width', '100%'); $table.append( '<tr id="rcHeader">' +	' Time ' +	' Title ' +	' Bytes ' +	//' Revision ' +	' User ' +	//' GEDB ' +	//' Price ' +	//' Last ' +	//' LowAlch ' +	//' HighAlch ' + ' '		);

$('#log_main').empty.append($table);

$('#logAutoRefresh').click(function {			window.clearTimeout(refreshTimer);			if ($(this).is(':checked')) {				refreshTimer = window.setTimeout(reloadData, 5 * 1000);			}		});

// Reload everything if these are changed. //$('#ewRecentRevOnly,#ewBotEdits').click(function {			//$('#ewHeader').nextAll.remove;			//rcIds = [];			//rcSince = null;			//reloadData;		//});

reloadData; } });

/* */