MediaWiki:GiveChatMod/code.js

/* * Name:        GiveChatMod * Description: Allows you to promote or demote user directly in chat * Author:      Rendann * Support:     Kopcap94 * Scripts used: * http://dev.wikia.com/wiki/MediaWiki:ChatBlockButton/code.3.js * http://dev.wikia.com/wiki/MediaWiki:MassCategorization/code.js */

$(function {   var call;    var config = mw.config.get([ 'wgUserName', 'wgUserGroups', 'wgContentLanguage', 'wgCanonicalSpecialPageName' ]);   var i18n = {        en: {            giveChatMod:  'Give ChatMod Status',            takeChatMod:  'Take ChatMod Status',            logPromote:   '$1 promoted $2 to be a chat moderator on this wiki',            logDemote:    '$1 demoted $2 to be a chat moderator on this wiki',            alertPromote: '$1 has promoted $2 to be a chat moderator.',            alertDemote:  '$1 has demoted $2 to be a chat moderator.'        }    };    i18n = i18n[config.wgContentLanguage] || i18n.en;

alias = $.fn.show; if (config.wgCanonicalSpecialPageName !== 'Chat' && config.wgUserGroups.indexOf('sysop') === -1) { return; }   $.fn.show = function { alias.apply(this, arguments); $( '.kick' ) .clone .addClass('give-chat-moderator') .removeClass('kick') .prependTo('.admin-actions');

if($('.give-chat-moderator svg').exists) { $('.give-chat-moderator svg')[0].setAttribute('viewBox','0 0 24 24');

$.get('/api.php', {               action: 'query',                list: 'users',                ususers: $('#UserStatsMenu .info ul .username').text,                usprop: 'groups',                format: 'json'            }, function(data){                if (data.query.users[0].groups.indexOf('chatmoderator') === -1) {                    $('.give-chat-moderator path').attr('d', 'M11 13v9a1 1 0 1 0 2 0v-9h9a1 1 0 1 0 0-2h-9V2a1 1 0 1 0-2 0v9H2a1 1 0 1 0 0 2h9z');                    $('.give-chat-moderator .label').text(i18n.giveChatMod);                    call = 1;                } else {                    $('.give-chat-moderator path').attr('d', 'M4.414 15H16a5 5 0 1 0 0-10H2a1 1 0 0 1 0-2h14a7 7 0 1 1 0 14H4.414l3.293 3.293a1 1 0 0 1-1.414 1.414l-5-5a.997.997 0 0 1 0-1.414l5-5a1 1 0 0 1 1.414 1.414L4.414 15z');                    $('.give-chat-moderator .label').text(i18n.takeChatMod); }           }

);       }        $('.give-chat-moderator').click(function { call == 1 ? giveChatMod( $('#UserStatsMenu .info ul .username').text ) : takeChatMod( $('#UserStatsMenu .info ul .username').text ); });   };    function giveChatMod(target) {        $.get( '/api.php', { action: 'query', list: 'users', ususers: target, ustoken: 'userrights', format: 'json' }, function(data) { $.post( '/api.php', {                   action: 'userrights',                    user: target,                    add: 'chatmoderator',                    reason: i18n.logPromote.replace('$1', config.wgUserName).replace('$2', target),                    token: data.query.users[0].userrightstoken,                    format: 'json'                    }, function(status) {                        var alert = new models.InlineAlert({text: i18n.alertPromote.replace('$1', config.wgUserName).replace('$2', target)});                        mainRoom.model.chats.add(alert);                        $('[name="message"]').val('').removeAttr('disabled').focus;            }); });   }

function takeChatMod(target) { $.get( '/api.php', {               action: 'query',                list: 'users',                ususers: target,                ustoken: 'userrights',                format: 'json'            }, function(data) {                $.post( '/api.php', { action: 'userrights', user: target, remove: 'chatmoderator', reason: i18n.logDemote.replace('$1', config.wgUserName).replace('$2', target), token: data.query.users[0].userrightstoken, format: 'json' }, function(status) { var alert = new models.InlineAlert({text: i18n.alertDemote.replace('$1', config.wgUserName).replace('$2', target)}); mainRoom.model.chats.add(alert); $('[name="message"]').val('').removeAttr('disabled').focus; });       });    } });