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/1603859/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();
        t.debugGameChat(); // Debug function to help understand the game's chat system
    },

    createMainDiv: function(){
        var t = Tabs.Chat;
        var m = '<DIV class=divHeader align=center>'+tx('CHAT')+'</div>';
        
        m += '<div id="pbChatContent" class="pbChatContainer" style="height:400px; max-height:400px; overflow-y:auto;"></div>';
        m += '<div id="pbChatInput" style="margin-top:10px;">';
        m += '<textarea id="pbChatTextArea" rows="3" style="width:100%; margin-bottom:5px;"></textarea>';
        m += '<button id="pbChatSendButton" style="width:100%;">Send</button>';
        m += '</div>';

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

        // Add event listeners
        ById('pbChatTextArea').addEventListener('keypress', function(e) {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                t.sendChat();
            }
        });

        ById('pbChatSendButton').addEventListener('click', function() {
            t.sendChat();
        });

        t.hookChat();
    },

    applyCustomStyles: function(){
        var styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.innerHTML = `
            .pbChatContainer .chat-message {
                text-align: right;
                direction: rtl;
                margin-bottom: 5px;
            }
            .pbChatContainer .chat-message .chat-time {
                float: left;
                color: #888;
            }
            .pbChatContainer .chat-message .chat-user {
                margin-left: 5px;
                font-weight: bold;
            }
            .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) {
            t.updateChat();

            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');
        }
    },

    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(){
        var t = Tabs.Chat;
        var chatTextArea = ById('pbChatTextArea');
        var message = chatTextArea.value.trim();
        
        if (message !== '') {
            var sent = false;

            // Method 1: Try using the game's Chat object
            if (typeof uW.Chat === 'object' && typeof uW.Chat.sendMsg === 'function') {
                try {
                    uW.Chat.sendMsg(message);
                    sent = true;
                } catch (e) {
                    console.error('Error using uW.Chat.sendMsg:', e);
                }
            }

            // Method 2: Try to find and trigger the game's send button
            if (!sent) {
                var gameSendButton = document.querySelector('#mod_comm_input button');
                if (gameSendButton) {
                    var gameTextArea = document.querySelector('#mod_comm_input textarea');
                    if (gameTextArea) {
                        gameTextArea.value = message;
                        gameSendButton.click();
                        sent = true;
                    }
                }
            }

            // Method 3: Try to dispatch a custom event that the game might be listening for
            if (!sent) {
                var chatEvent = new CustomEvent('chatMessage', { detail: { message: message } });
                document.dispatchEvent(chatEvent);
                sent = true;
            }

            if (sent) {
                chatTextArea.value = '';
                t.updateChat();
            } else {
                console.error('Failed to send chat message');
                alert('Failed to send chat message. Please try again.');
            }
        }
    },

    debugGameChat: function() {
        console.log('Chat object:', uW.Chat);
        console.log('Chat input element:', document.querySelector('#mod_comm_input'));
        console.log('Chat send button:', document.querySelector('#mod_comm_input button'));
        console.log('Chat textarea:', document.querySelector('#mod_comm_input textarea'));
        
        // Try to find any functions related to chat
        for (var key in uW) {
            if (typeof uW[key] === 'function' && key.toLowerCase().includes('chat')) {
                console.log('Potential chat function:', key);
            }
        }
    }
};