Greasy Fork

Greasy Fork is available in English.

allie test

tab

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/538683/1605108/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,
    chatTimer: null,
    
    init: function(div) {
        var t = Tabs.Chat;
        t.myDiv = div;
        
        // Create the chat interface
        t.createChatInterface();
        
        // Start monitoring for new messages
        t.startChatMonitor();
    },
    
    createChatInterface: function() {
        var t = Tabs.Chat;
        
        var m = '<div class="divHeader" align="center">CHAT</div>';
        
        // Chat tabs
        m += '<div id="pbChatTabs" style="margin-bottom:10px;">';
        m += '<ul class="tabs">';
        m += '<li class="tab active" id="pbGlobalChatTab" onclick="Tabs.Chat.switchTab(\'global\')">Global</li>';
        m += '<li class="tab" id="pbAllianceChatTab" onclick="Tabs.Chat.switchTab(\'alliance\')">Alliance</li>';
        m += '</ul>';
        m += '</div>';
        
        // Chat content area
        m += '<div id="pbChatContent" style="height:400px; border:1px solid #888; margin-bottom:10px; overflow-y:auto; padding:5px;"></div>';
        
        // Chat input area
        m += '<div id="pbChatInputArea" style="display:flex;">';
        m += '<input type="text" id="pbChatInput" style="flex-grow:1; padding:5px; margin-right:5px;" placeholder="Type your message here..." />';
        m += '<button id="pbChatSend" style="padding:5px 15px;" onclick="Tabs.Chat.sendChat()">Send</button>';
        m += '</div>';
        
        t.myDiv.innerHTML = m;
        
        // Add event listener for Enter key
        document.getElementById('pbChatInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                Tabs.Chat.sendChat();
            }
        });
        
        // Initialize with global chat
        t.currentTab = 'global';
        t.updateChatDisplay();
    },
    
    switchTab: function(tabName) {
        var t = Tabs.Chat;
        
        // Update tab UI
        document.getElementById('pbGlobalChatTab').className = 'tab' + (tabName === 'global' ? ' active' : '');
        document.getElementById('pbAllianceChatTab').className = 'tab' + (tabName === 'alliance' ? ' active' : '');
        
        // Set current tab
        t.currentTab = tabName;
        
        // Update chat display
        t.updateChatDisplay();
    },
    
    updateChatDisplay: function() {
        var t = Tabs.Chat;
        var chatContent = document.getElementById('pbChatContent');
        
        // Find the appropriate game chat container based on current tab
        var gameChat = null;
        if (t.currentTab === 'global') {
            gameChat = document.querySelector('#mod_comm_list1');
        } else {
            gameChat = document.querySelector('#mod_comm_list2');
        }
        
        // If we found the game chat, copy its content
        if (gameChat) {
            chatContent.innerHTML = gameChat.innerHTML;
            chatContent.scrollTop = chatContent.scrollHeight;
        } else {
            chatContent.innerHTML = '<div style="color:#888; text-align:center; padding:20px;">Chat not available</div>';
        }
    },
    
    startChatMonitor: function() {
        var t = Tabs.Chat;
        
        // Clear any existing timer
        if (t.chatTimer) {
            clearInterval(t.chatTimer);
        }
        
        // Set up a timer to check for new messages
        t.chatTimer = setInterval(function() {
            if (t.myDiv.style.display !== 'none') {
                t.updateChatDisplay();
            }
        }, 2000); // Check every 2 seconds
    },
    
    sendChat: function() {
        var t = Tabs.Chat;
        var input = document.getElementById('pbChatInput');
        var message = input.value.trim();
        
        if (message === '') return;
        
        // Find the game's chat input and send button
        var gameInput = null;
        var gameSendButton = null;
        
        // First, make sure the correct chat tab is selected in the game
        var gameTabSelector = document.querySelector('#mod_comm_tabs');
        if (gameTabSelector) {
            var tabIndex = (t.currentTab === 'global') ? 0 : 1;
            var tabToClick = gameTabSelector.querySelectorAll('li')[tabIndex];
            if (tabToClick) {
                // Simulate click on the appropriate tab
                tabToClick.click();
                
                // Wait a moment for the tab to switch
                setTimeout(function() {
                    // Now find the input and send button
                    gameInput = document.querySelector('#mod_comm_input textarea');
                    gameSendButton = document.querySelector('#mod_comm_input button');
                    
                    if (gameInput && gameSendButton) {
                        // Set the message in the game's input
                        gameInput.value = message;
                        
                        // Trigger input event to make sure the game recognizes the text
                        var inputEvent = new Event('input', { bubbles: true });
                        gameInput.dispatchEvent(inputEvent);
                        
                        // Click the send button
                        gameSendButton.click();
                        
                        // Clear our input
                        input.value = '';
                        
                        // Update the chat display after a short delay
                        setTimeout(function() {
                            t.updateChatDisplay();
                        }, 500);
                    } else {
                        console.error('Could not find game chat input or send button');
                    }
                }, 200);
            }
        } else {
            // If we can't find the tab selector, try direct approach
            gameInput = document.querySelector('#mod_comm_input textarea');
            gameSendButton = document.querySelector('#mod_comm_input button');
            
            if (gameInput && gameSendButton) {
                // Set the message in the game's input
                gameInput.value = message;
                
                // Trigger input event
                var inputEvent = new Event('input', { bubbles: true });
                gameInput.dispatchEvent(inputEvent);
                
                // Click the send button
                gameSendButton.click();
                
                // Clear our input
                input.value = '';
                
                // Update the chat display after a short delay
                setTimeout(function() {
                    t.updateChatDisplay();
                }, 500);
            } else {
                console.error('Could not find game chat input or send button');
            }
        }
    }
};