Jump to content

User:DannyS712 test/rating.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.
mw.loader.using( 'mediawiki.util', function () {
    $(document).ready( function () { 
        var link = mw.util.addPortletLink( 'p-cactions', '#', 'Get rating', 'ca-getRating', 'Get rating'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            getRating();
        } );
    } );
} );
function getRating () {
	return new Promise((resolve) => {
		var page = 'NASA|Alain Prost|Sébastien Ogier';
		var request = {
	        action: 'query',
	        titles: page,
	        prop: 'categories',
	        clcategories: 'Category:Good articles|Category:Featured articles',
	        format: 'json',
		    formatversion: 2
		};
		$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', request, function( response ) {
			console.log( response );
			if ( response && response.query && response.query.pages ) {
				console.log( response.query.pages );
				resolve( response.query.pages );
			}
			resolve ( false );
		} );
	} );
}