User:Suppa chuppa/abuselog.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 itemSince = null; var itemIds = [];

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 ($('#abAutoRefresh:checked').length) { window.clearTimeout(refreshTimer); refreshTimer = window.setTimeout(reloadData, 10 *1000); }		$('#ab_update img').hide; $('#abLastUpdate').text((new Date).toUTCString); }

function reloadData { $('#ab_update img').show; var itemQuery = { 'itemlimit': '1', 'action': 'query', 'list': 'abuselog' };

if (itemSince) { itemQuery['itemend'] = itemSince; }

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

response.query.recentchanges.reverse;

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

// Remove duplicates which may occur during autorefresh if ($.inArray(item.itemid, itemIds) > -1) { continue; }                               if(itemIds.length != 0) $('#abHeader').nextAll.remove; itemIds.push(item.itemid);

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

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

var date = item.timestamp.substring(0, 10); var time = item.timestamp.substring(11, 19); itemSince = item.timestamp;

$('#abHeader').after( '' +	' ' + time + ' ' +	' ' +		'' + item.title + ' ' +	' ' + '' + '' + item.user + '' + ' ' + ' ' +	'Triggered abuse filter ' + item.filter_id + ' ' +       ' &raquo; ' +		'talk &bull; ' +		'contribs' + ' '				); }

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['*']; $('#ab_main td.item_user_' + rev.revid).html('' + rev.user + '');

var $rbLink = $('#ab_main a.item_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(			'.item_cur > td, .item_cur > th { border-top: 2px solid #333 !important; }' +			'/*#ab_msg { padding: 1em; margin: 1px; border: 1px solid black; }*/'		);

$('ab_options').empty.append( ' ' +	' ' +		' Abuse Log Watch options ' +		' <label for="abAutoRefresh">Auto-refresh table ' +	' ' + ' '		);

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

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

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

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

reloadData; } });

/* */