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