Greasy Fork

Greasy Fork is available in English.

allie test

tab

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    init: function(div){
        var t = Tabs.Chat;
        t.myDiv = div;
        t.createMainDiv();
        t.applyCustomStyles();
        t.startPolling();
        t.debug('Chat tab initialized');
    },

    createMainDiv: function(){
        var t = Tabs.Chat;
        var m = '<DIV class=divHeader align=center>'+tx('CHAT')+'</div>';
        
        m += '<div id="pbChatContent" 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.cloneGameChatInput();
    },

    applyCustomStyles: function(){
        var styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.innerHTML = `
            #pbChatContent .chat-message {
                display: flex;
                flex-direction: row-reverse;
                justify-content: flex-start;
                align-items: baseline;
                margin-bottom: 5px;
                text-align: right;
            }
            #pbChatContent .chat-time {
                margin-left: 5px;
                color: #888;
                font-size: 0.8em;
            }
            #pbChatContent .chat-user {
                margin-left: 5px;
                font-weight: bold;
            }
            #pbChatContent .chat-text {
                word-wrap: break-word;
                max-width: 80%;
            }
        `;
        document.head.appendChild(styleElement);
    },

    startPolling: function() {
        var t = Tabs.Chat;
        t.pollInterval = setInterval(function() {
            t.checkForNewMessages();
        }, 1000); // Check every second
    },

    checkForNewMessages: function() {
        var t = Tabs.Chat;
        var gameChatContainer = document.querySelector('#mod_comm_list1');
        if (gameChatContainer) {
            var messages = gameChatContainer.querySelectorAll('.chat-message');
            if (messages.length > t.lastMessageCount) {
                t.debug('New messages detected');
                for (var i = t.lastMessageCount; i < messages.length; i++) {
                    var clonedMessage = messages[i].cloneNode(true);
                    t.formatChatMessage(clonedMessage);
                    t.chatDiv.appendChild(clonedMessage);
                }
                t.lastMessageCount = messages.length;
                t.chatDiv.scrollTop = t.chatDiv.scrollHeight;
            }
        } else {
            t.debug('Game chat container not found');
        }
    },

    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 {
            t.debug('Game chat input not found');
        }
    },

    formatChatMessage: function(messageElement) {
        var timeElement = messageElement.querySelector('.chat-time');
        var userElement = messageElement.querySelector('.chat-user');
        var textElement = messageElement.querySelector('.chat-text');

        if (timeElement) timeElement.textContent = '[' + timeElement.textContent + ']';
        if (userElement) userElement.textContent = userElement.textContent + ':';

        // Ensure elements are in the correct order
        if (textElement) messageElement.appendChild(textElement);
        if (userElement) messageElement.appendChild(userElement);
        if (timeElement) messageElement.appendChild(timeElement);
    },

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

        if (chatTextArea && gameChatTextArea && gameSendButton) {
            var message = chatTextArea.value.trim();
            if (message !== '') {
                gameChatTextArea.value = message;
                gameSendButton.click();
                chatTextArea.value = '';
                t.debug('Chat message sent: ' + message);
            }
        } else {
            t.debug('Could not find necessary elements to send chat');
        }
    },

    debug: function(message) {
        console.log('Chat Tab Debug: ' + message);
    }
};