User:Doork/chat.js

/* Make code load only when the menu appears else it won't work */ $('#WikiChatList li').click(function {   $('.UserStatsMenu').on('DOMNodeInserted', function  { //only appears if user is not a mod/staff

/* Add CSS rule to new block button to have block image */ mw.util.addCSS('.UserStatsMenu .actions ul li.givemod .icon { background-position: -614px 0px}');

/* Clone the kick button and change the class; rather than creating a new one from scratch, this keeps the styling intact and equal to the existing buttons */ var Button = $('.kick').clone.addClass('givemod').removeClass('kick');

$(this).children('.actions').children('.admin-actions').append(         Button        );

$('.givemod .label').text('Give ChatMod');

$('.givemod').click(function {	   	  // Custom inline alerts          function inlineAlert(msg) {            mainRoom.model.chats.add(new models.InlineAlert({text:msg}));            $('[name="message"]').val('').removeAttr('disabled').focus;          }            var name = $(this).parents.eq(2).children('.info').children('ul').children('.username').text,              Api = new mw.Api;          	  $.getJSON("/api.php?action=query&list=users&ustoken=userrights&ususers=" + name + "&format=json", function(token) { var config = { action: 'userrights', user: name, add: 'chatmoderator', reason: 'Promoted to chat moderator by ' + wgUserName + '.', token: token.query.users[0].userrightstoken };           Api.post(config) .done(function(d) {              if (!d.error) {                inlineAlert(name + 'successfully promoted to chat moderator.')              } else {                inlineAlert('Failed to promote: '+ d.error.code);              }            }) .fail(function {             inlineAlert('Failed to promote.');            }); });       });    });  });