User:CLoggermore/chat.js

// Refresh every 4 seconds window.chatReloadTime =4000; window.PrivateMessageAlert = $.extend(window.PrivateMessageAlert, {   beepSound: 'https://soundbible.com/grab.php?id=1645&type=mp3', //  beepSound: ['https://soundbible.com/grab.php?id=1645&type=mp3', 'https://soundbible.com/grab.php?id=1815&type=mp3'],    message: '$1 sent you a message!',    notifications: true,    alertWhileFocused: true,    interval: 2000 }); importArticles({   type: 'script',    articles: [         'u:dev:MediaWiki:ChatCount.js',         'u:dev:MediaWiki:ChatHacks.js',         'u:dev:MediaWiki:ChatImages/code.js',         'u:dev:MediaWiki:ChatMessageWallCount/code.js',         'u:dev:MediaWiki:ChatNotifications/code.js',         'u:dev:MediaWiki:ChatDeveloperTools.js',         'u:dev:MediaWiki:ChatPreloadButtons.js',         'u:dev:MediaWiki:MobileChat.js',         'u:dev:MediaWiki:Day/Night_chat/code.js',         'u:dev:MediaWiki:Custom-chat-ban-template/code.js',         'u:dev:MediaWiki:ChatEditTools/code.2.js',         'u:dev:MediaWiki:!block/code.js',         'u:dev:MediaWiki:FixAdminKick/code.js',         'u:dev:MediaWiki:GiveChatMod/code.js',         'u:dev:MediaWiki:LightBlock/code.js',         'u:dev:MediaWiki:EmoticonsWindow/code.js',         'u:dev:MediaWiki:ChatShortcuts.js',         'u:dev:MediaWiki:!pm.js',         'u:dev:MediaWiki:CapsFirst/code.js', 'u:dev:MediaWiki:ChatUserPageButton.js', 'u:dev:MediaWiki:PrivateMessageAlert/code.js', 'u:dev:MediaWiki:ChatAnnouncements/code.js', 'u:dev:MediaWiki:IsTyping.js', 'u:dev:MediaWiki:FixAdminKick/code.js', 'u:dev:MediaWiki:Tictactoe/code.js', 'u:dev:MediaWiki:ChatBanMessage.js', 'u:dev:MediaWiki:ChatReload/code.js', 'u:dev:MediaWiki:!kick/code.js', 'u:dev:MediaWiki:EmoticonsWindow/code.js', 'u:dev:MediaWiki:ResponsivePrivateList/code.js', 'u:dev:MediaWiki:ExtendedPrivateMessaging/code.js', 'u:dev:MediaWiki:ChatBlockButton/code.2.js', 'u:dev:MediaWiki:FasterBanModule/code.js', 'u:dev:MediaWiki:!mods.js', 'u:dev:MediaWiki:!ban/code.js' ] }); /** * !kick.js * * Allows use of !kick command in Special:Chat * @author: w:User:Slyst */ (function { var config = mw.config.get([       'wgCanonicalSpecialPageName',        'wgUserGroups'    ]), i18n, hierarchy = window.KickHierarchy || [ 'staff', 'sysop', 'helper', 'vstf', 'threadmoderator', 'chatmoderator' ];   if (        config.wgCanonicalSpecialPageName !== 'Chat' ||        !/staff|helper|sysop|threadmoderator|chatmoderator/.test(config.wgUserGroups.join)    ) { return; }   function inlineAlert(msg) { var $entry = $('', {           'class': 'inline-alert',            text: msg        }); if ($('.Chat li').last.hasClass('inline-alert')) { $entry.addClass('continued'); }       $('.Chat ul').append($entry); }   function getHighestGroup(user) { var min = 99; user.get('groups').forEach(function(group) {           var index = hierarchy.indexOf(group);            if (index !== -1 && min > index) {                min = index;            }        }); return min; }   function keydown(e) { if (e.which !== 13 || $(this).val.substr(0, 5) !== '!kick') { return; }       e.preventDefault; var username = $(this).val.substr(6), user = mainRoom.model.users.findByName(username), last = $('.Chat li').last.attr('data-user'); if (!user) { inlineAlert(               window.absentMessage ?                    window.absentMessage.replace(' ', username) :                    i18n.msg('absent', username).plain            ); return; }       if (            getHighestGroup(mainRoom.userMain) > getHighestGroup(user) &&            window.NoKickHigherUps        ) { inlineAlert(i18n.msg('higher', username).plain); return; }       mainRoom.kick({            name: username        }); $(this).val(''); }   mw.hook('dev.i18n').add(function(i18no) {        i18no.loadMessages('!kick').done(function (i18nd) { i18n = i18nd; $('[name="message"]').keydown(keydown); });   });    importArticle({        type: 'script',        article: 'u:dev:I18n-js/code.js'    }); }); /* * !ban w:c:dev:!ban * * Allows to block from chat without using the usual ban modal * Syntax: !ban USER NAME for BAN DURATION because BAN REASON * Alt Syntax: !ban USER NAME|BAN DURATION|BAN REASON * @author: w:User:Dorumin */ (function { var config = mw.config.get([       'wgCanonicalSpecialPageName',        'wgUserName'    ]), loaded = 0, i18n, wasDefault; if (       config.wgCanonicalSpecialPageName !== 'Chat' ||        window['!BanLoaded']    ) { return; }   window['!BanLoaded'] = true; [       'u:dev:MediaWiki:Chat-js.js', 'u:dev:MediaWiki:I18n-js/code.js' ].forEach(function(s) {       importArticle({ type: 'script', article: s });    }); // Taken and modified from w:c:dev:MediaWiki:QuickModTools/code.js. function calcTime(s) { if (s instanceof Number) { return s;       } var time = {}, i18n = { second: 1, minute: 60, hour: 3600, day: 86400, week: 604800, month: 2592000, year: 31536000 },           m = s.toLowerCase.match(/(\d+|an?) (second|minute|hour|day|week|month|year)/g); if (m === null && /never|infinite|indefinite|forever/i.test(s.toLowerCase)) { return 31536000000; } else if (m === null) { wasDefault = true; return window.defCBanDuration || 86400; // null } else if ($.isArray(m)) { // found match(es) var i;           for (i in m) { var a = m[i].split(' '); time[a[1]] = Number(a[0].replace(/an?/, '1')) * i18n[a[1]]; }           var timeCount = 0; for (i in time) { timeCount += time[i]; }           if (timeCount === 0) { wasDefault = true; return window.defCBanDuration || 86400; // equal to 0 seconds } else { return timeCount; }       } else { // no matches found - use default time wasDefault = true; return window.defCBanDuration || 86400; }   }    function keydown(e) { var $this = $(this), value = this.value; if (e.which === 13 && value.toLowerCase.substr(0, 5) === '!ban ') { e.preventDefault; var t = /\|/g.test(value) && !(                       / for | because (.+)?/gi.test(value) &&                        value.match(/ for | because (.+)?/gi).length === 2                    ) ? value.slice(5).split(/\|/g) : value.slice(5).split(/ for | because (.+)?/gi).filter(Boolean); $this.val(''); if (t[0] === config.wgUserName) { mainRoom.viewDiscussion.chatUL.append(                   $('', { 'class': 'inline-alert', text: i18n.msg('ban-you').plain })               );                mainRoom.viewDiscussion.scrollToBottom; return; }           mainRoom.socket.send(new models.BanCommand({ userToBan: t[0], time: calcTime(t[1] || window.defCBanDuration || ''), reason: t[2] || window.defCBanReason || i18n.msg('no-reason').plain }).xport); if (wasDefault) { mainRoom.viewDiscussion.chatUL.append(                   $('', { 'class': 'inline-alert', text: i18n.msg('time-invalid').plain })               );                mainRoom.viewDiscussion.scrollToBottom; wasDefault = false; }       }    }    function init(i18na) { i18n = i18na; $('[name="message"]').keydown(keydown); }   function preload { if (++loaded === 2) { if (!mainRoom.userMain.attributes.isModerator) { return; }           window.dev.i18n .loadMessages('!ban') .then(init); }   }    mw.hook('dev.i18n').add(preload); mw.hook('dev.chat.render').add(preload); });