MediaWiki:Bot-me.js

// assistance from Doru, Kocka, Becasita, Stjn // api call is broken

var ug = mw.config.get("wgUserGroups"); var skin = ((mw.config.get('skin') === 'monobook') || (mw.config.get('skin') === 'vector')); var isBot = mw.config.get("wgUserGroups").includes('Bot');
 * (function($, mw) {

if ( (ug.indexOf('AW-Staff') + ug.indexOf('CVU') ) > -2 && skin){ var msg = isBot === true ? "Remove Bot Flag" : "Bot Me"; if ($("#t-fd").length > 0) {return;} else { $.when( mw.loader.using( 'mediawiki.util' ), mw.loader.using( 'mediawiki.api' ), $.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);