User:Ketil3/common.js

// this version shows subcats in HTML in new window. function mylog (t) { console.log(t); } function myShowresult(t) { var myWindow=window.open("","","width=200,height=200"); myWindow.document.write(t); }		// $(recuGallTag).html(t); $( function { 	// jQuery, executed after document has been fully loaded:   var recuGallTag = '#recuGall';    mylog (mw.config.get('wgPageName'));    mylog (mw.config.get('wgNamespaceNumber'));    // if ( ! $(recuGallTag).length) return; // abort if there is no tag (place to write results)   if (! ( mw.config.get('wgCanonicalNamespace') == "Category" && $(recuGallTag).length)) return; // abort if not category page	var urlprefix = "https://en.wikipedia.org";	// var URLtouse=mw.config.get('wgScriptPath') + '/index.php?title=User:' + mw.config.get('wgUserName') + '/' + counterfile;	$.ajax({		// type: "GET", // GET default url: urlprefix + "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Ferrari&cmlimit=500&cmnamespace=14&format=json", success: function ( response ) { // $(recuGallTag).html( JSON.stringify (response)); // for debugging var subcats = response['query']['categorymembers']; var t = ""; // " "; for (var i in subcats) { var title = subcats[i]['title']; // t = t + JSON.stringify(cat) + " "; // for debugging // t = t + "*" + title.replace("Category:","") + " "; // wikitext not what we want t = t + "   " + title + ""; }			t += ""; myShowresult(t); },		error: function ( response )  { mylog ( "Failure: " + response + " " + response.status + " " + response.statusText);} }).done( function( response ) { mylog("Hurray"); }); } );