User:Incnis Mrsi/edithysteria.js

// Ported from pl:MediaWiki:Gadget-edithysteria.js, see there for authorship

window.editHysteriaGadget = { version: 5,

init: function { if ( mw.config.get( 'wgNamespaceNumber' ) < 0 || mw.util.getParamValue('printable') === 'yes' ) { return; }

var that = this;

var request = { action:	'query', prop:	'revisions', rvprop:	'user|ids', format:	'json', titles:	mw.config.get( 'wgPageName' ), rvlimit:	50, requestid:	new Date.getTime };		jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {			jQuery(document).ready(function { if (result) { that.showResults(result); }			});		});	},	userlink: function(name) { var str = '' + name + ' ' + '(talk' +		 ' · contribs)';

//		if ( jQuery.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) != -1 ) { //			str += ', block'; //		} // //		str += ')';

return str; },	showResults: function(data) { var page = data.query.pages[ mw.config.get( 'wgArticleId' ) ]; var firstHeading; var headers = document.getElementsByTagName( 'h1' );

for ( var i = 0; i < headers.length; i++ ) { var header = headers[i]; if(header.className == "firstHeading" || header.id == "firstHeading" || header.className == "pagetitle") { firstHeading = header; break; }		}

if( !firstHeading ) { firstHeading = document.getElementById("section-0"); }

if( !firstHeading ) { return; }

var div = document.createElement("div"); div.style.cssText = "font-size:0.5em;line-height:1em"; div.className = 'plainlinks'; if ( mw.config.get( 'skin' ) == 'modern' ) { div.style.marginLeft = "10px"; div.style.display = "inline-block"; }

firstHeading.appendChild(div);

var html = ''; if (! page) { div.innerHTML = html + "Page not exists."; div.style.color = "red"; return; }

var topuser = page.revisions[0].user; var ldiff; var luser; var count = 1;

for (var i = 1; i < page.revisions.length; i++) { ldiff = page.revisions[i].revid; luser = page.revisions[i].user; if (luser != topuser) break; count++; }

if (ldiff) { html += 'Last edited' + ' by ' + this.userlink(topuser) + ' (' + count + '×)';

if(luser !== "" && luser != topuser) { html += ', previous edit by ' + this.userlink(luser); }			html += '.'; div.innerHTML = html; }		else if (topuser !== "") { div.innerHTML = html + 'This is the only version by ' + this.userlink(topuser) + '.'; }		if ( mw.config.get('skin') == 'modern' ) { var links = div.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { links[i].style.color = 'white'; links[i].style.textDecoration = 'underline'; }		}	} };

editHysteriaGadget.init;