Greasy Fork is available in English.
tab
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/538683/1603863/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();
},
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();
},
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 = gameChatContainer.innerHTML;
t.chatDiv.scrollTop = t.chatDiv.scrollHeight;
}
},
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');
}
}
};