Survev.io Counters

Give survev.io better experience

2025-09-13 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

// ==UserScript==
// @name         Survev.io Counters
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      1.0.0
// @description  Give survev.io better experience
// @author       asultra and wzld
// @match        https://survev.io/
// @icon         https://cdn.discordapp.com/icons/947128006030282792/c80363d8d6dea22ef392c4d325e0c9f4.png?size=64
// @grant        GM_addStyle
// ==/UserScript==

/* #FPS Booster (if u want to use this, u have to delete #Uncap FPS!)
(function() {
    'use strict';
    let MAX = 540; //frame rate you desire
    requestAnimationFrame = e => setTimeout(e, 1e3 / MAX);
})();*/

/*#Uncap_FPS*/
(function() {
    'use strict';

    function uncapFPS() {
        window.requestAnimationFrame = function(callback) {
            return setTimeout(callback, 1);
        };
    }
    uncapFPS();
})();

/*CSS*/
(function() {
    'use strict';
    GM_addStyle(`
        #ui-game {
            opacity: 1;
        }
    `);
})();

/*#FPS_Counter*/
(function() {
    // Create FPS display
    const fpsDisplay = document.createElement('div');
    fpsDisplay.style.position = 'absolute';
    fpsDisplay.style.top = '60%'; // Middle of the screen vertically
    fpsDisplay.style.left = '10px'; // Left side of the screen
    fpsDisplay.style.transform = 'translateY(-50%)'; // Centers it vertically based on the top position
    fpsDisplay.style.color = 'white';
    fpsDisplay.style.fontSize = '14px'; // Smaller font size
    fpsDisplay.style.fontFamily = '"roboto condensed", sans-serif'; // Regular Arial font without bold
    fpsDisplay.style.fontWeight = 'bold';
    fpsDisplay.style.textShadow = '1px 1px 2px black'; // Slight shadow for visibility
    fpsDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.3)';
    fpsDisplay.style.padding = '3px 5px'; // Padding around the text
    fpsDisplay.style.borderRadius = '5px'; // Slightly rounded corners for styling
    fpsDisplay.style.zIndex = '10000'; // Ensure the FPS display is on top
    fpsDisplay.innerHTML = `0 FPS`;
    document.body.appendChild(fpsDisplay);
    // Update FPS
    let times = [];
    const getFPS = () => {
        window.requestAnimationFrame(() => {
            const now = performance.now();

            while (times.length > 0 && times[0] <= now - 1000) times.shift();
            times.push(now);
            fpsDisplay.innerHTML = `${times.length} FPS`;
            if (times.length <= 50) {
                fpsDisplay.style.color = "red";
            } else {
                fpsDisplay.style.color = "white";
            }
            getFPS();
        });
    }
    getFPS();
})();

/*#LAT_Counter*/
(function() {
    const pingDisplay = document.createElement('div');
    pingDisplay.style.position = 'absolute';
    pingDisplay.style.top = 'calc(60% + 25px)'; // Positioned below FPS counter
    pingDisplay.style.left = '10px'; // Align with FPS counter
    pingDisplay.style.transform = 'translateY(-50%)'; // Centers it vertically based on the top position
    pingDisplay.style.color = 'white'; // Yellow color for ping counter
    pingDisplay.style.fontSize = '14px'; // Same font size as FPS counter
    pingDisplay.style.fontFamily = '"roboto condensed", sans-serif'; // Regular Arial font
    pingDisplay.style.fontWeight = 'bold';
    pingDisplay.style.textShadow = '1px 1px 2px black'; // Slight shadow for visibility
    pingDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.3)';
    pingDisplay.style.padding = '3px 5px'; // Padding around the text
    pingDisplay.style.borderRadius = '5px'; // Slightly rounded corners for styling
    pingDisplay.style.zIndex = '10000'; // Ensure the Ping display is on top
    pingDisplay.innerHTML = `Waiting for a game start...`; // Use backticks for string interpolation
    document.body.appendChild(pingDisplay);

    var sendTime, receiveTime, timeout, region, DOM_observer, ws;
    var teamJoined = document.getElementById("msg-wait-reason"),
        endBtn = document.getElementById("ui-stats-options");

    window.onload = () => {
        var strtBtn = document.getElementsByClassName("btn-green btn-darken menu-option");
        var strtBtnArray = [strtBtn[0], strtBtn[1], strtBtn[2]];
        strtBtnArray.forEach((btn) => {
            btn.onclick = () => {
                region = document.getElementById("server-select-main").value;
                getPing();
            };
        });
        strtBtn[3].onclick = () => {
            region = document.getElementById("team-server-select").value;
            getPing();
        };
    };

    document.getElementById("btn-game-quit").onclick = () => {
        ws.close()
    };
    document.getElementById("btn-spectate-quit").onclick = () => {
        ws.close()
    };
    DOM_observer = new MutationObserver((mutations) => {
        if (mutations[0].addedNodes.length === 1) {
            endBtn.getElementsByTagName("a")[0].onclick = () => {
                ws.close()
            };
        } else if (mutations[0].addedNodes.length === 3) {
            region = document.getElementById("team-server-select").value;
            delayConnect();
        };
    });
    DOM_observer.observe(endBtn, {
        childList: true
    });
    DOM_observer.observe(teamJoined, {
        childList: true
    });

    function wsUrl() {
        var wsUrl, wsRegion;
        if (region === 'na') {
            wsRegion = 'usr';
        } else if (region === 'eu') {
            wsRegion = 'eur';
        } else if (region === 'asia') {
            wsRegion = 'asr';
        } else if (region === 'sa') {
            wsRegion = 'sa';
        } else if (region === 'ru') {
            wsRegion = 'russia';
        };
        wsUrl = `wss://${wsRegion}.mathsiscoolfun.com:8001/ptc`;
        return wsUrl;
    };

    function delayConnect() {
        timeout = setTimeout(getPing, 2500);
    };

    function doSend(message) {
        if (ws.readyState === 1) {
            sendTime = Date.now();
            ws.send(message);
        };
    };

    function getPing() {
        var ping, url = wsUrl();
        ws = new WebSocket(url);

        ws.onopen = () => {
            clearTimeout(timeout);
            doSend(new ArrayBuffer(1));
        };

        ws.onclose = (evt) => {
            if (evt.code === 1005) {
                pingDisplay.innerHTML = `Waiting for a game start...`;
                pingDisplay.style.color = "white";
            } else if (evt.code === 1006) {
                ws = null;
                delayConnect();
            };
        };

        ws.onmessage = () => {
        	receiveTime = Date.now();
        	ping = receiveTime - sendTime;
            if (ping >= 120) {
                pingDisplay.style.color = "red";
            } else if (ping >= 90 && ping < 120) {
                pingDisplay.style.color = "orange";
            } else if (ping >= 60 && ping < 90) {
                pingDisplay.style.color = "yellow";
            } else {
                pingDisplay.style.color = "white";
            }
        	pingDisplay.innerHTML = `${ping} ms`;
        	setTimeout(() => {
        		doSend(new ArrayBuffer(1))
        	}, 1000);
        };

        ws.onerror = () => {
            pingDisplay.innerHTML = `NaN`;
            pingDisplay.style.color = "gray";
        };
    };
})();

/*#HP&AD_Counter*/
! function() {
    "use strict";
    var e = 0,
        t = document.createElement("span");
    t.style = "display:block;position:fixed;z-index: 2;margin:6px 0 0 0;right: 15px;mix-blend-mode: difference;font-weight: bold;font-size:large;";
    document.querySelector("#ui-health-container").appendChild(t);
    var n = document.createElement("span");
    n.style = "display:block;position:fixed;z-index: 2;margin:6px 0 0 0;left: 15px;mix-blend-mode: difference;font-weight: bold;font-size: large;";
    document.querySelector("#ui-health-container").appendChild(n);
    setInterval((function() {
        var i = document.getElementById("ui-health-actual").style.width.slice(0, -1);
        e !== i && (e = i, t.innerHTML = Number.parseFloat(i).toFixed(1));
        var o = 25 * document.getElementById("ui-boost-counter-0").querySelector(".ui-bar-inner").style.width.slice(0, -1) / 100 + 25 * document.getElementById("ui-boost-counter-1").querySelector(".ui-bar-inner").style.width.slice(0, -1) / 100 + 37.5 * document.getElementById("ui-boost-counter-2").querySelector(".ui-bar-inner").style.width.slice(0, -1) / 100 + 12.5 * document.getElementById("ui-boost-counter-3").querySelector(".ui-bar-inner").style.width.slice(0, -1) / 100;
        n.innerHTML = Math.round(o)
    }))
}();

/*Make things easy xlibizitoynetly*/
function delAds(e) {
    document.getElementById(e) && document.getElementById(e).remove()
}
setInterval(function() {
    var adsA = document.getElementsByClassName("ad-block-leaderboard-bottom")[0];
    delAds("leaderboard-front");
    delAds("adunit");
    delAds("ui-stats-ad-container-desktop");
    adsA && adsA.remove();
}, 1000);

/*
#Credits
- Asphixia: LAT counter
- Asultra: FPS counter based on NARS code
- SamerKizi: Creator of HP&AD counter
- Blubbled: Creator of Uncap FPS - https://greasyfork.org/en/scripts/493862-uncap-fps-for-suroi
*/