Greasy Fork is available in English.
tab
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/538683/1603834/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.hookChat();
},
hookChat: function(){
var t = Tabs.Chat;
// Try to find the game's chat container
var gameChatContainer = document.querySelector('#mod_comm_list1');
if (gameChatContainer) {
// Clone the game's chat container
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');
}
// Try to find the game's chat input
var gameChatInput = document.querySelector('#mod_comm_input');
if (gameChatInput) {
// Clone the game's chat input
var inputClone = gameChatInput.cloneNode(true);
t.inputDiv.appendChild(inputClone);
// Set up event listener for the cloned input
var chatTextArea = t.inputDiv.querySelector('textarea');
if (chatTextArea) {
chatTextArea.addEventListener('keypress', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
t.sendChat(this.value);
this.value = '';
}
});
}
} 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(message){
// Find the game's chat send function
if (typeof uW.Chat === 'object' && typeof uW.Chat.sendMsg === 'function') {
uW.Chat.sendMsg(message);
} else {
console.error('Could not find game chat send function');
}
}
};