User:Dorumin/commands.​js

// Chat commands for stuff I do often.  importArticle({   type: 'script',    article: 'u:dev:MediaWiki:Chat-js.js' });

mw.hook('dev.chat.render').add(function {   function getCurrentRoom {        return mainRoom.chats.privates[mainRoom.activeRoom] || mainRoom;    }

window.ChatCommands = $.extend(window.ChatCommands, {       // Aliases        shrugs: 'shrug',        godwin: 'hitler',        boyz: 'pepper',        peper: 'pepper',        pepermint: 'pepper',        // Constants        oof: 'https://i.imgur.com/UUzGtDK.jpg',        pepper: 'https://i.imgur.com/NX3GZbj.png',        chatjs: 'chat.js',        chatcss: 'chat.css',        hitler: 'https://en.wikipedia.org/wiki/Godwin\'s_law',        coppa: 'https://coppa.org',        rules: 'rules',        // Dynamic        shrug: function(text) {            return text + ' ¯\\_(ツ)_/¯'        },        dev: function(text) {            var s = text.split(' '),            p = s.pop;            return s.join(' ') + ' ' + p + '';        },        // Useful functions        private: function(name) {            // No group PM support because XPM should handle that if (mainRoom.model.users.findByName(name) && name != wgUserName) { mainRoom.openPrivateChat([name]); } else { dev.chat.inlineAlert('Don\'t PM yourself, stupid'); }       },        fake: function(text) { if (!text.trim.length) return; var s = text.split(' '), name = s[0], i = 1, user; while (!(user = mainRoom.model.users.findByName(name))) { if (i > s.length) { name = wgUserName; i = 0; } else { name = s.slice(0, i++); }           }            var text = s.slice(i).join(' '), room = getCurrentRoom; room.model.chats.add(new models.ChatEntry({ roomId: room.roomId, name: name, text: text, avatarSrc: user.get('avatarSrc'), timeStamp: Date.now, id: -1, maxCharacterLimit: 1000 }));       }    });

mainRoom.viewDiscussion.getTextInput.on('keydown', function(e) {       if (e.which == 13 && !e.shiftKey) {            var v = e.target.value;            if (v[0] != '/') return;            var key = v.slice(1).split(' ')[0].toLowerCase,            short = v.slice(key.length + 2),            command = ChatCommands[key];            if (!command || !key) return;            if (typeof command == 'string') {                command = ChatCommands[command] || command;            }            e.target.value = typeof command == 'function' ? command(short) || '' : short + ' ' + command;        }    }); });