User:Suppa chuppa/recentchanges.js

var timer = 3; //in seconds

$(function {	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); if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) {                   var anchor = anchors[i]; if(anchor.getAttribute("href")) anchor.target = "_blank"; }	}

function reloadData { $('#rc_update img').show; var show = $('#rcShowLast').val; var IP = $('#rcShowIP:checked').length; var user = $('#rcShowUsers:checked').length; var add = ''; var exclude = $('#rcExclude').val; if(IP&&user){ add = ''; }               else if(IP) { add = '|anon'; }               else { add = '|!anon'; }		var rcQuery; if(exclude=='') {                       rcQuery = { 'rclimit': show, 'rcshow': '!bot' + add, 'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment|tags', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', };               }                else {                       rcQuery = { 'rclimit': show, 'rcshow': '!bot' + add, 'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment|tags', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', 'rcexcludeuser': exclude };               }		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 tag = ""; if (rc.tags != "") { tag = " (Tag: " + rc.tags + ") "; }

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

$('#rcHeader').after( '' +	' ' + time + ' ' +	' ' +		'' + rc.title + ' ' +		'(edit)' +               ' (diff)' +                ' (diff+)' +                ' (history)' + 	' ' +	'' + prefix + (rc.newlen - rc.oldlen) + ' ' +	'' + '' + rc.user + '' + ' ' + ' <tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_prev">' +	'<td colspan="2" class="comment"> ' + rc.parsedcomment + tag + '  ' + ' &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) + '&id=' + rev.revid).text('rollback'); }				}			});		});           	$('[name=quickdiff]').click(function {            		var cur = $(this);            		var diff_class = cur[0].className.split('\\=\\');            		var diff = diff_class[0];            		var page = diff_class[1];            		$.ajax({ url: wgScriptPath + '/api.php', dataType: 'json', data: { format: 'json', action: 'query', prop: 'revisions', titles: page, rvdiffto: diff, indexpageids: true },               		success: function(data) {                   			var div = $(' ').attr('class', 'qdiff'); div.html(data.query.pages[data.query.pageids[0]].revisions[0].diff['*']); cur.after(div); }           		});                });	}

if ((wgPageName == 'User:Quarenon/Scripts/Exchange_Watch' || wgPageName == 'User:Suppa_chuppa/RecentChangesHybrid' || wgPageName == 'User:Thebrains222/Counter_Vandalism_Feed' || 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( ' ' +	'<fieldset class="collapsible collapsed">' +		' 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="10" /> <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;			rcIds = [];			rcSince = null;			reloadData;                       timer = $('#rclTimer').val;		});

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

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

reloadData; } });

/* */