User:MZMcBride/coords.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.
/**
 * Simple title coords remover
 * @author MZMcBride
 * Public domain; 2022
 */

var coordslink = mw.util.addPortletLink(
	'p-cactions',
	'#',
	'Cooooooords',
	'ca-coords',
	'Cooooooords',
	'c'
);

// Bind click handler
$( coordslink ).click( function () {
	var page_title = mw.config.get('wgPageName');
	coords( page_title );
});

function coords( page_title ) {
	var api = new mw.Api();

	api.get( {
		action: 'query',
		meta: 'tokens',
		type: 'csrf',
		format: 'json'
	} ).done( 

		function( data ) {
			var edit_token = data.query.tokens.csrftoken;
			api.post( {
				action: 'edit',
				title: page_title,
				summary: 'coords in the infobox seem sufficient',
				token: edit_token
			} ).done(

				function( data ) {
					window.close();
					if (!window.closed) {
						window.location = '/wiki/'+page_title;
					}
				}

			);
		}
	);
}