Pengguna:Iwan Novirion/editHysteria.js

Revisi sejak 28 Februari 2022 06.00 oleh Ladsgroup (bicara | kontrib) (Maintenance: Fixing deprecated call to importScriptURI (mw:ResourceLoader/Migration_guide_(users)#importScriptURI))
(beda) ← Revisi sebelumnya | Revisi terkini (beda) | Revisi selanjutnya → (beda)

Catatan: Setelah menyimpan, Anda harus memintas tembolok (cache) peramban Anda untuk melihat perubahannya. Google Chrome, Firefox, Microsoft Edge dan Safari: Tahan tombol Shift dan klik Muat ulang (Reload) di tombol bilah alat. Untuk detail dan instruksi tentang peramban lain, lihat halaman menghapus singgahan (Inggris).

var beau$userGroups = {};
 
if (wgUserGroups) {
	for (var i = 0; i < wgUserGroups.length; i++) {
		beau$userGroups[ wgUserGroups[i] ] = true;
	}
}
 
function beau$callAPI(query) {
	var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?';
 
	for (var field in query) {
		var value = query[field];
		url += '&' + field + '=' + encodeURIComponent(value);
	}
	url += '&format=json';
	mw.loader.load(url);
}

var editHysteriaGadget = {};
 
editHysteriaGadget.init = function () {
	var firstHeading;
	var headers = document.getElementsByTagName("h1");
 
	for(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:8pt;line-height:1em";
	if (skin == 'modern')
	{
		div.style.marginLeft = "10px";
		div.style.display = "inline-block";
	}
 
	firstHeading.appendChild(div);
	this.div = div;
 
	beau$callAPI({
		action:	'query',
		prop:	'revisions',
		rvprop:	'user|ids',
		rvlimit:	50,
		callback:	'editHysteriaGadget.gotRevisions',
		titles:	wgPageName,
		requestid: new Date().getTime()
	});
};
 
editHysteriaGadget.wikilink = function(page) {
	return wgScript + '?title=' + encodeURIComponent(page);
};
 
editHysteriaGadget.userlink = function(name) {
	var str = '<a href="' + this.wikilink('User:' + name) + '">' + name + '</a> ' +
	  '(<a href="' + this.wikilink('Special:Contributions/' + name) + '">kontribusi</a>, <a href="' + this.wikilink('User_talk:' + name) + '">bicara</a>';
 
	if ( beau$userGroups['.sysop'] )
		str += ', <a href="' + this.wikilink('Special:Blockip/' + name) + '">sekat</a>';
 
	str += ')';
 
	return str;
};
 
editHysteriaGadget.gotRevisions = function(data) {
	var page = data.query.pages[wgArticleId];
	var html = '';
 
	var div = this.div;
	if (! page) {
		div.innerHTML = html + "Halaman tidak ada";
		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 += 'Terakhir <a href="'+ wgScript + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&diff=cur&oldid=' + ldiff + '"/>disunting</a>' +
			' oleh ' + this.userlink(topuser) + ' (' + count + 'x).';
 
                if(luser !== "" && luser != topuser) {
			html += ' Sebelumnya disunting ' + this.userlink(luser) + '.';
		}
                div.innerHTML = html;
	}
        else if (topuser !== "") {
		div.innerHTML = html + 'Satu-satunya versi halaman. ' +
			'Oleh ' + this.userlink(topuser) + '.';
	}
	if (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';
		}
	}
};
 
if (wgNamespaceNumber >= 0 && !document.location.href.match(/printable=yes/))
	addOnloadHook(function() { editHysteriaGadget.init() } );