User:MACH-59330/chat.js

// QuickModTools configuration window.QuickModTools = { quickreasons: [ 'spam', 'sockpuppet', 'impersonation', 'inappropriate language', 'inappropriate username', 'Inappropriate language - please see the Chat Guidelines', 'Inappropriate discussion', 'Off-topic discussion - please see the Chat Guidelines', 'Impolite behaviour - please see the Chat Guidelines', 'Not complying with mod direction - please see the Chat Guidelines', 'Intimidating behaviour/harassment' ],   defbanreason: 'Misbehaving in chat - please see the Chat Guidelines', defbanlength: '86400' };

// Custom desktop notifications +ping class & PM. // uses code forked from TK-999 and Noreplyz) require(['wikia.window', 'jquery', 'mw'], function (window, $, mw) { // Notifications API support. if (!window.Notification) { return; }   // Variables. var me = mw.config.get('wgUserName'), pings = window.pings || new RegExp('(' + [ 'speed', 'help', 'mod', 'css', 'template', 'infobox', 'vanguard', 'discussions' ].join('|') + ')', 'gi'); // Main custom notification class. var customNotifications = { init: function { // Sound setup this.$sound = $(' ', {               'id': 'ChatNotification',                'src': 'https://images.wikia.nocookie.net/speedit/images/0/01/Notification.ogg',                'style': 'display: none;'            }).appendTo(document.body); // Delegate notification events. window.mainRoom.socket.bind('chat:add', $.proxy(this.main, this)); window.mainRoom.model.privateUsers.bind('add', $.proxy(this.priv, this)); // Request notification permission. $($.proxy(window.Notification.requestPermission, this, this.opt)); },       // Main room notification handler. main: function(m) { // Data & scope limiting. var d = JSON.parse(m.data).attrs; if (d.isInlineAlert || // ensure user message               !pings.test(d.text) || // ping list test                d.name == me // prevent self-pings            ) { return; }           // Configuration & styling. var c = { body: d.text, icon: d.avatarSrc.replace(/28(?!.*28)/, '150') };           mainRoom.viewDiscussion.chatUL .children('#entry-' + mainRoom.model.chats.models.slice(-1)[0].cid) .addClass('ping'); // Send notifications. this.$sound.get(0).play; if (window.navigator.vibrate) { window.navigator.vibrate(200); }           if (!document.hasFocus ||                mainRoom.viewDiscussion.chatDiv.css('display') == 'none'            ) { var o = new window.Notification(d.name, c); setTimeout(o.close.bind(o), 5000); }       },        // Private message notification handler. priv: function(p) { var pid = p.attributes.roomId; var pr = window.mainRoom.chats.privates[pid]; pr.model.chats.bind('afteradd', $.proxy(function(m) { var d = m.attributes, u = d.name; if (                   u == me ||                    ($('Chat_' + pid).css('display') != 'none' && document.hasFocus)               ) { return; }               var a = d.avatarSrc.replace(/28(?!.*28)/, '150'), t = 'PM from ' + u,                   c = { body: d.text, icon: a }, o = new window.Notification(t, c); if (window.navigator.vibrate) { window.navigator.vibrate([200, 100, 200]); }               this.$sound.get(0).play; setTimeout(o.close.bind(o), 5000); }, this)); },       // Notifications API permission. opt: function(r) { if (r !== "granted") { window.mainRoom.socket.unbind(                   'chat:add', this.main                ); window.mainRoom.model.privateUsers.unbind(                   'add', this.priv                ); }       }    };    mw.hook('dev.chat').add(        $.proxy(customNotifications.init, customNotifications)    ); importArticles({       'type': 'script',        'article': 'u:dev:Chat-js.js'    }); });

// Add "data-user" attribute to join messages for QuickModTools mw.hook('dev.chat.render').add(function(mainRoom) {   var regexp = new RegExp( mw.messages.get('chat-user-joined') .replace(/([^A-Za-z0-9_\s:$])/g, '\\$1') .replace(/\$1/g, '([\\s\\S]+)') );   function insertJoinAttr(m) {        if ( !m.attributes.isInlineAlert || !regexp.test(m.attributes.text) ) {           return;        }         var u = m.attributes.text.match(regexp)[1];         mainRoom.viewDiscussion.chatUL             .children('#entry-' + m.cid)             .attr('data-user', u);    }    mainRoom.model.chats.bind('add', insertJoinAttr); }); importArticles({ 'type': 'script', 'article': 'u:dev:Chat-js.js' });

// Chat imports importArticles({   type: 'script',    articles: [        'u:dev:FasterBanModule/code.js',        'u:dev:MessageBlocker/code.js',        'u:dev:QuickModTools/code.js',        'u:dev:EmoticonsWindow/code.js',        'u:dev:MobileChat.js'    ] });