User:Suppa chuppa/log.js

var ewGedbFetching = false; var ewItemIds = [];

$(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, 10 *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|loginfo', 'action': 'query', 'list': 'recentchanges', 'rctype': 'log' };

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; }                               if(rcIds.length != 0) $('#logHeader').nextAll.remove; 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 next = "";

if (rc.logtype=="move") { next = ' ' + '' + 'Moved to: ' + '' + rc.move.new_title; } else if (rc.logtype=="block") { next = ' ' + '' + 'Blocked for: ' + '' + rc.block.duration; } else if (rc.logtype=="abusefilter") { next = ' ' + '' + 'Modified abuse filter.' + ''; } else if (rc.logtype=="newusers") { next = ' ' + '' + 'New user account.' + ''; } else if (rc.logtype=="useravatar") { next = ' ' + '' + 'Updated user avatar.' + ''; } else if (rc.logtype=="protect") { next = ' ' + '' + 'Protecting page. ' + '' + rc.param; } else if (rc.logtype=="rights") { next = ' ' + '' + 'Changed user rights: ' + '' + rc.rights.old + ' to ' + rc.rights.new; }

var prev = "";

if (rc.logtype=="delete") { prev = '' + 'Deleting page. ' + '</a>'; } else if (rc.logtype=="upload") { prev = '' + 'Uploading file. ' + '</a>'; }

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

$('#logHeader').after( '<tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_cur">' +	' ' + time + ' ' +	' ' +		'' + rc.title + '</a> ' +	' ' + '<td class="rc_user_' + rc.revid + '">' + '' + rc.user + '</a>' + ' ' + ' <tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_prev">' +	' ' + prev + rc.parsedcomment + next + ' ' +       ' &raquo; ' +		'talk</a> &bull; ' +		'contribs</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['*']; $('#log_main td.rc_user_' + rev.revid).html('' + rev.user + '</a>');

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

if ((wgPageName == 'User:Suppa_chuppa/Sandbox_4' || 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( ' ' +	' ' +		' Log Watch options ' +		'<input type="checkbox" id="logAutoRefresh" checked="checked" /> <label for="logAutoRefresh">Auto-refresh table ' +	' ' + ' '		);

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

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

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

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

reloadData; } });

/* */