User:IvanLanin/monobook.js

From Wikipedia

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.

/* <pre> */
/**
 * Variable declaration
 */
var tabNsUser = 'Pengguna:';
var tabNsUserTalk = 'Bicara_Pengguna:';
var labelEditCount = 'Jumlah suntingan'; 
var labelPurge = 'Hapus singgahan';
var labelPortlet = 'Peralatan tambahan';
var urlEditCount = 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=idwiki_p&user=';

/*
 * Create tidy title
 */
function getTidyTitle() {
	var editlk = document.getElementById('ca-edit');
	if (editlk == null) {
		editlk = document.getElementById('ca-viewsource');
		if (editlk == null) {
			editlk = document.getElementById('ca-article');
		}
	}
	editlk = editlk.getElementsByTagName('a')[0].href; 

	if (editlk.indexOf('title=') >= 0) {
		editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.indexOf('&'));
	} else {
		editlk = editlk.substring(editlk.indexOf('/wiki/') + 6);
	}
	return editlk;
}

/*
 * Add link
 */
function addLink(name, url) {
	var na = document.createElement('a');
	var txt = document.createTextNode(name);
	var nli = document.createElement('li');
	na.setAttribute('href', url);  
	na.appendChild(txt);
	nli.setAttribute('class', 'p-newlinks');
	nli.appendChild(na);
	return nli;
}

/*
 * Create portlet
 */
function ExtraPortlet() {
	var ndivportlet = document.createElement('div');
	var ndivpbody = document.createElement('div');
	var colone = document.getElementById('column-one');
	var nul = document.createElement('ul');
	var title = document.createElement('h5');
	var interwiki = document.getElementById('p-lang');
	var pageName = getTidyTitle();

	ndivportlet.className = 'portlet';
	ndivportlet.id = 'p-newlinks';
	ndivpbody.className = 'pBody';
	
	nul.setAttribute('id', 'p-newlinks');
	nul.appendChild(addLink(labelPurge, '/wiki/' + pageName + '?action=purge'));
	if (pageName.indexOf(tabNsUser) == 0 || pageName.indexOf(tabNsUserTalk) == 0) {
		pageName = pageName.substring(pageName.indexOf(':') + 1);
		pageName = pageName.replace(/\/.*$/, '');
		nul.appendChild(addLink(labelEditCount, urlEditCount + pageName));
	}

	title.appendChild(document.createTextNode(labelPortlet));
	ndivportlet.appendChild(title);
	ndivpbody.appendChild(nul);
	ndivportlet.appendChild(ndivpbody);
	if (interwiki == null) {
		colone.appendChild(ndivportlet);
	} else {
		colone.insertBefore(ndivportlet, interwiki);
	}
}

/*
 * Hook portlet on load
 */
if (window.addEventListener) 
	window.addEventListener("load", ExtraPortlet, false);
else if (window.attachEvent) 
	window.attachEvent("onload", ExtraPortlet);

/* </pre> */
Navigation
generic heading