Arras.io Chat

Use Right Shift button to enable/disable chat

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