Arras.io Chat

Use Right Shift button to enable/disable chat

目前为 2023-01-09 提交的版本。查看 最新版本

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