Greasy Fork is available in English.

Scenexe2 Utils

scenexe2 utilities.

// ==UserScript==
// @name         Scenexe2 Utils
// @namespace    http://tampermonkey.net/
// @version      1
// @description  scenexe2 utilities.
// @author       phosphorus2
// @match        https://scenexe2.io/*
// @grant        none
// @license All Rights Reserved. This code is for personal, non-commercial use only. Modifications, redistributions, or unauthorized use are prohibited without explicit permission.
// ==/UserScript==
(async () => {
    const api = async (type) => {
        const url = `https://expandedwater.online:3000/api/messages/${type}`;
        try {
            const response = await fetch(url);
            const message = await response.json();
            return message;
        } catch (e) {
            console.warn("Error fetching API:", e);
        }
    };

    const menu = document.createElement("div");
    menu.style.position = "absolute";
    menu.style.top = "10%";
    menu.style.left = "10%";
    menu.style.width = "300px";
    menu.style.padding = "10px";
    menu.style.border = "3px solid black";
    menu.style.borderRadius = "5px";
    menu.style.backgroundColor = "rgba(0, 0, 0, 0.6)";
    menu.style.fontFamily = "'Ubuntu', sans-serif";
    menu.style.color = "white";
    menu.style.fontWeight = "bold";
    menu.style.textShadow =
        "2px 2px 0px black, " +
        "-2px -2px 0px black, " +
        "2px -2px 0px black, " +
        "-2px 2px 0px black";
    menu.style.transition = "opacity 0.5s ease";
    menu.style.opacity = "1";
    menu.style.cursor = "grab";
    menu.id = "menu";
    document.body.appendChild(menu);

    let isDragging = false;
    let offsetX = 0;
    let offsetY = 0;

    menu.addEventListener("mousedown", (e) => {
        isDragging = true;
        offsetX = e.clientX - menu.offsetLeft;
        offsetY = e.clientY - menu.offsetTop;
        menu.style.cursor = "grabbing";
    });

    document.addEventListener("mousemove", (e) => {
        if (isDragging) {
            menu.style.left = `${e.clientX - offsetX}px`;
            menu.style.top = `${e.clientY - offsetY}px`;
        }
    });

    document.addEventListener("mouseup", () => {
        isDragging = false;
        menu.style.cursor = "grab";
    });

    const drawText = (t, i) => {
        let e = document.getElementById(i);
        if (!e) {
            e = document.createElement("div");
            e.id = i;
            e.style.marginBottom = "7.5px";
            menu.appendChild(e);
        }
        e.textContent = t;
    };

    const drawButton = (text, id, onClick) => {
        let button = document.getElementById(id);
        if (!button) {
            button = document.createElement("button");
            button.id = id;
    
            button.style.position = "relative";
            button.style.margin = "5px 0";
            button.style.padding = "5px 10px";
            button.style.border = "2px solid black";
            button.style.borderRadius = "5px";
            button.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
            button.style.fontFamily = "'Ubuntu', sans-serif";
            button.style.color = "white";
            button.style.fontWeight = "bold";
            button.style.textShadow =
                "2px 2px 0px black, " +
                "-2px -2px 0px black, " +
                "2px -2px 0px black, " +
                "-2px 2px 0px black";
            button.style.cursor = "pointer";
    
            menu.appendChild(button);
        }
        button.textContent = text;
    
        button.onclick = onClick;
    };

    const convert = (n) => {
        let a = Math.floor(n / 1000);
        let b = Math.floor(a / 60);
        let c = a % 60;
        return `${b}m ${c}s`;
    };

    const extract = (c) => {
        const m = c.match(/\]\sSpawned\sa\s(.+?)!/);
        return m ? m[1] : null;
    };

    const scenexe = {
                abyss: async () => {
            try {
                const latest = (await api("1221635977987100874"))?.[0];
                if (!latest || latest === updated.abyss) return;
        
                updated.abyss = latest;
        
                const directionsMatch = latest.content.match(/(top|bottom|left|right)/gi);
                const timeMatch = latest.content.match(/(\d+(\.\d+)?)\sminutes/);
        
                if (directionsMatch && timeMatch) {
                    const directions = directionsMatch.slice(0, 2).map(dir => dir.toLowerCase());
                    const minutes = parseFloat(timeMatch[1]);
                    const openingTime = latest.timestamp + minutes * 60 * 1000;
        
                    const update = () => {
                        const remainingTime = openingTime - Date.now();
                        if (remainingTime > 0) {
                            const readableTime = convert(remainingTime);
                            drawText(
                                `Abyssal Gate opens in ${readableTime} (${directions.join(' ')})`,
                                "abyss-timer"
                            );
                        } else {
                            drawText(`Abyssal Gate has already opened (${directions.join(' ')})`, "abyss-timer");
                            clearInterval(interval);
                        }
                    };
        
                    update();
                    const interval = setInterval(update, 1000);
                }
            } catch (e) {
                console.error("Error in abyss function:", e);
            }
        },
        spawns: async () => {
            const messages = await api("1187917859742027786");
            const latest = messages[0];
    
            if (latest) {
                const elapsed = Date.now() - latest.timestamp;
    
                drawText(`${extract(latest.content)} (${convert(elapsed)} ago)`, "shape");
            }
        },
        reconnect: (() => {
            q = true;
            drawButton("Reconnect", "reconnect-button", () => {
                window.g();
            });
        }),
        loop: async () => {
            for (const key of Object.keys(scenexe)) {
                if (key !== "loop" && typeof scenexe[key] === "function") {
                    await scenexe[key]();
                }
            }
        }
    };    

    let menuVisible = true;

    document.addEventListener("keydown", (e) => {
        if (e.code === "ShiftRight") {
            menuVisible = !menuVisible;
            if (menuVisible) {
                menu.style.opacity = "0";
                setTimeout(() => {
                    if (!menuVisible) menu.style.display = "none";
                }, 500);
            } else {
                menu.style.display = "block";
                setTimeout(() => {
                    menu.style.opacity = "1";
                }, 0);
            };
        }
    });

    setInterval(async () => {
        await scenexe.loop();
    }, 1000);
})();