User:Danski454/inlineQnum.js

$(function{	if(!mw.config.get("wgIsArticle")) return;//don't display on history etc.	function loadQnums(continueData){		var api = new mw.Api;		api.get({action:"query", format:"json", prop:"pageprops", titles:mw.config.get("wgPageName"), generator:"links", ppprop:"wikibase_item", gpllimit:"max", redirects:true, gplcontinue:continueData.gplcontinue, "continue":continueData.continue }).done(function(data){ var redirects = {}; if (data.query.redirects){ for (var i = 0; i < data.query.redirects.length; i++) { if (redirects[data.query.redirects[i].to]){ redirects[data.query.redirects[i].to].push(data.query.redirects[i].from); }					else { redirects[data.query.redirects[i].to] = [data.query.redirects[i].from]; }				}			}			for(var id in data.query.pages) { if (data.query.pages[id].pageprops && data.query.pages[id].pageprops.wikibase_item){ $("a[title='" + data.query.pages[id].title.replace(/'/, "\\'") + "']") .append(' (' + data.query.pages[id].pageprops.wikibase_item + ') '); if (redirects[data.query.pages[id].title]){ for (var red in redirects[data.query.pages[id].title]){ $("a[title='" + redirects[data.query.pages[id].title][red].replace(/'/, "\\'") + "']") .append(' (' + data.query.pages[id].pageprops.wikibase_item + ') '); }					}				}// else console.log(data.query.pages[id]); }			if (data.continue){ loadQnums(data.continue); }		});	}	loadQnums({}); });