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