Gats.io - Chat scroller

chat scroller for gats.io with continuous scrolling

  1. // ==UserScript==
  2. // @name Gats.io - Chat scroller
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.3
  5. // @description chat scroller for gats.io with continuous scrolling
  6. // @author nitrogem35
  7. // @match https://gats.io
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let chatLoop;
  15. let maxLength;
  16. let scrollText = '';
  17. let scrollSpeed = 200;
  18. let currentIndex = 0;
  19.  
  20. function startChatLoop() {
  21. chatLoop = true;
  22. loopFunc();
  23. }
  24.  
  25. function loopFunc() {
  26. if (!chatLoop) return;
  27.  
  28. let s = scrollText;
  29. let e = currentIndex % 12 === 0 ? 1 : 0;
  30.  
  31. if (s.length < 28) {
  32. maxLength = s.length;
  33. } else {
  34. maxLength = 28;
  35. }
  36.  
  37. let displayText = s.substring(currentIndex, currentIndex + maxLength);
  38. if (displayText.length < maxLength) {
  39. displayText += s.substring(0, maxLength - displayText.length);
  40. }
  41.  
  42. let z = displayText.split('');
  43. let numRandom = Math.round(Math.random() * 2);
  44.  
  45. for (let j = 0; j < numRandom; j++) {
  46. z.push(" ");
  47. }
  48.  
  49. z = z.join("");
  50. //encode commas (,) as tilde (~) because gats client does that
  51. z = z.replaceAll(",", "~");
  52. Connection.list[0].socket.send(`c,${z}`);
  53.  
  54. currentIndex = (currentIndex + 1) % s.length;
  55.  
  56. setTimeout(loopFunc, scrollSpeed);
  57. }
  58.  
  59. document.getElementById("chatbox").setAttribute("maxlength", 1000);
  60. var div = document.createElement("div");
  61. document.body.appendChild(div);
  62.  
  63. function createHTML() {
  64. let html = `
  65. <style>
  66. .main {
  67. pointer-events: none; position: fixed; z-index:999; top: 150px; left: 10px;
  68. font-family: 'arial';
  69. color: black;
  70. font-size: 20px;
  71. }
  72. </style>
  73. <div class="main" id="scrollerGUI">
  74. <br>nitrogem35's chat scroller (Improved)</br>
  75. <br>Text to Scroll: ${scrollText}</br>
  76. <br>Save text (from chatbox) [\\]</br>
  77. <br>Start/Stop Scroll: [']</br>
  78. <br>Scroll Speed (Higher=slower): ${scrollSpeed}ms [.] (+) / [,] (-) </br>
  79. <br>Hide overlay: [;]</br>
  80. </div>`;
  81. div.innerHTML = html;
  82. }
  83.  
  84. createHTML();
  85.  
  86. document.addEventListener('keydown', function(key) {
  87. if (key.keyCode == 222) {
  88. chatLoop = !chatLoop;
  89. if (chatLoop) startChatLoop();
  90. }
  91. if (key.keyCode == 220) {
  92. scrollText = document.getElementById("chatbox").value + ' ';
  93. createHTML();
  94. }
  95. if (key.keyCode == 190) {
  96. scrollSpeed += 5;
  97. createHTML();
  98. }
  99. if (key.keyCode == 188) {
  100. scrollSpeed = Math.max(0, scrollSpeed - 5);
  101. createHTML();
  102. }
  103. if (key.keyCode == 186) {
  104. div.innerHTML = div.innerHTML ? '' : createHTML();
  105. }
  106. });
  107. })();