allie test

tab

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/538683/1603824/allie%20test.js

  1. // Add this to your existing tabs
  2. Tabs.Chat = {
  3. tabOrder: 900,
  4. tabLabel: 'Chat',
  5. tabDisabled: false,
  6. myDiv: null,
  7. timer: null,
  8. chatMessages: [],
  9. lastFetchTime: 0,
  10.  
  11. init: function(div){
  12. var t = Tabs.Chat;
  13. t.myDiv = div;
  14. t.createMainDiv();
  15. t.startFetchingChat();
  16. },
  17.  
  18. createMainDiv: function(){
  19. var t = Tabs.Chat;
  20. var m = '<DIV class=divHeader align=center>'+tx('CHAT')+'</div>';
  21. m += '<div id="ChatContent" style="height:450px; max-height:450px; overflow-y:auto;">';
  22. m += '<table width="100%">';
  23. m += '<tr><td><INPUT id=btChatEnabled type=checkbox '+ (Options.ChatOptions.Enabled?' CHECKED':'') +'> '+tx('Enable Chat')+'</td>';
  24. m += '<td>'+tx('Refresh Interval')+': <INPUT id=btChatInterval type=text size=3 value="'+ Options.ChatOptions.Interval +'"> '+tx('seconds')+'</td></tr>';
  25. m += '</table>';
  26. m += '<div id="ChatMessages"></div>';
  27. m += '</div>';
  28. // Add chat input and send button
  29. m += '<div id="ChatInputArea" style="margin-top:10px;">';
  30. m += '<input type="text" id="ChatInput" style="width:80%;" placeholder="Type your message here...">';
  31. m += '<button id="ChatSendButton" style="width:18%; margin-left:2%;">Send</button>';
  32. m += '</div>';
  33.  
  34. t.myDiv.innerHTML = m;
  35. ById('btChatEnabled').addEventListener('change', function(){
  36. Options.ChatOptions.Enabled = this.checked;
  37. saveOptions();
  38. t.toggleChat();
  39. }, false);
  40. ById('btChatInterval').addEventListener('change', function(){
  41. Options.ChatOptions.Interval = parseInt(this.value);
  42. saveOptions();
  43. t.restartTimer();
  44. }, false);
  45.  
  46. // Add event listener for send button
  47. ById('ChatSendButton').addEventListener('click', t.sendChat, false);
  48. // Add event listener for Enter key in input field
  49. ById('ChatInput').addEventListener('keypress', function(e) {
  50. if (e.key === 'Enter') {
  51. t.sendChat();
  52. }
  53. }, false);
  54.  
  55. t.toggleChat();
  56. },
  57.  
  58. toggleChat: function(){
  59. var t = Tabs.Chat;
  60. if(Options.ChatOptions.Enabled){
  61. t.startFetchingChat();
  62. } else {
  63. t.stopFetchingChat();
  64. }
  65. },
  66.  
  67. startFetchingChat: function(){
  68. var t = Tabs.Chat;
  69. if(t.timer == null){
  70. t.timer = setInterval(t.fetchChat, Options.ChatOptions.Interval * 1000);
  71. t.fetchChat(); // Fetch immediately
  72. }
  73. },
  74.  
  75. stopFetchingChat: function(){
  76. var t = Tabs.Chat;
  77. if(t.timer != null){
  78. clearInterval(t.timer);
  79. t.timer = null;
  80. }
  81. },
  82.  
  83. restartTimer: function(){
  84. var t = Tabs.Chat;
  85. t.stopFetchingChat();
  86. t.startFetchingChat();
  87. },
  88.  
  89. fetchChat: function(){
  90. var t = Tabs.Chat;
  91. var url = 'https://rycamelot.com/fb/e2/src/ajax/getChat.php';
  92. GM_xmlhttpRequest({
  93. method: 'GET',
  94. url: url,
  95. onload: function(response) {
  96. if (response.status === 200) {
  97. t.processChat(response.responseText);
  98. } else {
  99. console.error('Failed to fetch chat:', response.status, response.statusText);
  100. }
  101. },
  102. onerror: function(error) {
  103. console.error('Error fetching chat:', error);
  104. }
  105. });
  106. },
  107.  
  108. processChat: function(responseText){
  109. var t = Tabs.Chat;
  110. var chatData;
  111. try {
  112. chatData = JSON.parse(responseText);
  113. } catch (e) {
  114. console.error('Error parsing chat data:', e);
  115. return;
  116. }
  117.  
  118. // Assuming the chat data is an array of messages
  119. chatData.forEach(function(message) {
  120. if (message.time > t.lastFetchTime) {
  121. t.chatMessages.push(message);
  122. t.lastFetchTime = message.time;
  123. }
  124. });
  125.  
  126. // Keep only the last 100 messages
  127. if (t.chatMessages.length > 100) {
  128. t.chatMessages = t.chatMessages.slice(-100);
  129. }
  130.  
  131. t.displayChat();
  132. },
  133.  
  134. displayChat: function(){
  135. var t = Tabs.Chat;
  136. var chatDiv = ById('ChatMessages');
  137. var html = '';
  138.  
  139. t.chatMessages.forEach(function(message) {
  140. html += '<div class="chatMessage">';
  141. html += '<span class="chatTime">[' + new Date(message.time * 1000).toLocaleTimeString() + ']</span> ';
  142. html += '<span class="chatUser">' + message.user + ':</span> ';
  143. html += '<span class="chatText">' + message.text + '</span>';
  144. html += '</div>';
  145. });
  146.  
  147. chatDiv.innerHTML = html;
  148. t.scrollToBottom();
  149. },
  150.  
  151. scrollToBottom: function() {
  152. var chatDiv = ById('ChatMessages');
  153. chatDiv.scrollTop = chatDiv.scrollHeight;
  154. },
  155.  
  156. sendChat: function() {
  157. var t = Tabs.Chat;
  158. var chatInput = ById('ChatInput');
  159. var message = chatInput.value.trim();
  160. if (message === '') return; // Don't send empty messages
  161. var url = 'https://rycamelot.com/fb/e2/src/ajax/sendChat.php'; // You'll need to confirm the correct URL
  162. GM_xmlhttpRequest({
  163. method: 'POST',
  164. url: url,
  165. data: 'message=' + encodeURIComponent(message),
  166. headers: {
  167. 'Content-Type': 'application/x-www-form-urlencoded'
  168. },
  169. onload: function(response) {
  170. if (response.status === 200) {
  171. // Message sent successfully
  172. chatInput.value = ''; // Clear input field
  173. t.fetchChat(); // Fetch latest messages including the one just sent
  174. } else {
  175. console.error('Failed to send chat:', response.status, response.statusText);
  176. }
  177. },
  178. onerror: function(error) {
  179. console.error('Error sending chat:', error);
  180. }
  181. });
  182. },
  183. };

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址