RoSniperX

working stream sniper script without using exploits

目前為 2024-12-02 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         RoSniperX
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  working stream sniper script without using exploits
// @author       Lukas Dobbles
// @match        https://www.roblox.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
const getJSON = (url, args = {}) => {
  args.headers = args.headers || {};
  args.credentials = "include";

  return fetch(url, args).then((r) => r.json());
};

const search = async (placeId, name, setStatus, cb, setThumb) => {
  const userId = await getUserId(name);
  const thumbUrl = await getThumb(userId);
  setStatus("thumb url: " + thumbUrl);
  setThumb(thumbUrl);
  let cursor = null;
  let searching = true;
  let allPlayerTokens = [];
  let serversScraped = 0;
  const startTime = Date.now();

  while (searching) {
    const servers = await getServer(placeId, cursor).catch((err) => {
      setStatus(
        `Error fetching servers. Try again or get help on the discord server https://discord.gg/7zTCxVj9JD. ${err}`
      );
    });
    serversScraped += servers.data.length;

    cursor = servers.nextPageCursor;
    for (let i = 0; i < servers.data.length; i++) {
      const place = servers.data[i];
      allPlayerTokens = allPlayerTokens.concat(
        place.playerTokens.map((token) => ({
          token,
          place,
        }))
      );
    }

    if (!cursor) break;

    setStatus(
      `scraped ${allPlayerTokens.length} player tokens from ${serversScraped} servers`
    );
  }

  const chunkSize = 100;

  let found = false;

  for (let i = 0; i < allPlayerTokens.length && !found; i += chunkSize) {
    const chunk = allPlayerTokens.slice(i, i + chunkSize);
    setStatus(
      `Searching servers ${Math.floor(
        ((i + chunk.length) / allPlayerTokens.length) * 100
      )}%`
    );

    try {
      const { data: serverThumbs } = await fetchThumbs(
        chunk.map(({ token }) => token)
      );
      if (!serverThumbs) {
        setStatus(
          "Error fetching server thumbnails. Try again or get help at the Discord server: https://discord.gg/7zTCxVj9JD."
        );
        continue;
      }

      for (const thumb of serverThumbs) {
        if (thumb && thumb.imageUrl === thumbUrl) {
          found = true;

          setStatus(
            `Found them! Searched ${allPlayerTokens.length} players in ${
              (Date.now() - startTime) / 1000
            } seconds`
          );

          const thumbToken = thumb.requestId.split(":")[1];
          const matchedPlace = chunk.find((x) => x.token === thumbToken)?.place;

          if (matchedPlace) {
            cb({
              found: true,
              place: matchedPlace,
            });
          } else {
            setStatus("Matched place not found.");
            cb({ found: false });
          }

          break; // Exit the loop once found
        }
      }

      // If after the last chunk and not found
      if (!found && i + chunkSize >= allPlayerTokens.length) {
        cb({ found: false });
      }
    } catch (err) {
      setStatus(
        "There was an error when fetching user thumbnails. Try again or get help at the Discord server: https://discord.gg/7zTCxVj9JD. " +
          err
      );
    }
  }

  // If not found after all chunks
  if (!found) {
    cb({ found: false });
  }
};

const getUserId = (name) =>
  fetch("https://www.roblox.com/users/profile?username=" + name).then((r) => {
    return r.url.match(/\d+/)[0];
  });

const getThumb = (id) =>
  getJSON(
    `https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${id}&format=Png&size=150x150`
  ).then((d) => d.data[0].imageUrl);

const getServer = (placeId, cursor) => {
  let url = `https://games.roblox.com/v1/games/${placeId}/servers/Public?limit=100`;

  if (cursor) url += "&cursor=" + cursor;
  return getJSON(url);
};

const fetchThumbs = (tokens) => {
  let body = [];

  tokens.forEach((token) => {
    body.push({
      requestId: `0:${token}:AvatarHeadshot:150x150:png:regular`,
      type: "AvatarHeadShot",
      targetId: 0,
      token,
      format: "png",
      size: "150x150",
    });
  });

  return getJSON("https://thumbnails.roblox.com/v1/batch", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Accept: "application/json",
    },
    body: JSON.stringify(body),
  });
};

const instancesContainer = document.getElementById(
  "running-game-instances-container"
);
if (instancesContainer) {
  const containerHeader = document.createElement("div");
  containerHeader.classList = "section";

  const headerText = document.createElement("h2");
  headerText.innerText = "RoSniperX";
  containerHeader.appendChild(headerText);

  const form = document.createElement("form");

  const thumbImage = document.createElement("img");
  thumbImage.height = "40";
  thumbImage.style.display = "none";
  containerHeader.appendChild(thumbImage);

  const usernameInput = document.createElement("input");
  usernameInput.classList = "input-field";
  usernameInput.placeholder = "Username";
  form.appendChild(usernameInput);

  const submitButton = document.createElement("button");
  submitButton.classList = "btn-primary-md";
  submitButton.innerText = "Search";
  submitButton.disabled = true;
  form.appendChild(submitButton);

  usernameInput.addEventListener("keyup", (e) => {
    submitButton.disabled = e.target.value.length === 0;
  });

  const statusText = document.createElement("p");
  form.appendChild(statusText);

  const joinBtn = document.createElement("button");
  joinBtn.style.display = "none";
  joinBtn.innerText = "Join";
  joinBtn.classList =
    "btn-control-xs rbx-game-server-join game-server-join-btn btn-primary-md btn-min-width";

  containerHeader.appendChild(form);
  containerHeader.appendChild(joinBtn);
  instancesContainer.insertBefore(
    containerHeader,
    instancesContainer.firstChild
  );

  form.addEventListener("submit", (evt) => {
    evt.preventDefault();

    joinBtn.style.display = "none";

    const placeId = location.href.match(/\d+/)[0];

    search(
      placeId,
      usernameInput.value,
      (txt) => {
        console.log(txt);
        statusText.innerText = txt;
      },
      (place) => {
        if (!place.found) {
          statusText.innerText = "couldn't find them";
          joinBtn.style.display = "none";
          return;
        }

        joinBtn.style.display = "";

        joinBtn.onclick = () => {
          window.Roblox.GameLauncher.joinGameInstance(placeId, place.place.id);
        };
      },
      (src) => {
        thumbImage.src = src;
        thumbImage.style.display = "";
      }
    );
  });
}
})();