neftalito / Join empty roblox server

// ==UserScript==
// @name         Join empty roblox server
// @version      0.0.4
// @namespace   https://openuserjs.org/users/neftalito
// @description  Adds a button on roblox to join an empty server (or the server with less people)
// @author       Neftalito
// @match        https://www.roblox.com/games/*
// @copyright 2021, neftalito (https://openuserjs.org/users/neftalito)
// @license MIT
// ==/UserScript==
/*jshint esversion: 6 */

function Entrar() {
    const gid = Number(window.location.pathname.split('/')[2]);
    const url = `https://www.roblox.com/games/${gid}`;

    const searchForGame = function (gid, min, max) {
        var page = Math.round((max + min) / 2);
        fetch(`https://www.roblox.com/games/getgameinstancesjson?placeId=${gid}&startindex=${page}`)
            .then((resp) => resp.json())
            .then(function (data) {
                if (data.Collection.length < 10 && data.Collection.length > 0) {
                    var server = data.Collection[data.Collection.length - 1];
                    console.log('Servidor vacio encontrado:', server, '\nJugadores:', server.CurrentPlayers.length);
                    button.innerHTML = 'Server found!';
                    try {
                        eval(server.JoinScript);
                    } catch (e) {
                        console.log('Error:', e);
                        button.innerHTML = 'Error';
                    }
                    return true;
                } else if (data.Collection.length == 0) {
                    max = page;
                    console.log('Pagina vacia: Probando otra pagina', page);
                    searchForGame(gid, min, max);
                } else {
                    min = page;
                    console.log('No vacio, probando un nuevo servidor:', page);
                    searchForGame(gid, min, max);
                }
            });
    };
    searchForGame(gid, 0, 10000);
}

var button = document.createElement('button');
document.getElementsByClassName('game-buttons-container')[0].appendChild(button);
button.innerHTML = 'Join Empty Server';
button.addEventListener("click", function () {
    button.innerHTML = "Searching server..."
    Entrar();
    button.disabled = true;
    setTimeout(() => {button.innerHTML = 'Join Empty Server'; button.disabled = false;}, 10000);
});
button.style.background = '#3fc679';
button.style.borderRadius='8px';