User:Suppa chuppa/recentchanges2.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 rcQuery = { 'rclimit': show, 'rcshow': '!bot', 'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', 'rcexcludeuser': 'Cook_Me_Plox' };

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 + '' +                                                    ' (diff | ' + 'history). . ' +                                                    '' + prefix + (rc.newlen - rc.oldlen) + ' . . ' +                                                     '' + rc.user + ' ' +                                                     '(talk | ' + 'contribs | ' + 'block) ' +		                                    '(undo</a>) ' +		                                     '[</a>] '

/* '<tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_cur">' + ' ' + time + ' ' + ' ' +		'' + rc.title + '</a> ' + '(edit</a>)' + ' (diff</a>)' + ' (history</a>)' + ' ' +	'<td class="mw-plusminus-' + lenClass + '">' + prefix + (rc.newlen - rc.oldlen) + ' ' + '<td colspan="2" class="rc_user_' + rc.revid + '">' + '' + rc.user + '</a>' + ' ' + ' <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> &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" />' +	' ' + ' '		);

$('#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. $('#rcRefresh').click(function {			$('#rcHeader').nextAll.remove;//.sleep(2500);			rcIds = [];			rcSince = null;			reloadData;                       timer = $('#rcTimer').val;		});

reloadData; } });

/* */