User:Invisible Idiot/monobook.js

// Original code: pl:MediaWiki:Gadget-mark-disambigs.js, author: pl:User:Beau

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 dg$pageLoaded = false; var dg$dataLoaded = false; var dg$disambig = {}; var dg$uniqueLinks = 0; var dg$links = 0;

if (wgNamespaceNumber >= 0 && wgAction == 'view') { dg$request; addOnloadHook(dg$init); }

function dg$request(clcontinue) {	var query = { action:	'query', titles:	wgPageName, prop:	'categories', cllimit:	500, gpllimit:	500, generator:	'links', callback:	'dg_callback', };	if (clcontinue) { query['clcontinue'] = clcontinue; }	beau$callAPI(query); }

function dg$isDisambig(categories) {	for (var key in categories) { if (categories[key].title == 'Category:Disambiguation pages') return true; }	return false; }

function dg_callback(data) {	if (! data.query) return;

document.data = data; for (var pageid in data.query.pages) { var page = data.query.pages[pageid]; if (page.categories && dg$isDisambig(page.categories)) {			if (dg$disambig[page.title]) continue;

dg$disambig[page.title] = true; dg$uniqueLinks++; }	}	if (data['query-continue'] && data['query-continue']['categories']) { dg$request(data['query-continue']['categories']['clcontinue']) }	else if (dg$pageLoaded) dg$doColor; else dg$dataLoaded = true; }

function dg$doColor { if (! dg$uniqueLinks) return;

var links = document.getElementsByTagName('a'); dg$disambig['Wikipedia:Strona ujednoznaczniająca'] = false; for (var i = 0; i < links.length; i++) {		var link = links[i];

if (dg$disambig[link.title]) { dg$links++; if (link.text == 'inne znaczenia tego określenia') continue; if (link.parentNode && link.parentNode.parentNode) if (link.parentNode.parentNode.className.match(/\bdisambig\b/)) continue; link.className = 'mw-disambig'; }	} // 	if (dg$links > 0) { // 		jsMsg("Linków do stron ujednoznaczniających: " + dg$links + ", różnych stron: " + dg$uniqueLinks); // 	} }

function dg$init { dg$pageLoaded = true; if (dg$dataLoaded) dg$doColor; }