Jump to content

User:JJPMaster/Scripts/GreenAndGold.js

From Wikipedia, the free encyclopedia
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.
$(function() {
	const wikiSlash = mw.config.get("wgArticlePath").replace("$1", '');
	const links = $("#mw-content-text").find(`a[href^='${wikiSlash}']`);
	let titles = [];
	let finalTitle;
	$(links).each(function() {
			titles.push(decodeURI($(this).attr("href").replace(wikiSlash, '')));
	    	
	});
	let queryableTitles = titles.slice(0, 40);
	finalTitle = queryableTitles.join("|");
	var params = {
		action: 'query',
		format: 'json',
		list: 'categorymembers',
		cmtitle: "Featured articles"
	},
	api = new mw.Api();

	api.get( params ).done( function ( data ) {
		// var pages = data.query.pages,
		// 	p;
		// for ( p in pages ) {
		// 	pages[ p ].categories.forEach( function ( cat ) {
		// 		console.log( cat.title );
		// 	} );
		// }
		console.log(data);
	});
	// $.get('/w/api.php?' +
	//     $.param({
	//         format: 'json',
	//         action: 'query',
	//         prop: 'categories',
	//         titles: finalTitle
	//     })).done(function(data) { console.log(data) });
	
	
});