Chatttt

xhat

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/536283/1590706/Chatttt.js

  1. // crossDomainChat.js (New Tab for Cross-Domain Chat)
  2.  
  3. Tabs.CrossDomainChat = {
  4. tabOrder: 2140, // Adjust order as needed
  5. tabLabel: "Cross-Domain Chat",
  6. tabColor: "orange",
  7. myDiv: null,
  8. chatHistory: [], // Store chat history
  9. maxHistory: 200, // Maximum number of messages to store
  10. domains: [], // List of domains to chat with
  11.  
  12. init(div) {
  13. this.myDiv = div;
  14. this.paint();
  15. },
  16.  
  17. paint() {
  18. const m = `
  19. <div class="divHeader" align="center">Cross-Domain Chat</div>
  20. <br>
  21. <div align="center">
  22. <label for="chatDomains">Domains (comma-separated):</label>
  23. <input type="text" id="chatDomains" class="btInput" value="${this.domains.join(', ')}">
  24. <br><br>
  25. <textarea id="chatInput" rows="3" cols="50" class="btInput" placeholder="Enter message..."></textarea>
  26. <br>
  27. <button id="sendButton" class="buttonv2 std blue">Send</button>
  28. <br><br>
  29. <div id="chatDisplay" style="height: 400px; overflow-y: scroll;"></div>
  30. </div>
  31. `;
  32.  
  33. this.myDiv.innerHTML = m;
  34.  
  35. // Event listeners
  36. $("#sendButton").click(() => this.sendMessage());
  37. $("#chatDomains").change(() => this.updateDomains());
  38. },
  39.  
  40. updateDomains() {
  41. const domainsInput = $("#chatDomains").val();
  42. this.domains = domainsInput.split(',').map(d => d.trim()).filter(d => d !== ""); // Clean up domains
  43. this.saveDomains(); // Save domains to storage (using GM_setValue or similar)
  44. },
  45.  
  46. sendMessage() {
  47. const message = $("#chatInput").val().trim();
  48. if (message === "" || this.domains.length === 0) {
  49. return;
  50. }
  51.  
  52. // Add message to chat history
  53. this.addMessage(Seed.player.name, message, getServerId()); // Add sender's domain
  54. this.displayChat();
  55.  
  56. // Send message to other domains (implementation omitted)
  57. // This would involve sending cross-domain messages or using a shared server.
  58. // You'll need to devise a secure and reliable communication method.
  59.  
  60. $("#chatInput").val(""); // Clear input field
  61. },
  62.  
  63.  
  64. addMessage(sender, message, domain) {
  65. this.chatHistory.push({ sender, message, timestamp: Date.now(), domain });
  66. if (this.chatHistory.length > this.maxHistory) {
  67. this.chatHistory.shift(); // Remove oldest message
  68. }
  69. this.saveChatHistory(); // Save chat history to storage
  70. },
  71.  
  72. displayChat() {
  73. const chatDisplay = $("#chatDisplay");
  74. chatDisplay.empty(); // Clear previous messages
  75.  
  76. this.chatHistory.forEach(msg => {
  77. const messageElement = $("<div></div>");
  78. messageElement.html(`[${new Date(msg.timestamp).toLocaleTimeString()}] [${msg.domain}] ${msg.sender}: ${msg.message}`);
  79. chatDisplay.append(messageElement);
  80. });
  81.  
  82. // Scroll to bottom
  83. chatDisplay.scrollTop(chatDisplay[0].scrollHeight);
  84. },
  85.  
  86. // ... (Implement saveDomains and saveChatHistory using GM_setValue or similar) ...
  87.  
  88. show() {
  89. this.loadDomains(); // Load saved domains
  90. this.loadChatHistory(); // Load saved chat history
  91. this.displayChat();
  92. },
  93.  
  94. hide() {
  95. // ... (Any logic to run when the tab is hidden) ...
  96. }
  97. };