MediaWiki:Gadget-Botify.js

// // Will Bot the user just before the Replace Text starts // Notes: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api //

/* Either Bots or Unbots the current user */ function botify( addOrRemove, callback ) { var hasCallback = ( arguments.length >= 2 ); //Create api options object var apiOptions = { action: 'userrights', user: mw.config.get("wgUserName"), };	apiOptions[addOrRemove] = 'bot'; //Use POST to change bot userright (new mw.Api).postWithToken('userrights', apiOptions).done(function(data){		console.log(data);		console.log("Botify success.");		mw.notify("Botify success.");		if (hasCallback) {			callback;		}	}).fail(function{		console.log("Error in botify.");		mw.notify("Error in botify.");	}); }

/* Adds an Event Listener for the Replace Text submit button */ function botOnReplaceText { $('#choose_pages').on('submit', function(e){		e.preventDefault;		botify('add', function{ $('#choose_pages').off('submit').submit; });	}); }

//When document ready: $(function{	botOnReplaceText;	//Link in Tools in sidebar to bot	mediaWiki.util.addPortletLink("p-tb", "#", "Rebot", "ca-rebot", "Click to rebot");	console.log("Rebot link added");	//Event listener for that link	$("#ca-rebot").on("click", function(e){ e.preventDefault; botify('add'); }); console.log("Rebot click event added");	//Link in Tools in sidebar to unbot	mediaWiki.util.addPortletLink("p-tb", "#", "Unbot", "ca-unbot", "Click to unbot");	console.log("Unbot link added");	//Event listener for that link	$("#ca-unbot").on("click", function(e){ e.preventDefault; botify('remove'); }); console.log("Unbot click event added"); });