User:Ahecht/sandbox7

From Wikipedia, the free encyclopedia
function getRcats(cont='', cmcont='') {
	new mw.Api().get(
		{action:'query', format:'json', redirects:'true', list:'categorymembers', cmtitle:'Category:Redirect templates', cmnamespace:10, cmtype:'page', continue:cont, cmcontinue:cmcont, cmlimit:'max'}
	).done( (result) => {
		if (result?.query?.categorymembers) {
			result.query.categorymembers.forEach( (e) => {
				select.append( $( "<option>" ).attr( "value", e.title ).text( e.title.slice(9) ) );
			} );
			if (result.continue) {
				getRcats(result.continue.continue, result.continue.cmcontinue)
			} else {
				$( '.mw-content-container' ).append( select );
				select.chosen({search_contains: true});
			}
		} else {console.warn("error");console.log(result);}
	} ).fail( (e) => {console.warn(e)} );
}

mw.loader.load(["jquery.chosen"]);
var select = $( "<select>" ).attr( "id", "rcat-chooser-form" ).on("change", () => {console.log(select.val());});
rCats = []
getRcats()