User:1Veertje/Tips/CatPerson.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<nowiki><noinclude>
//Person category creation script///////////////////////////////////////

//
$( document ).ready(function() {
	if (mw.config.get('wgNamespaceNumber') == 14 && mw.config.get('wgAction') == 'edit'){ // 14 = category
		$($( "a:contains('People')" )[0]).removeAttr('href');
		$($( "a:contains('People')" )[0]).on('click', function(){
			document.getElementById("wpTextbox1").value += peoplePrefill();
		});
	}
});
function peoplePrefill(){
	parts = mw.config.get('wgPageName').replace('Category:', '').replace(/\(.+?\)/g,"").replace(/_/g, " ").trim().split(' ');
	sort = '{{DEFAULTSORT:'+  parts[parts.length - 1];
	delete parts[parts.length - 1];
	sort += ', '+parts.join(" ").trim()+'}}';
	return '{{Wikidata Infobox|defaultsort=no}}\n' +sort + '\n';
}
//End Person category creation script///////////////////////////////////////
//</noinclude></nowiki>