🥬 disconnect alerts 💸

auto reconnect if you disconnect from the socket, very easy to use

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         🥬 disconnect alerts 💸
// @namespace    http://tampermonkey.net/
// @version      1.0.1.1
// @description  auto reconnect if you disconnect from the socket, very easy to use
// @author       x/y codeing studios, zackiboiz for antiafk script
// @match        https://classic.talkomatic.co/room.html?roomId=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=talkomatic.co
// @grant        none
// @license      MIT
// ==/UserScript==

// We may switch to more autonomous methods in the future, to prevent complex configuration
// Change some of these depending on your WiFi speed if the program doesn't work as intended

var CONFIG = {
    ANTIAFK: true, // Default: true
    RUNTIME: 3000, // Default: 3.0 seconds
    CONNECT: 1500, // Default: 1.5 seconds
    RESTORE: 3000, // Default: 3.0 seconds
    WAITING: 1000, // Default: 1.0 seconds
}

// Helping function.
function uploadMessage (t) {
    if (!chatInput) { return } // Prevent the crash
    chatInput.textContent = t
    updateSentMessage() // Talkomatic function to emit the message
}
// Wait reasonable amount of time to run codes, default: 3 seconds
setTimeout(() => {
    // First we check if socket is already disconnected
    if (!socket.connected) {
        // We already disconnected. What a bummer
        window.location.reload()
    }
    // Then register callback
    socket.on("disconnect", (e) => {
        // Wait for determining if it's a reload, the thread freezes if reloading.
        setTimeout(() => {
            // Persist the last sent message to localStorage
            if (lastSentMessage) {
                localStorage.Message = lastSentMessage
            }
            setTimeout(() => {window.location.reload()}, CONFIG.CONNECT)
        }, CONFIG.WAITING)
    })
}, CONFIG.RUNTIME)

socket.on("connect", (e) => {
    // Oh good. We connection, we send the saved message
    if (localStorage.Message) {
        // If the message doesn't get restored, try increasing CONFIG.RESTORE
        setTimeout(() => {uploadMessage(localStorage.Message); localStorage.Message = ""}, CONFIG.RESTORE)
    }
})

if (CONFIG.ANTIAFK) {
    setInterval(() => {
        // If you emit socket event, server no kick you!
        socket.emit("anti-afk", {
            "sender": (currentUsername + " / " + currentLocation)
        })
    }, 10000)
}