Player Count Detector Diep.io

Check the current player count

当前为 2024-12-13 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Player Count Detector Diep.io
// @namespace    http://tampermonkey.net/
// @version      2024-11-22
// @description  Check the current player count
// @author       Comma
// @match        https://diep.io/*
// @grant        none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

// HOLD Q TO TOGGLE VISIBILITY
// You can change the key toggle here:
          var keyy = "q"



        var val = "null"
document.addEventListener('keydown', function(event) {
    if (event.key.toLowerCase() === keyy.toLowerCase()) {
        event.preventDefault();
    }
});

    var count = document.createElement('div');
    var countt = document.createElement('div');
    var counttt = document.createElement('div');
    var display = false;
    var intervalId = null;

    count.textContent = "Region Count:"
    count.style.position = "relative";
    countt.textContent = "Gamemode Count: ";
    countt.style.position = "relative";
    counttt.textContent = "Player Counter By Comma";
    counttt.style.color = "white";
    counttt.style.position = "relative";
    counttt.style.zIndex = "9999";
    counttt.style.top = "25%";
    counttt.style.left = "50%";
    counttt.style.transform = "translate(-50%, -50%)";
    counttt.style.backgroundColor = "black";
    counttt.style.width = "fit-content";
    counttt.style.height = "fit-content";
    counttt.style.padding = "2vh";
    count.style.fontFamily = "arial"
    countt.style.fontFamily = "arial"
    counttt.style.fontFamily = "arial"
    counttt.style.display = "none";
    counttt.style.borderRadius = "12px";
    counttt.style.boxShadow = '0 0 20px rgba(72, 171, 224, 1), 0 0 40px rgba(72, 171, 224, 0.8)';
    counttt.style.transition = 'box-shadow 0.3s ease';
    counttt.style.letterSpacing = "1.5px";
    document.body.appendChild(counttt);
    counttt.appendChild(count);
    counttt.appendChild(countt);

    let isTabHeldDown = false;

        async function fetchData() {
    if (!display) return;
        var regionn = window.__common__.active_region;
        var gamemode = window.__common__.active_gamemode;
    try {
        console.log('fetched');
        const response = await fetch('https://lb.diep.io/api/lb/pc');
        if (!response.ok) {
            throw new Error('Network response was not ok');
        }
        const data = await response.json();
        const sydneyRegion = data.regions.find(region => region.region === regionn);
        if (!sydneyRegion) {
            console.log('Region not found');
            return;
        }

        const sydneyPlayers = sydneyRegion.numPlayers;

        const lobbies = sydneyRegion.lobbies;
        const index = lobbies.findIndex(lobby => lobby.gamemode === gamemode);

        if (index !== -1) {
            const sydneyLobby = lobbies[index];
            const numPlayers = sydneyLobby.numPlayers;

            count.textContent = `Region Count: ${sydneyPlayers} ${regionn}`;
            countt.textContent = `${gamemode}: ${numPlayers} Players`;
        } else {
            console.log(`${gamemode} lobby not found.`);
        }
    } catch (error) {
        console.log("Too many fetch requests to api");
    }
}
    var interval; var timeout;
        document.addEventListener('keydown', (event) => {
        if ((event.key === keyy.toLowerCase() || event.key === keyy.toUpperCase()) && !isTabHeldDown) {
            isTabHeldDown = true;
            display = true;
            counttt.style.display = "block";
           fetchData()
            if(val !== null){
          var timeout = setTimeout(function() {
          interval = setInterval(fetchData, 1000);
           }, 1000);
            }
        }
    });
    document.addEventListener('keyup', (event) => {
        if ((event.key === keyy.toLowerCase() || event.key === keyy.toUpperCase()) && isTabHeldDown) {
            isTabHeldDown = false;
            display = false;
            counttt.style.display = "none";
            val = null;
        }
    });
})();