User:Bluefire2/rc.js

// A modification of User:Suppa_chuppa/recentchanges.js

var timer = 3; //in seconds

$(function {	var refreshTimer = null;	var rcSince = null;	var rcIds = [];

var loadingHtml = '';

function scriptURL(article) { return wgArticlePath.replace('$1', encodeURI(article.replace(/ /g, '_')).replace(/\?/g, '%3F')); }

function callAPI(data, method, callback) { data['format'] = 'json'; if(method == 'GET') $.get(wgScriptPath + '/api.php', data, function(response) { callback(response); }, 'json'); else $.post(wgScriptPath + '/api.php', data, function(response) {callback(response); }, 'json'); }

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

function reloadData { $('#rc_update img').show; var show = $('#rcShowLast').val; var IP = $('#rcShowIP:checked').length; var user = $('#rcShowUsers:checked').length; var exclude = $('#rcExclude').val; var add = ''; if(IP && !user) add = '|anon'; else if(user && !IP) 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); var prefix = ''; var lenClass = 'even'; var open = , close = ;

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

if (Math.abs(rc.newlen - rc.oldlen) > 499) { open = , close = ; }

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 + ' ' +					' (edit|diff)' +					' ' + rc.title + ' ' +					'' + open + prefix + (rc.newlen - rc.oldlen) + close + ' ' +					'' + '' + 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>' + 'warn</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 = response.query.pages[pageId].revisions[i]['*'];						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].replace(/_/g, ' ');

$.ajax({					url: wgScriptPath + '/api.php',					dataType: 'json',					data: {						'format': 'json',						'action': 'query',						'prop': 'revisions',						'rvdiffto': 'prev',						'revids': diff,						'indexpageids': true					},					success: function(data)					{						var div = $(' ').attr('class', 'qdiff');						cur.after(div);						div.next('.diff-lineno').attr('style', 'width: 50%');						div.html('<h3 style="text-align:center">' + page + '  ');						$('#qdiff-content').append(data.query.pages[data.query.pageids[0]].revisions[0].diff['*']);						div.prepend($('<img style = "float:right;" class="qdiffclose" src="http://images3.wikia.nocookie.net/__cb20100514174733/runescape/images/a/a2/X_mark.svg" width="15" height="16" />'));						$('.qdiffclose').click(function { $('.qdiff').remove; });						$('.qdiff').click(function(event) { event.stopPropagation; } );						$('body').click(function(event) { $('.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(' ' +							' ' +								' Recent Changes Watch options [+]</a>  ' +							' ' +							' ' +								' Recent Changes Watch options [-]</a> ' +								'<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 [+]</a>  ' +							' ' +							' ' +								' Advanced options [-]</a> ' +                						'<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-link-toggle1').click(function {			$('#rc-toggle1').css('display', 'none');			$('#rc-hide1').toggle;		}); $('#rc-link-show1').click(function {			$('#rc-toggle1').toggle;			$('#rc-hide1').css('display', 'none');		}); $('#rc-link-toggle2').click(function {			$('#rc-toggle2').css('display', 'none');			$('#rc-hide2').toggle;		}); $('#rc-link-show2').click(function {			$('#rc-toggle2').toggle;			$('#rc-hide2').css('display', 'none');		});

$('#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; } });

/* */