Player Count Detector

Check the current player count

目前为 2024-12-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Player Count Detector
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-11-22
  5. // @description Check the current player count
  6. // @author Comma
  7. // @match https://diep.io/
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // HOLD Q TO TOGGLE VISIBILITY
  16. // You can change the key toggle here:
  17. var keyy = "q"
  18.  
  19.  
  20.  
  21. var val = "null"
  22. document.addEventListener('keydown', function(event) {
  23. if (event.key.toLowerCase() === keyy.toLowerCase()) {
  24. event.preventDefault();
  25. }
  26. });
  27.  
  28. var count = document.createElement('div');
  29. var countt = document.createElement('div');
  30. var counttt = document.createElement('div');
  31. var display = false;
  32. var intervalId = null;
  33.  
  34. count.textContent = "Region Count:"
  35. count.style.position = "relative";
  36. countt.textContent = "Gamemode Count: ";
  37. countt.style.position = "relative";
  38. counttt.textContent = "Player Counter By Comma";
  39. counttt.style.color = "white";
  40. counttt.style.position = "relative";
  41. counttt.style.zIndex = "9999";
  42. counttt.style.top = "25%";
  43. counttt.style.left = "50%";
  44. counttt.style.transform = "translate(-50%, -50%)";
  45. counttt.style.backgroundColor = "black";
  46. counttt.style.width = "fit-content";
  47. counttt.style.height = "fit-content";
  48. counttt.style.padding = "2vh";
  49. count.style.fontFamily = "arial"
  50. countt.style.fontFamily = "arial"
  51. counttt.style.fontFamily = "arial"
  52. counttt.style.display = "none";
  53. counttt.style.borderRadius = "12px";
  54. counttt.style.boxShadow = '0 0 20px rgba(72, 171, 224, 1), 0 0 40px rgba(72, 171, 224, 0.8)';
  55. counttt.style.transition = 'box-shadow 0.3s ease';
  56. counttt.style.letterSpacing = "1.5px";
  57. document.body.appendChild(counttt);
  58. counttt.appendChild(count);
  59. counttt.appendChild(countt);
  60.  
  61. let isTabHeldDown = false;
  62.  
  63. async function fetchData() {
  64. if (!display) return;
  65. var regionn = window.__common__.active_region;
  66. var gamemode = window.__common__.active_gamemode;
  67. try {
  68. console.log('fetched');
  69. const response = await fetch('https://lb.diep.io/api/lb/pc');
  70. if (!response.ok) {
  71. throw new Error('Network response was not ok');
  72. }
  73. const data = await response.json();
  74. const sydneyRegion = data.regions.find(region => region.region === regionn);
  75. if (!sydneyRegion) {
  76. console.log('Region not found');
  77. return;
  78. }
  79.  
  80. const sydneyPlayers = sydneyRegion.numPlayers;
  81.  
  82. const lobbies = sydneyRegion.lobbies;
  83. const index = lobbies.findIndex(lobby => lobby.gamemode === gamemode);
  84.  
  85. if (index !== -1) {
  86. const sydneyLobby = lobbies[index];
  87. const numPlayers = sydneyLobby.numPlayers;
  88.  
  89. count.textContent = `Region Count: ${sydneyPlayers} ${regionn}`;
  90. countt.textContent = `${gamemode}: ${numPlayers} Players`;
  91. } else {
  92. console.log(`${gamemode} lobby not found.`);
  93. }
  94. } catch (error) {
  95. console.log("Too many fetch requests to api");
  96. }
  97. }
  98. var interval; var timeout;
  99. document.addEventListener('keydown', (event) => {
  100. if ((event.key === keyy.toLowerCase() || event.key === keyy.toUpperCase()) && !isTabHeldDown) {
  101. isTabHeldDown = true;
  102. display = true;
  103. counttt.style.display = "block";
  104. fetchData()
  105. if(val !== null){
  106. var timeout = setTimeout(function() {
  107. interval = setInterval(fetchData, 1000);
  108. }, 1000);
  109. }
  110. }
  111. });
  112. document.addEventListener('keyup', (event) => {
  113. if ((event.key === keyy.toLowerCase() || event.key === keyy.toUpperCase()) && isTabHeldDown) {
  114. isTabHeldDown = false;
  115. display = false;
  116. counttt.style.display = "none";
  117. val = null;
  118. }
  119. });
  120. })();