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.0
  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. chatLoop = setInterval(function(){
  22. (s.length < 30) ? (maxLength = s.length) : (maxLength = 30)
  23. s = s.substr(1) + s.substr(0, 1);
  24. RF.list[0].socket.send(`c,${s.substring(Math.round(Math.random()),maxLength)}`)
  25. }, scrollSpeed)
  26. }
  27.  
  28. document.getElementById("chatbox").setAttribute("maxlength", 120)
  29.  
  30. var div = document.createElement("div"); document.body.appendChild(div);
  31. function createHTML() {
  32. let html = `
  33. <style>
  34. .main {
  35. pointer-events: none; position: fixed; z-index:999; top: 180px; left: 10px;
  36. font-family: 'arial';
  37. color: black;
  38. font-size: 20px;
  39. }
  40.  
  41. </style>
  42.  
  43. <div class="main" id="scrollerGUI">
  44.  
  45. <br>nitrogem35's chat scroller</br>
  46. <br>Text to Scroll: ${scrollText}</br>
  47. <br>Save text (from chatbox) [\\]</br>
  48. <br>Start/Stop Scroll: [']</br>
  49. <br>Scroll Speed (Higher=slower): ${scrollSpeed} [,] (+) / [.] (-) </br>
  50. <br>Hide overlay: [;]</br>
  51.  
  52. </div>`
  53. div.innerHTML = html;
  54. }
  55.  
  56. createHTML()
  57.  
  58. document.addEventListener('keydown', function(key) {
  59. if(key.keyCode == 222) {
  60. if(chatLoop) {
  61. clearInterval(chatLoop);
  62. chatLoop = undefined
  63. }
  64. else {
  65. startChatLoop();
  66. }
  67. };
  68. if(key.keyCode == 220) {
  69. scrollText = document.getElementById("chatbox").value
  70. scrollText += ' '
  71. createHTML()
  72. }
  73. if(key.keyCode == 190) {
  74. (scrollSpeed > 0) ? (scrollSpeed -= 5) : (null)
  75. createHTML()
  76. restartChatLoop()
  77. }
  78. if(key.keyCode == 188) {
  79. scrollSpeed += 5
  80. createHTML()
  81. restartChatLoop()
  82. }
  83. if(key.keyCode == 186) {
  84. if(div.innerHTML != '') div.innerHTML = ''
  85. else createHTML()
  86. }
  87. })
  88.  
  89. function restartChatLoop() {
  90. if(chatLoop) {
  91. clearInterval(chatLoop);
  92. chatLoop = undefined
  93. }
  94. startChatLoop()
  95. }
  96. })();