MediaWiki:WorkingMoreUsersCount.js

/* WorkingMoreUsersCount * * Ever fooled by the +n at the side of the minimal user list on the chat rail module? * Never again. * Shows a modal with all the users currently in chat when clicked. * * For personal use * @author Dorumin */ $(window).on('load', function {   importArticles({ type: 'style', article: 'u:the-iron-sandbox:MediaWiki:WorkingMoreUsersCount.css' });   $('body')        .off('click', '.WikiaChatLink, .chat-module .start-a-chat-button, .chat-module .more-users-count', ChatWidget.openChat)        .on('click', '.WikiaChatLink, .chat-module .start-a-chat-button', ChatWidget.openChat);    $('.chat-module .more-users-count').on('click', function(e) { e.preventDefault; var $ajax = $(' ', {           id: 'uc-modal-ajax',            src: window.stylepath + '/common/images/ajax.gif',            alt: 'loading...'        }), $userlist = $('', {           id: 'uc-modal-userlist'        }), $user = $('', {           class: 'uc-modal-user',            append: [                $(' ', { class: 'avatar' }),               $('', { class: 'uc-username' }),               $(' ', {                    class: 'uc-actions' })           ]        }),        modal; $.showCustomModal('Users', $ajax, {           callback: function(usersModal) {                modal = usersModal;            }        }); /* wgWikiaChatUsers is usually defined globally on all pages, but we want to have the latest version */ $.get('/wikia.php?controller=Chat&format=json', (d) => {           modal.find('.modalContent').empty.append($userlist);            var str = d.globalVariablesScript,            fixedJson = str                .match(/"wgWikiaChatUsers":\s*(\[[\s\S]+?\])/)[1]                    .replace(/\\x([0-9a-f]{2})/g, '\\u00$1'),            json = JSON.parse(fixedJson),            arr = json.sort(function(a,b) {                return a.username.localeCompare(b.username);            }).reverse,            i = arr.length;            while (i--) {                var item = arr[i],                $el = $user.clone,                encodedName = encodeURIComponent(item.username);                $el.find('.avatar')                    .attr('src', item.avatarUrl);                $el.find('.uc-username')                    .attr('href', '/wiki/User:' + encodedName)                    .text(item.username);                $el.find('.uc-actions').append(                    $('', {                        href: item.profileUrl,                        html: item.profileIcon                    }),                    $('', {                        href: item.contribsUrl,                        html: item.contribIcon                    })                );                $userlist.append($el);            }        });    }); });