🥬 disconnect alerts 💸

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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