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', 'mw'], function (context, mw) {   // Scoping and    if (!context.Notification) {        return;    }    //     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            context.mainRoom.socket.bind('chat:add', this.main);            context.mainRoom.model.privateUsers.bind('add', this.priv);            // Request notification permission            $.proxy(context.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')                },                l = '#Chat_' + context.mainRoom.roomId + ' li:last-of-type';            $(l).addClass('ping');            // Send notifications            customNotifications.$sound.get(0).play;            if (context.navigator.vibrate) {                context.navigator.vibrate(200);            }            if (!document.hasFocus || $('#Chat_' + window.mainRoom.roomId).css('display') == 'none' ) {               var o = new context.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[id];            pr.model.chats.bind('afteradd', 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 ' + user, c = { body: d.text, icon: a }, o = new context.Notification(t, c); if (context.navigator.vibrate) { context.navigator.vibrate([200, 100, 200]); }               customNotifications.$sound.get(0).play; setTimeout(o.close.bind(o), 5000); });       },        // Notifications API permission        opt: function(r) {            if (r !== "granted") {                context.mainRoom.socket.unbind( 'chat:add', this.main );               context.mainRoom.model.privateUsers.unbind( 'add', this.priv );           }        }    };    mw.hook('dev.chat').add( $.proxy(customNotifications.init, customNotifications) );   importArticles({ 'type': 'scripts', 'article': 'u:dev:MediaWiki:Chat-js.js' }); });

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