🥬 disconnect alerts 💸

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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