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