allie test

tab

当前为 2025-06-08 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/538683/1603854/allie%20test.js

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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: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 !== '') {
            if (typeof uW.Chat === 'object' && typeof uW.Chat.sendMsg === 'function') {
                uW.Chat.sendMsg(message);
                chatTextArea.value = '';
                t.updateChat();
            } else {
                console.error('Could not find game chat send function');
            }
        }
    }
};