Jump to content

User:MusikAnimal/previewUserboxes.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 14:09, 9 July 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
 * Script:	previewUserboxes.js
 * Author:	en:User:MusikAnimal
 * 
 * Notes:	This script only shows userboxes that are less than 2500 bytes in size
 *			This is because some users frustratingly put userboxes categories on their user page (many times unintentional)
 *
 */

if(wgCategories.indexOf("Userboxes") > -1) {
	// showUserboxes = function() {
		var boxes = $("#mw-pages").find(".mw-content-ltr").find("a");
		$.each(boxes,function(i,box){
			// $.get(wgScriptPath+"/api.php?action=query&prop=revisions&rvprop=size&format=json&titles="+box.text,function(size) {
			$.get(wgScriptPath+"/api.php?format=json&action=parse&page="+box.text,function(data){
				if(data.parse && data.parse.text["*"].length < 2500) {
					$html = "<div>" + data.parse.text["*"] + "</div>" +
							"<div style='clear:both;margin-bottom:10px'>{{<a href='"+wgScriptPath+"/index.php?title="+box.text+"'>"+box.text+"</a>}}</div>";
					$(box).parent().html($html);
				}
			});
		});
	// }
}