Global Chat

You can chat with other players from all servers! When you write something in the chat sploop.io then it is shown in the global chat. (This script does not allow you to communicate with everyone, but allows you to communicate with all users of this script)

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Global Chat
// @namespace    -
// @version      0.1
// @description  You can chat with other players from all servers! When you write something in the chat sploop.io then it is shown in the global chat. (This script does not allow you to communicate with everyone, but allows you to communicate with all users of this script)
// @author       Nudo
// @match        *://sploop.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sploop.io
// @grant        none
// ==/UserScript==

(function() {
    const SERVER = "globalchatserver.stopitplz.repl.co"
    const WSSERVER = `ws${location.protocol.slice(4, 5) || ""}://${SERVER}`

    let socket = null

    function sendMessage(data) {
        if (!socket) {
            return void 0
        }

        if (socket.readyState !== 1) {
            return void 0
        }

        socket.send(JSON.stringify([localStorage.nickname || "noname", data]))
    }

    function serverSetup() {
        socket = new WebSocket(WSSERVER)
        socket.binaryType = "arraybuffer"

        socket.onopen = () => {
            sendMessage("connected")
        }

        socket.onmessage = (message) => {
            const data = JSON.parse(message.data)

            onMessage(data)
        }
    }

    function onMessage(data) {
        Menu.addMessage(data[0], data[1], data[2])
    }

    window.addEventListener("load", () => serverSetup())

    const Menu = {}

    Menu.html = `
    <div class="global-chat-holder">
      <container class="chat-wrapper"></container>
    </div>

    <style>
    .chat-wrapper main {
      color: #fff;
      margin: 3px;
      font-size: 14px;
    }

    .chat-wrapper {
      display: flex;
      flex-direction: column;
      overflow: hidden;
      max-height: 400px;
    }

    .chat-wrapper::-webkit-scrollbar {
      width: 0;
    }

    .global-chat-holder {
      position: absolute;
      top: 5px;
      left: 5px;
      pointer-events: none;
      z-index: 999999;
    }
    </style>
    `

    Menu.addMessage = function(nickname, message, color) {
        if (!message.length) {
            return void 0
        }

        const wrapper = document.querySelector(".chat-wrapper")

        message = antiSpam(message)

        wrapper.innerHTML += `
        <main class="text-shadowed-3" style="color: ${color || "#fff"}">
        ${nickname}: ${message}
        </main>
        `

        wrapper.scrollTo(0, wrapper.scrollHeight)
    }

    const canvas = document.getElementById("game-canvas")

    canvas.insertAdjacentHTML("beforebegin", Menu.html)

    window.addEventListener("keydown", (event) => {
        if (event.code === "Enter") {
            const chatValue = document.getElementById("chat").value

            sendMessage(chatValue)
        }
    })

    function antiSpamLetters(message) {
        let letterCounter = {}

        for (let i = 0; i < message.length; i++) {
            if (!message[i - 1]) {
                continue
            }

            if (letterCounter[message[i]] == null) {
                letterCounter[message[i]] = 0
            }

            if (message[i].toLowerCase() === message[i - 1].toLowerCase()) {
                letterCounter[message[i]] += 1
            }
        }

        for (const letter in letterCounter) {
            if (letterCounter[letter] >= 5) {
                message = "spam"
            }
        }

        return message
    }

    function antiSpamSymbols(message) {
        let symbolCounter = {}

        const symbols = ["@", "!", "#", "$", "%", "&"]

        for (const symbol of symbols) {
            if (message.match(symbol)) {
                for (const letter of message) {
                    if (symbolCounter[letter] == null) {
                        symbolCounter[letter] = 0
                    }

                    if (letter === symbol) {
                        symbolCounter[letter] += 1
                    }
                }
            }
        }

        for (const symbol in symbolCounter) {
            if (symbolCounter[symbol] >= 5) {
                message = "spam"
            }
        }

        return message
    }

    function antiSpam(message) {
        message = antiSpamLetters(message)
        message = antiSpamSymbols(message)

        return message
    }
})()