User:DannyS712 test/FPC.js

// $(function { var FPC_config = {	name: 'FPC voter',	version: 1.0,	debug: true }; var FPC_summary = 'Vote with ' + FPC_config.name + ' (version ' + FPC_config.version + ')'; var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';

mw.loader.using( 'mediawiki.util', function {    $(document).ready( function  { mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'FPC voter', 'ca-FPC-vote', 'vote'); $('#ca-FPC-vote').on('click', function {       	FPC;    	} ); } ); } ); function FPC{ var vote = prompt("Please enter your vote (not including \bolding\)", "Support"); var reason = prompt("Please enter your rational (optional)", ""); var not_vote = "*" + vote + " - "; if (reason !== null && reason !== "") { not_vote = not_vote + reason + ' '; }	not_vote = not_vote + '~'; console.log(not_vote); var page = mw.config.get( 'wgPageName' ); var content = get_page( page ); console.log( content ); var comment = ""; var with_comment = not_vote + '\n' + comment; var new_content = content.replace( comment, with_comment); console.log( new_content ); set_page( page, new_content ); } function get_page( name ){ var page_to_get = { action: 'query', titles: name, prop: 'revisions', rvprop: 'content', format: 'json', formatversion: 2 };   var result = null; $.ajax({		url: scriptUrl,		type: 'get',		data: page_to_get,		dataType: 'json',		async: false,		success: function(page) {			if (FPC_config.debug) console.log( page );			result = page.query.pages["0"].revisions["0"].content;		   if (FPC_config.debug) console.log( result );		} 	}); return result; } function set_page ( page, new_content){ console.log( page, new_content ); var to_send = { action: 'edit', title: page, text: new_content, summary: FPC_summary, token: mw.user.tokens.get( 'csrfToken' ) };   console.log( to_send ); $.when(       $.post( scriptUrl, to_send, function( response ){ } )    ).done( function {		location.reload;    } ); } }); //