allie test

tab

Version vom 10.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/1605159/allie%20test.js

Tabs.Chat = {
    tabOrder: 900,
    tabLabel: 'Chat',
    tabDisabled: false,
    myDiv: null,
    globalChatDiv: null,
    allianceChatDiv: null,
    inputDiv: null,
    currentChatType: 'global',

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

    createMainDiv: function() {
        var t = Tabs.Chat;
        var m = '<DIV class=divHeader align=center>' + tx('CHAT') + '</div>';

        m += '<div id="pbChatTabs" style="margin-bottom:10px;">';
        m += '<button id="pbGlobalChatTab" class="tabActive">Global Chat</button>';
        m += '<button id="pbAllianceChatTab">Alliance Chat</button>';
        m += '</div>';

        // Container for side-by-side chat divs
        m += '<div style="display: flex;">';
        m += '<div id="pbGlobalChatContent" style="height:400px; max-height:400px; overflow-y:auto; width: 50%;"></div>';
        m += '<div id="pbAllianceChatContent" style="height:400px; max-height:400px; overflow-y:auto; width: 50%; display:none;"></div>';
        m += '</div>';

        m += '<div id="pbChatInput" style="margin-top:10px;"></div>';

        t.myDiv.innerHTML = m;

        t.globalChatDiv = ById('pbGlobalChatContent');
        t.allianceChatDiv = ById('pbAllianceChatContent');
        t.inputDiv = ById('pbChatInput');

        ById('pbGlobalChatTab').addEventListener('click', function () { t.switchChatType('global'); });
        ById('pbAllianceChatTab').addEventListener('click', function () { t.switchChatType('alliance'); });

        t.cloneGameChatInput();
    },

    hookGameChat: function() {
        var t = Tabs.Chat;
        var gameChatContainer = document.querySelector('#mod_comm_list1');
        var gameAllianceChatContainer = document.querySelector('#mod_comm_list2');

        if (gameChatContainer && gameAllianceChatContainer) {
            var observerGlobal = new MutationObserver(function (mutations) {
                t.updateChat('global');
            });

            var observerAlliance = new MutationObserver(function (mutations) {
                t.updateChat('alliance');
            });

            observerGlobal.observe(gameChatContainer, { childList: true, subtree: true });
            observerAlliance.observe(gameAllianceChatContainer, { childList: true, subtree: true });

            t.updateChat('global');
            t.updateChat('alliance');
        } else {
            console.error('Could not find game chat containers');
        }
    },

    updateChat: function(chatType) {
        var t = Tabs.Chat;
        var gameChatContainer = (chatType === 'global') ?
            document.querySelector('#mod_comm_list1') :
            document.querySelector('#mod_comm_list2');
        var targetDiv = (chatType === 'global') ? t.globalChatDiv : t.allianceChatDiv;

        if (gameChatContainer && targetDiv) {
            targetDiv.innerHTML = gameChatContainer.innerHTML;
            targetDiv.scrollTop = targetDiv.scrollHeight;
        }
    },

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

            var chatTextArea = t.inputDiv.querySelector('textarea');
            var sendButton = t.inputDiv.querySelector('button');

            if (chatTextArea && sendButton) {
                chatTextArea.addEventListener('keypress', function (e) {
                    if (e.key === 'Enter' && !e.shiftKey) {
                        e.preventDefault();
                        t.sendChat();
                    }
                });

                sendButton.addEventListener('click', function () {
                    t.sendChat();
                });
            }
        } else {
            console.error('Could not find game chat input');
        }
    },

    sendChat: function() {
        var t = Tabs.Chat;
        var chatTextArea = t.inputDiv.querySelector('textarea');
        var gameChatTextArea = document.querySelector('#mod_comm_input textarea');
        var gameSendButton = document.querySelector('#mod_comm_input button');
        var gameChatTypeSelector = document.querySelector('#mod_comm_tabs');

        if (chatTextArea && gameChatTextArea && gameSendButton && gameChatTypeSelector) {
            var message = chatTextArea.value.trim();
            if (message !== '') {
                // Set the correct chat type in the game's interface
                if (t.currentChatType === 'global') {
                    gameChatTypeSelector.selectedIndex = 0; // Assuming 0 is for global chat
                } else if (t.currentChatType === 'alliance') {
                    gameChatTypeSelector.selectedIndex = 1; // Assuming 1 is for alliance chat
                }

                gameChatTextArea.value = message;
                gameSendButton.click();
                chatTextArea.value = '';
            }
        } else {
            console.error('Could not find necessary elements to send chat');
        }
    },

    switchChatType: function(chatType) {
        var t = Tabs.Chat;
        t.currentChatType = chatType;

        if (chatType === 'global') {
            t.globalChatDiv.style.display = 'block';
            t.allianceChatDiv.style.display = 'none';
            ById('pbGlobalChatTab').className = 'tabActive';
            ById('pbAllianceChatTab').className = '';
        } else {
            t.globalChatDiv.style.display = 'none';
            t.allianceChatDiv.style.display = 'block';
            ById('pbGlobalChatTab').className = '';
            ById('pbAllianceChatTab').className = 'tabActive';
        }
    }
};