Roblox Server Utils

Adds useful features related to roblox servers

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Roblox Server Utils
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Adds useful features related to roblox servers
// @author       Kugel
// @match        http*://www.roblox.com/games/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=roblox.com
// @grant        GM_setClipboard
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const placeId = URL.parse(location.href).pathname.split("/")[2];
    if(!placeId) return;
    const updateMenu = (oldBtn, jobId) => {
        oldBtn.querySelector("a").onclick = (ev) => {
            if (ev.target.id === "copy-jobid") {
                GM_setClipboard(jobId);
            }
        };
    };
    const createMenu = (container, jobId) => {
        const oldBtn = container.querySelector("button#rbx-utils");
        if (oldBtn) return updateMenu(oldBtn, jobId);
        const menuBtn = document.createElement("button");
        menuBtn.className = "btn-generic-more-sm";
        menuBtn.type = "button";
        menuBtn.id = "rbx-utils";
        menuBtn.title = "more";

        const menuSpan = document.createElement("span");
        menuSpan.className = "icon-more";
        menuBtn.appendChild(menuSpan);
        container.appendChild(menuBtn);
        const popup = `<div id="game-instance-dropdown-menu" role="tooltip" class="fade in popover bottom" style="display: none; position: relative;"><div class="arrow" style="left: 50%;"></div><div class="popover-content"><ul class="dropdown-menu" role="menu"><li><a class="rbx-private-server-configure" id="copy-jobid">Copy job ID</a></li></ul></div></div>`;
        menuBtn.innerHTML += popup;

        menuBtn.onclick = () => {
            const popover = menuBtn.querySelector("div");
            popover.style.display = popover.style.display == "none" ? "block" : "none";

        };

        menuBtn.querySelector("a").onclick = (ev) => {
            if (ev.target.id === "copy-jobid") {
                GM_setClipboard(jobId);
            }
        };
    };
    const updateRate = 2000;
    setInterval(() => {
        const joinBtns = document.querySelectorAll("button.game-server-join-btn");
        for (const btn of joinBtns) {
            const jobId = btn.getAttribute("data-btr-instance-id");
            if (!jobId) continue;

            createMenu(btn.parentElement.parentElement, jobId, placeId);
        }
    }, updateRate);
    const joinInstance = unsafeWindow.Roblox.GameLauncher.joinGameInstance;
    if (!joinInstance) return;
    const containerHeader = document.querySelector("div#rbx-public-running-games").querySelector("div.container-header");
    containerHeader.id = "rbx-utils";
    const joinDiv = document.createElement("div");
    joinDiv.style.padding = "6px";
    const jobInput = document.createElement("input");
    jobInput.type = "text";
    jobInput.className = "dialog-input";
    jobInput.placeholder = "Job ID";
    jobInput.style = "overflow: hidden; overflow-wrap: break-word; width: 325px; height: 37px; border: none; outline: none; margin-right: 5px; border-radius: 10px; padding: 5px; text-align: center;";
    jobInput.spellcheck = false;
    jobInput.autocapitalize = "off";
    jobInput.autocomplete = "off";
    const joinBtn = document.createElement("button");
    joinBtn.type = "submit";
    joinBtn.textContent = "Join";
    joinBtn.className = "btn-primary-md";
    joinBtn.onclick = () => {
        const jobId = jobInput.value;
        if(jobId === "") alert("No job ID specified. choosing random server.");
        joinInstance(placeId, jobId);
    };
    joinDiv.appendChild(jobInput);
    joinDiv.appendChild(joinBtn);
    containerHeader.appendChild(joinDiv);

})();