Gats.io - Chat scroller

chat scroller for gats.io

当前为 2021-06-06 提交的版本,查看 最新版本

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