Greasy Fork 还支持 简体中文。

Arras.io Chat

Use Right Shift button to enable/disable chat

目前為 2023-01-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Arras.io Chat
  3. // @match *://arras.io/*
  4. // @match *://arras.netlify.app/*
  5. // @match *://arrax.io/*
  6. // @match *://arras.cx/*
  7. // @author Inellok
  8. // @description Use Right Shift button to enable/disable chat
  9. // @namespace Inellok Labs.
  10. // @version 1.7
  11. // @run-at document-end
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15.  
  16. function getServerFromLoc()
  17. {
  18. let rlockhash = "";
  19. let started = false;
  20. for (let i = 0; i < location.hash.length; i++) {
  21. if (location.hash[i] === '#') {
  22. started = true;
  23. continue
  24. }
  25. if (started) {
  26. rlockhash += location.hash[i];
  27. }
  28. }
  29. return rlockhash;
  30. }
  31.  
  32.  
  33. function getName()
  34. {
  35. let rname = "unnamed";
  36. let item = window.localStorage.getItem("arras.io");
  37.  
  38. if (item != null) {
  39. rname = JSON.parse(window.localStorage.getItem("arras.io")).name;
  40. }
  41. return rname;
  42. }
  43.  
  44.  
  45. function sendEverything() {
  46. let xhr = new XMLHttpRequest();
  47. xhr.open("POST", "https://arrasio-chat.glitch.me/");
  48.  
  49. //We need this to send http requests from arras.io page to the server with other URL
  50. xhr.setRequestHeader("Accept", "plain/text");
  51. xhr.setRequestHeader("Content-Type", "plain/text");
  52. //------
  53.  
  54. //when we got server's response
  55. xhr.onreadystatechange = function() {
  56. let srv = getServerFromLoc();
  57. if (xhr.readyState === 4) {
  58. chat_container.innerText = "";
  59. let msgs = JSON.parse(xhr.responseText);
  60. for (let i = 0; i < msgs.length; ++i) {
  61. if (srv === msgs[i].srv) {
  62. let msg = msgs[i].nick + ": " + msgs[i].message;
  63. chat_container.innerText += (msg + '\n');
  64. }
  65. }
  66. }
  67. };
  68.  
  69. xhr.send(JSON.stringify({
  70. srv: getServerFromLoc(),
  71. nick: getName(),
  72. message: msg_container.value
  73. }));
  74. }
  75.  
  76. //We need this to draw chat over arras drawing canvas
  77. let canvas = document.getElementById("canvas");
  78. canvas.style.zIndex = 1;
  79. canvas.style.position = "absolute";
  80.  
  81.  
  82. let lockhash = "";
  83.  
  84.  
  85. let info_container = document.createElement("div");
  86. info_container.innerText = "Arras.io Chat (by Inellok)";
  87. info_container.style.marginLeft = "40%";
  88. info_container.style.color = "white";
  89. info_container.style.opacity = "1";
  90.  
  91.  
  92. let chat_container = document.createElement("div");
  93. chat_container.style.marginLeft = "2%";
  94. chat_container.style.color = "red";
  95. chat_container.style.opacity = "1";
  96. chat_container.style.height = "88%";
  97. chat_container.fontSize = "100%";
  98.  
  99. let msg_container = document.createElement("input");
  100.  
  101. msg_container.placeholder = "message";
  102. msg_container.style.marginLeft = "2%";
  103. msg_container.style.color = "black";
  104. msg_container.style.opacity = "1";
  105. msg_container.style.height = "5%";
  106. msg_container.style.width = "65%";
  107. msg_container.style.fontSize = "110%";
  108.  
  109.  
  110. let send_container = document.createElement("button");
  111.  
  112. send_container.innerText = "SEND / UPDATE";
  113. send_container.style.marginLeft = "2%";
  114. send_container.style.color = "black";
  115. send_container.style.opacity = "1";
  116. send_container.style.height = "5%";
  117. send_container.style.width = "21%";
  118. send_container.style.fontSize = "60%";
  119.  
  120. send_container.onclick = function() {
  121. sendEverything();
  122.  
  123. return false;
  124. }
  125.  
  126. let mainContainer = document.createElement("div");
  127. mainContainer.style = `
  128. width:50%;
  129. height:85%;
  130. background:#000000;
  131. opacity: 90%;
  132. margin: auto;
  133. font-size: 150%;
  134. visibility:hidden;
  135. z-index:2;
  136. position:absolute;
  137. margin-left: 20%`;
  138.  
  139. msg_container.addEventListener("keydown", (e) => {
  140. //We need this to not move our character while writing message
  141. e.stopPropagation();
  142. if (e.code === "Enter" && document.activeElement === msg_container) {
  143. sendEverything();
  144. msg_container.value = "";
  145. }
  146.  
  147. if (e.code === "ShiftRight") {
  148. if (mainContainer.style.visibility === "hidden") {
  149. mainContainer.style.visibility = "visible";
  150. } else {
  151. mainContainer.style.visibility = "hidden";
  152. }
  153. }
  154. });
  155.  
  156. window.addEventListener("keydown", (e) => {
  157. //show/hide our chat when press right shift
  158. if (e.code === "ShiftRight") {
  159. if (mainContainer.style.visibility === "hidden") {
  160. mainContainer.style.visibility = "visible";
  161. } else {
  162. mainContainer.style.visibility = "hidden";
  163. }
  164. }
  165.  
  166.  
  167. });
  168.  
  169. mainContainer.appendChild(info_container);
  170. mainContainer.appendChild(chat_container);
  171. mainContainer.appendChild(msg_container);
  172. mainContainer.appendChild(send_container);
  173. document.body.appendChild(mainContainer);