User:DannyS712 test/in cat 3.js

var ok_ns = 0;

var CL_config = { name: 'cat links', version: 3.0, debug: true }; var CL_advert = 'Adding links with ' + CL_config.name + ' (version ' + CL_config.version + ')';

mw.loader.using( 'mediawiki.util', function {    importScript('User:DannyS712 test/append.js');    $(document).ready( function  { var link = mw.util.addPortletLink( 'p-cactions', '#', 'Cats', 'ca-cats', 'cats'); $( link ).click( function ( event ) {           event.preventDefault;            cats;        } ); } ); } ); function cats { var page = prompt("Please enter the category name (not including \"Category:\")", "Wikipedians"); var number = parseInt(prompt("How many links would you like added", "10"), 10);

if (number == -1){ ok_ns = parseInt(prompt("What namespace would you like to be included? (Use the namespace number)", "0"), 0); if (config.debug) console.log( ok_ns ); number = parseInt(prompt("How many links would you like added", "10"), 10); }	if (page === null || page === "") { console.log( "User cancelled the prompt." ); } else { console.log( page ); var catRequest = { action: 'query', list: 'categorymembers', cmnamespace: ok_ns, cmlimit: number, cmtitle: 'Category:' + page, cmprop: 'title', format: 'json' };		$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', catRequest, function( catResponse ) {			var pages = catResponse.query.categorymembers;			var listed = [];			var links = "";			for (var i = 0; i < pages.length; i++) {				if ( check_ns( pages[i].ns ) ) {					var link = make_link ( pages[i] );					listed.push(link);					links = links + link;				}			}			if ( links === "" ) {				alert( "There are no pages in the specified namespace in that category." );			}			else addNewSection( CL_advert, 'Pages in Category:' + page + '', links );		} ); } } function check_ns ( ns ){ if (config.debug) console.log ( ok_ns, ns); return ( ns === ok_ns ); } function make_link ( page ){ var title = page.title; if ( page.ns === 6 || page.ns === 14 ) title = ':' + title; var this_link = '* ' + title + '\n'; return this_link; }