Gats.io - Chat scroller

chat scroller for gats.io

目前為 2021-06-06 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

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

(function() {
    'use strict';

var chatLoop;
var maxLength;
var scrollText = ''
var scrollSpeed = 80

function startChatLoop() {
    let s = scrollText
    let i = 0
    let e = 0
    chatLoop = setInterval(function(){
        i % 12 == 0 ? e = 1 : e = 0
        s.length < 30 ? maxLength = s.length : maxLength = 30
        s = s.substr(1) + s.substr(0, 1);
        RF.list[0].socket.send(`c,${s.substring(e,maxLength)}`)
        i++
    }, scrollSpeed)
}

document.getElementById("chatbox").setAttribute("maxlength", 400)

var div = document.createElement("div"); document.body.appendChild(div);
function createHTML() {
    let html = `
    <style>
        .main {
            pointer-events: none; position: fixed; z-index:999; top: 180px; left: 10px;
            font-family: 'arial';
            color: black;
            font-size: 20px;
        }

    </style>

    <div class="main" id="scrollerGUI">

        <br>nitrogem35's chat scroller</br>
        <br>Text to Scroll: ${scrollText}</br> 
        <br>Save text (from chatbox) [\\]</br>
        <br>Start/Stop Scroll: [']</br>
        <br>Scroll Speed (Higher=slower): ${scrollSpeed} [.] (+) / [,] (-) </br>
        <br>Hide overlay: [;]</br>

    </div>`
    div.innerHTML = html;
}

createHTML()

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

function restartChatLoop() {
    if(chatLoop) {
        clearInterval(chatLoop);
        chatLoop = undefined
    }
    startChatLoop()
}
})();