User:Suppa chuppa/recentchanges.js

/*
 * Thanks to Quarenon for the outline (almost all of the code) and Megan for helping make it work.

var ewGedbFetching = false; var ewItemIds = []; var timer = 3; //in seconds

$(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);				}			},			timeout: 10000		}); }

function reloadComplete { if ($('#rcAutoRefresh:checked').length) { window.clearTimeout(refreshTimer); refreshTimer = window.setTimeout(reloadData, timer * 1000); //in ms		} $('#rc_update img').hide; $('#rcLastUpdate').text((new Date).toUTCString); }

function reloadData { $('#rc_update img').show; var show = $('#rcShowLast').val; var IP = $('#rcShowIP:checked').length; var user = $('#rcShowUsers:checked').length; var add = ''; if(IP&&user){ add = ''; }               else if(IP) { add = '|anon'; }               else { add = '|!anon'; }		var rcQuery = { 'rclimit': show, 'rcshow': '!bot' + add, 'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', //'rcexcludeuser': $('#rcExclude').val };

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);

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;

$('#rcHeader').after( '' +	' ' + time + ' ' +	' ' +		'' + rc.title + ' ' +		'(edit)' +               ' (diff)' +                ' (history)' + 	' ' +	'' + prefix + (rc.newlen - rc.oldlen) + ' ' +	'' + '' + rc.user + '' + ' ' + ' ' +	'' + rc.parsedcomment + ' ' +        ' &raquo; ' +		'talk</a> &bull; ' + 'contribs</a> &bull; ' + 'undo</a> &bull; ' + '</a> &bull; ' + 'block</a> ' + ' '				);			}

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['*'];

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

var $rbLink = $('#rc_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' || wgPageName == 'User:Thebrains222/Projects/Sandbox4' || wgPageName=='User:Suppa_chuppa/RCH_Lite') && (wgAction == 'view' || wgAction == 'purge')) { $('#WikiaRail').remove; $('body').addClass('oasis-one-column');

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

$('#rc_options').empty.append( ' ' +	' ' +		' Recent Changes Watch options ' +		'<input type="checkbox" id="rcAutoRefresh" checked="checked" /> <label for="rcAutoRefresh">Auto-refresh table ' +               'Show last <input type="text" id="rcShowLast" maxlength="3" size="1" value="25" /> <label for="rcShowLast"> RC edits   ' +                 'Refresh every <input type="text" id="rcTimer" maxlength="3" size="1" value="3" /> <label for="rcTimer"> seconds ' +                '<input type="button" value="Refresh" id="rcRefresh" />' +	' '  + ' ' + ' ' +		' Advanced options ' +                '<input type="checkbox" id="rcShowIP" checked="checked" /> <label for="rcShowIP">Show IP edits   ' +                '<input type="checkbox" id="rcShowUsers" checked="checked" /> <label for="rcShowUsers">Show user edits   ' +                'Exclude user from rc: <input type="text" id="rcExclude" size="1" /> <label for="rcExclude"> ' + ' ');

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

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

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

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

// Reload everything if these are changed.

$('#rcShowIP').click(function {			$('#rcHeader').nextAll.remove;//.sleep(2500);			rcIds = [];			rcSince = null;			reloadData;                       timer = $('#rclTimer').val;		});

$('#rcShowUsers').click(function {			$('#rcHeader').nextAll.remove;//.sleep(2500);			rcIds = [];			rcSince = null;			reloadData;                       timer = $('#rclTimer').val;		});

$('#rcRefresh').click(function {			$('#rcHeader').nextAll.remove;//.sleep(2500);			rcIds = [];			rcSince = null;			reloadData;                       timer = $('#rcTimer').val;		});

reloadData; } });

/* */