Greasy Fork

Greasy Fork is available in English.

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.

当前为 2022-07-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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.
// @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
    }
})()