Gats.io - Chat scroller

chat scroller for gats.io with continuous scrolling

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Gats.io - Chat scroller
// @namespace    http://tampermonkey.net/
// @version      3.3
// @description  chat scroller for gats.io with continuous scrolling
// @author       nitrogem35
// @match        https://gats.io
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let chatLoop;
    let maxLength;
    let scrollText = '';
    let scrollSpeed = 200;
    let currentIndex = 0;

    function startChatLoop() {
        chatLoop = true;
        loopFunc();
    }

    function loopFunc() {
        if (!chatLoop) return;

        let s = scrollText;
        let e = currentIndex % 12 === 0 ? 1 : 0;

        if (s.length < 28) {
            maxLength = s.length;
        } else {
            maxLength = 28;
        }

        let displayText = s.substring(currentIndex, currentIndex + maxLength);
        if (displayText.length < maxLength) {
            displayText += s.substring(0, maxLength - displayText.length);
        }

        let z = displayText.split('');
        let numRandom = Math.round(Math.random() * 2);

        for (let j = 0; j < numRandom; j++) {
            z.push(" ");
        }

        z = z.join("");
        //encode commas (,) as tilde (~) because gats client does that
        z = z.replaceAll(",", "~");
        Connection.list[0].socket.send(`c,${z}`);

        currentIndex = (currentIndex + 1) % s.length;

        setTimeout(loopFunc, scrollSpeed);
    }

    document.getElementById("chatbox").setAttribute("maxlength", 1000);
    var div = document.createElement("div");
    document.body.appendChild(div);

    function createHTML() {
        let html = `
        <style>
            .main {
                pointer-events: none; position: fixed; z-index:999; top: 150px; left: 10px;
                font-family: 'arial';
                color: black;
                font-size: 20px;
            }
        </style>
        <div class="main" id="scrollerGUI">
            <br>nitrogem35's chat scroller (Improved)</br>
            <br>Text to Scroll: ${scrollText}</br>
            <br>Save text (from chatbox) [\\]</br>
            <br>Start/Stop Scroll: [']</br>
            <br>Scroll Speed (Higher=slower): ${scrollSpeed}ms [.] (+) / [,] (-) </br>
            <br>Hide overlay: [;]</br>
        </div>`;
        div.innerHTML = html;
    }

    createHTML();

    document.addEventListener('keydown', function(key) {
        if (key.keyCode == 222) {
            chatLoop = !chatLoop;
            if (chatLoop) startChatLoop();
        }
        if (key.keyCode == 220) {
            scrollText = document.getElementById("chatbox").value + '   ';
            createHTML();
        }
        if (key.keyCode == 190) {
            scrollSpeed += 5;
            createHTML();
        }
        if (key.keyCode == 188) {
            scrollSpeed = Math.max(0, scrollSpeed - 5);
            createHTML();
        }
        if (key.keyCode == 186) {
            div.innerHTML = div.innerHTML ? '' : createHTML();
        }
    });
})();