Roblox Server Finder

Finds an empty server for you to join.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Roblox Server Finder
// @version      1.5
// @description  Finds an empty server for you to join.
// @match        https://www.roblox.com/games/*
// @author       Roblox_Scripter_Tools
// @grant        none
// @namespace https://greasyfork.org/users/902751
// ==/UserScript==

(function () {
  // Gets the game ID
  const gid = Number(window.location.pathname.split("/")[2]);
  if (!gid) return;
  // Gets the game URL
  const url = `https://www.roblox.com/games/${gid}`;

  const searchForGame = function (gid, min, max) {
    // Get the game page
    let page = Math.round((max + min) / 2);
    // Fetch roblox's servers
    fetch(`https://www.roblox.com/games/getgameinstancesjson?placeId=${gid}&startindex=${page}`)
      // Turn the response into JSON
      .then((resp) => resp.json())
      .then(function (data) {
        if (data.Collection.length < 10 && data.Collection.length > 0) {
          let server = data.Collection[data.Collection.length - 1];
          if(server.CurrentPlayers.length == 0) {
            min = page;
            console.log("No people, trying new server:", page);
            searchForGame(gid, min, max);
            return false;
          }
          console.log(
            "Found empty server:",
            server,
            "\nCurrent Total Players:",
            server.CurrentPlayers.length
          );
          if (
            confirm(
              "Found server with " +
                server.CurrentPlayers.length +
                " players.\nWould you like to join this server?"
            )
          ) {
            try {
              eval(server.JoinScript);
            } catch (e) {
              console.log("Error:", e);
            }
          } else {
            min = page;
            console.log("User canceled, trying new server:", page);
            searchForGame(gid, min, max);
            return false;
          }
          return true;
        } else if (data.Collection.length == 0) {
          max = page;
          console.log("Page empty, trying new page:", page);
          searchForGame(gid, min, max);
        } else {
          min = page;
          console.log("Not empty, trying new server:", page);
          searchForGame(gid, min, max);
        }
      });
  };

  let h3ader = document.createElement("h3");
  h3ader.innerHTML = "Empty Server Tool";

  let btn = document.createElement("span");
  btn.id = "-ServerTool-findServer";
  btn.onclick = function () {
    searchForGame(gid, 0, 10000);
  };
  btn.innerHTML = "Join Empty Server";
  btn.className = "btn-secondary-md";

  document.getElementById("game-instances").prepend(btn);
  document.getElementById("game-instances").prepend(h3ader);
})();