Roblox Smart Server Join

Join Roblox servers intelligently based on server size, including private servers with debugging logs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Roblox Smart Server Join
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Join Roblox servers intelligently based on server size, including private servers with debugging logs
// @author       Kanako
// @match        *://www.roblox.com/*
// @grant        none
// @license      Apache License 2.0
// ==/UserScript==

(function() {
    'use strict';

    // Function to join a public server using the protocol URL
    function joinPublicServer(placeId, jobId) {
        const protocolUrl = `roblox://experiences/start?placeId=${placeId}&gameInstanceId=${jobId}`;
        console.log(`Joining public server with URL: ${protocolUrl}`);
        window.location.href = protocolUrl;
    }

    // Function to join a private server using the protocol URL
    function joinPrivateServer(placeId, linkCode) {
        const protocolUrl = `roblox://placeid=${placeId}&linkcode=${linkCode}`;
        console.log(`Joining private server with URL: ${protocolUrl}`);
        window.location.href = protocolUrl;
    }

    // Extract the placeId and linkCode from the URL
    function extractParamsFromUrl(url) {
        const regex = /\/games\/(\d+)\/[^?]+\?privateServerLinkCode=(\d+)/;
        const match = url.match(regex);
        if (match && match.length === 3) {
            console.log(`Extracted placeId: ${match[1]}, linkCode: ${match[2]}`);
            return { placeId: match[1], linkCode: match[2] };
        } else {
            console.error('Could not extract placeId and linkCode from URL');
            return null;
        }
    }

    // Disable default join behavior for private servers
    function disableDefaultJoin() {
        window.addEventListener('click', function(event) {
            const element = event.target;
            if (element.tagName === 'A' && element.href && element.href.startsWith('https://www.roblox.com/games/') &&
                element.href.includes('privateServerLinkCode')) {
                event.preventDefault();
            }
        });
    }

    // Replace current page with a blank page
    function replaceWithBlankPage() {
        const blankPageUrl = 'about:blank';
        console.log('Replacing page with a blank page...');
        window.location.replace(blankPageUrl);
    }

    // Run the setup functions and replace with a blank page immediately
    disableDefaultJoin();
    const params = extractParamsFromUrl(window.location.href);
    if (params) {
        const { placeId, linkCode } = params;
        console.log('Detected private server link.');
        joinPrivateServer(placeId, linkCode);
    } else {
        const playButton = document.querySelector('button[data-testid="play-button"]');
        if (playButton) {
            console.log('Play button detected.');
            playButton.addEventListener('click', async function(e) {
                e.preventDefault();
                console.log('Play button clicked');
                // Add your logic to join a public server here
            });
        }

        // Add logic to handle joining public servers here
        console.log('Searching for public server join button.');
    }
    replaceWithBlankPage(); // Replace with a blank page after setup
})();