User:Jorrel Fraajic/monobook.js

/* */

var rcUpdateInterval = 10; var rcHideBots = true; var rcHideMinor = false; var rcHideAnons = false; var rcNS = null; var rcLimit = 50; var rcUpdater = null;

function rcAddText(el, text) {   el.appendChild(document.createTextNode(text)); }

function rcUrlize(page) {   return page.replace(' ', '_'); }

function RCHtmlUpdater(el) {   this.element = el; }

RCHtmlUpdater.prototype.resetControl = function {   while(this.element.firstChild) this.element.removeChild(this.element.firstChild); }

RCHtmlUpdater.prototype.update = function(d) {   var array = d.query.recentchanges; var ul = document.createElement('ul'); ul.className = 'special'; for(var i = 0; i < array.length; i++) {       var e = array[i]; var a;       var li = document.createElement('li'); rcAddText(li, '(');       a = document.createElement('a');        a.href = '/index.php?title=' + rcUrlize(e.title) + '&curid=' + e.pageid + '&diff=' + e.revid + '&oldid=' + e.old_revid;        a.title = e.title;        a.tabindex = 1;        rcAddText(a, 'diff');        li.appendChild(a);        rcAddText(li, ') (');        a = document.createElement('a');        a.href = '/index.php?title=' + rcUrlize(e.title) + '&curid=' + e.pageid + '&action=history';        a.title = e.title;        rcAddText(a, 'hist');        li.appendChild(a);        rcAddText(li, ') . . '); if(typeof(e.new) != 'undefined' || typeof(e.minor) != 'undefined') {           var strong = document.createElement('strong'); rcAddText(strong,               (typeof(e.new) != 'undefined' ? 'N' : '') + (typeof(e.minor) != 'undefined' ? 'm' : '')); li.appendChild(strong); rcAddText(li, ' '); }       a = document.createElement('a'); a.href = '/wiki/' + rcUrlize(e.title); a.title = e.title; rcAddText(a, e.title); li.appendChild(a); var date = e.timestamp.substring(e.timestamp.indexOf('T') + 1, e.timestamp.indexOf('Z')); rcAddText(li, '; ' + date + ' . . '); a = document.createElement('a'); a.href = '/wiki/User:' + rcUrlize(e.user); a.title = 'User:' + e.user; rcAddText(a, e.user); li.appendChild(a); rcAddText(li, ' (');       a = document.createElement('a');        a.href = '/wiki/User_talk:' + rcUrlize(e.user);        a.title = 'User talk:' + e.user;        rcAddText(a, 'Talk');        li.appendChild(a);        rcAddText(li, ' | ');        a = document.createElement('a');        a.href = '/wiki/Special:Contributions/' + rcUrlize(e.user);        a.title = 'Special:Contributions/' + e.user;        rcAddText(a, 'contribs');        li.appendChild(a);        rcAddText(li, ' | ');        a = document.createElement('a');        a.href = '/wiki/Special:Blockip/' + rcUrlize(e.user);        a.title = 'Special:Blockip/' + e.user;        rcAddText(a, 'block');        li.appendChild(a);        rcAddText(li, ') '); if(typeof(e.comment) != 'undefined') {           var em = document.createElement('em'); rcAddText(em, '(' + e.comment + ')'); li.appendChild(em); }       ul.appendChild(li); }

this.resetControl; this.element.appendChild(ul); }

function rcRetrieveData {   var limitString = '&rclimit=' + rcLimit; var nsString = (rcNS == null) ? '' : '&rcnamespace=' + rcNS; var settings = new Array; if(rcHideBots) settings.push('!bot'); if(rcHideMinor) settings.push('!minor'); if(rcHideAnons) settings.push('!anon'); var showString = '&rcshow=' + settings.join('|'); var queryString = '/api.php?action=query&list=recentchanges&rcprop=user|comment|flags&format=json' + limitString + showString + nsString; var loader = new ContentLoader; loader.callback = rcOnDataArrival; loader.send(queryString); }

function rcOnDataArrival {   var d = eval('(' + this.text + ')'); rcUpdater.update(d); setTimeout('rcRetrieveData', rcUpdateInterval * 1000); }

function onPageLoad {   var rcRoot = document.getElementById('rcview');

if(!rcRoot) return; rcUpdater = new RCHtmlUpdater(rcRoot); rcUpdater.resetControl; rcRetrieveData; }

/* */