MediaWiki:Bot-me.js

// API call was by Doru and help from Kocka to prompt reason

var ug = mw.config.get("wgUserGroups"); if ( (ug.indexOf('AW-Staff') + ug.indexOf('CVU') ) > -2 ){ var isBot = mw.config.get("wgUserGroups").includes('Bot');
 * (function($, mw) {

var msg = isBot === true ? "Remove Bot Flag" : "Bot Me";

// monobook & vector support if ( (mw.config.get('skin') === 'monobook') || (mw.config.get('skin') === 'vector')) { $.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function { 				mw.util.addPortletLink('p-tb', '#', msg, 't-bot');			} ); }		$('#t-bot').click(function {			var reason = prompt('Enter reason');			if (!reason) {				reason = prompt('Enter reason');			}			else {				if (isBot) {					removeFlag(reason);				}				else {					botMe(reason);				}			}		});

function botMe(reason) { var Api = new mw.Api; Api.get({				action: 'query',				list: 'users',				ususers: mw.config.get("wgUserName"),				ustoken: 'userrights'			}).done(function(d) {				Api.post({ action: 'userrights', user: mw.config.get("wgUserName"), reason:reason, token: d.query.users[0].userrightstoken, add: 'Bot' }).done(function(r) { alert("you now have a bot flag"); });			}); }		function removeFlag(reason) { var Api = new mw.Api; Api.get({				action: 'query',				list: 'users',				ususers: mw.config.get("wgUserName"),				ustoken: 'userrights'			}).done(function(d) {				Api.post({ action: 'userrights', user: mw.config.get("wgUserName"), reason:'removing bot flag', token: d.query.users[0].userrightstoken, remove: 'Bot' }).done(function(r) { alert("removing the bot flag"); });			}); }	} }) (this.jQuery, this.mediaWiki);