User:Dorumin/chat.js

importArticles({   type: 'script',    articles: [        'u:dev:PrivateHistory/code.js',        'u:dev:FaviconNotifier/code.js',        'u:dev:IsTyping/code.js',        'u:dev:Tabinsert.js', // WTF WHY ISNT IT TabInsert.js???        'u:dev:ExtendedPrivateMessaging/code.js',        'u:dev:PrivateMessageAlert/code.js',        'u:dev:EscapeEmoticons/code.js',        'u:dev:EmoticonsWindow/code.js'    ] });

(function reload {   if (!window.mainRoom) {        setTimeout(reload, 200);        return;    }    mainRoom.model.chats.bind('afteradd', function { var div = mainRoom.viewDiscussion.chatDiv.get(0); if (div.scrollHeight - div.scrollTop - div.clientHeight < 500) { mainRoom.viewDiscussion.scrollToBottom; }   });

mainRoom.model.privateUsers.bind('add', function(u) {       var room = mainRoom.chats.privates[u.attributes.roomId];        room.model.chats.bind('afteradd', function { var div = room.viewDiscussion.chatDiv.get(0); if (div.scrollHeight - div.scrollTop - div.clientHeight < 500) { room.viewDiscussion.scrollToBottom; }       });    });

// My homegrown LightBlock which actually removes continued messages var blocks = JSON.parse(localStorage.getItem('chat-blocks') || '[]'); mainRoom.viewDiscussion.getTextInput.on('keypress', function(e) {       if (e.which != 13) return;        var split = this.value.split(' '),        command = split[0],        rest = split.slice(1).join(' ');        switch (command) {            case '/block':                e.preventDefault;                this.value = ;                if (blocks.includes(rest)) {                    inline(rest + ' is already blocked.');                } else {                    blocks.push(rest);                    localStorage.setItem('chat-blocks', JSON.stringify(blocks));                    inline('Blocked ' + rest + '.');                    inline('Currently blocked users: ' + blocks.join(', '));                }                break;            case '/unblock':                e.preventDefault;                this.value = ;                var index = blocks.indexOf(rest);                if (index === -1) { inline(rest + ' is not blocked.'); } else { blocks.splice(index, 1); localStorage.setItem('chat-blocks', JSON.stringify(blocks)); inline('Unblocked ' + rest + '.'); inline('Currently blocked users: ' + blocks.join(', ')); }               break; case '/blocks': e.preventDefault; this.value = ''; inline('Currently blocked users: ' + blocks.join(', ')); break; }   });    mainRoom.model.chats.bind('afteradd', function(model) { if (blocks.includes(model.attributes.name)) { mainRoom.model.chats.remove(model); // No backing out }   });    function inline(text) {        mainRoom.model.chats.add(new models.InlineAlert({            text: text,            synthetic: true        }));    }    ['main', 'private'].forEach(function(scope) { mainRoom.viewUsers.bind(scope + 'ListClick', function {           $('#UserStatsMenu img').attr('src', function(_, src) { return src.replace('/scale-to-width-down/28', '/scale-to-width-down/150'); });       });    }); });