您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
tab
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/538683/1603875/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(); }, 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.cloneGameChat(); }, 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); }, cloneGameChat: function(){ var t = Tabs.Chat; // Clone chat container var gameChatContainer = document.querySelector('#mod_comm_list1'); if (gameChatContainer) { var chatClone = gameChatContainer.cloneNode(true); t.chatDiv.appendChild(chatClone); // Set up a mutation observer to watch for changes in the game's chat 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'); } // Clone chat input var gameChatInput = document.querySelector('#mod_comm_input'); if (gameChatInput) { var inputClone = gameChatInput.cloneNode(true); t.inputDiv.appendChild(inputClone); // Set up event listener for the cloned input 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'); } }, updateChat: function(){ var t = Tabs.Chat; var gameChatContainer = document.querySelector('#mod_comm_list1'); if (gameChatContainer && t.chatDiv) { t.chatDiv.innerHTML = ''; // Clear existing content var chatMessages = gameChatContainer.querySelectorAll('.chat-message'); chatMessages.forEach(function(message) { var newMessage = message.cloneNode(true); t.formatChatMessage(newMessage); t.chatDiv.appendChild(newMessage); }); t.chatDiv.scrollTop = t.chatDiv.scrollHeight; } }, 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.updateChat(); } } else { console.error('Could not find necessary elements to send chat'); } } };