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) {				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 = { 'rclimit': show, 'rcshow': '!bot' + add, 'rcprop': 'user|timestamp|title|ids|sizes|parsedcomment|tags', 'action': 'query', 'list': 'recentchanges', 'rctype': 'edit|new', 'rcexcludeuser': (exclude == '' ? 'Wikia' : 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;

if(rc.ns == "112") continue;

$('#rcHeader').after(' ' + time + ' ' +					' (edit|diff)' +					' ' + rc.title + ' ' +					'' + prefix + (rc.newlen - rc.oldlen) + ' ' +					'' + '' + rc.user + '' +       				' (talk' + '|contribs) ' +					' <tr class="rc_rev_' + rc.revid + ' rc_page_' + rc.pageid + ' rc_prev">' +             				' (hist</a>|qdiff</a>) ' +					'<td colspan="2" class="comment"> ' + rc.parsedcomment + tag + '  ' +       					' &raquo; undo</a> &bull; ' +					'</a> &bull; ' +                			'block</a> '				); }

if(revs.length == 0) { reloadComplete; return; } callAPI({				'revids': revs.join('|'),				'rvprop': 'user|timestamp|ids|size',				'rvtoken': 'rollback',				'action': 'query',				'prop': 'revisions',			}, 'GET', function(response) {				for (var pageId in response.query.pages) {					for (var i in response.query.pages[pageId].revisions) {						var rev = response.query.pages[pageId].revisions[i];						var content = rev['*'];						var $rbLink = $('#rc_main a.rc_rb_' + rev.revid);						$rbLink.attr('href', $rbLink.attr('href') + encodeURIComponent(rev.rollbacktoken) + '&id=' + rev.revid).text('rollback');					}				}				reloadComplete;			});

$('[name=quickdiff]').unbind; $('[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',						'rvdiffto': 'prev',						'revids': diff,						'indexpageids': true					},					success: function(data)					{						var div1 = $(' ').attr('class', 'qdiff');						div.html(data.query.pages[data.query.pageids[0]].revisions[0].diff['*']);						div.append($('<img class="qdiffclose" src="http://images3.wikia.nocookie.net/__cb20100514174733/runescape/images/a/a2/X_mark.svg" width="15" height="16" />'));						div.next('.diff-lineno').attr('style', 'width: 50%');						div1.prepend(page + ' ' + div + ' );						cur.after(div1);						$('.qdiffclose').click(function { $('.qdiff').remove; });                			}				}); });

if (revs.length == 0) { reloadComplete; return; }		});	}

if ((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 ' +				' Options ' +				' 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; } });

/* */