allie test

tab

Version vom 08.06.2025. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.ip-ddns.com/scripts/538683/1603842/allie%20test.js

Tabs.Chat = {
    tabOrder: 900,
    tabLabel: 'Chat',
    tabDisabled: false,
    myDiv: null,
    chatDiv: null,
    inputDiv: null,

    init: function(div){
        var t = Tabs.Chat;
        t.myDiv = div;
        t.createMainDiv();
        t.applyCustomStyles();
    },

    createMainDiv: function(){
        var t = Tabs.Chat;
        var m = '<DIV class=divHeader align=center>'+tx('CHAT')+'</div>';
        
        m += '<div id="pbChatContent" class="pbChatContainer" style="height:450px; max-height:450px; overflow-y:auto;"></div>';
        m += '<div id="pbChatInput" style="margin-top:10px;"></div>';

        t.myDiv.innerHTML = m;
        
        t.chatDiv = ById('pbChatContent');
        t.inputDiv = ById('pbChatInput');

        t.hookChat();
    },

    applyCustomStyles: function(){
        var styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.innerHTML = `
            .pbChatContainer .chat-message {
                text-align: right;
                direction: rtl;
            }
            .pbChatContainer .chat-message .chat-time {
                float: left;
            }
            .pbChatContainer .chat-message .chat-user {
                margin-left: 5px;
            }
            .pbChatContainer .chat-message .chat-text {
                display: inline-block;
                direction: ltr;
                text-align: left;
            }
        `;
        document.head.appendChild(styleElement);
    },

    hookChat: function(){
        var t = Tabs.Chat;
        
        var gameChatContainer = document.querySelector('#mod_comm_list1');
        if (gameChatContainer) {
            var chatClone = gameChatContainer.cloneNode(true);
            t.chatDiv.appendChild(chatClone);

            var observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if (mutation.type === 'childList') {
                        t.updateChat();
                    }
                });
            });

            observer.observe(gameChatContainer, { childList: true, subtree: true });
        } else {
            console.error('Could not find game chat container');
        }

        var gameChatInput = document.querySelector('#mod_comm_input');
        if (gameChatInput) {
            var inputClone = gameChatInput.cloneNode(true);
            t.inputDiv.appendChild(inputClone);

            var chatTextArea = t.inputDiv.querySelector('textarea');
            if (chatTextArea) {
                chatTextArea.addEventListener('keypress', function(e) {
                    if (e.key === 'Enter' && !e.shiftKey) {
                        e.preventDefault();
                        t.sendChat(this.value);
                        this.value = '';
                    }
                });
            }
        } else {
            console.error('Could not find game chat input');
        }
    },

    updateChat: function(){
        var t = Tabs.Chat;
        var gameChatContainer = document.querySelector('#mod_comm_list1');
        if (gameChatContainer && t.chatDiv) {
            t.chatDiv.innerHTML = gameChatContainer.innerHTML;
            t.chatDiv.scrollTop = t.chatDiv.scrollHeight;
            
            // Add our custom class to each chat message
            var chatMessages = t.chatDiv.querySelectorAll('.chat-message');
            chatMessages.forEach(function(message) {
                message.classList.add('pbChatMessage');
            });
        }
    },

    sendChat: function(message){
        if (typeof uW.Chat === 'object' && typeof uW.Chat.sendMsg === 'function') {
            uW.Chat.sendMsg(message);
        } else {
            console.error('Could not find game chat send function');
        }
    }
};