RustClash.com - Check tickets

This script will show all tickets in a battle

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         RustClash.com - Check tickets
// @namespace    https://gge.gg
// @version      0.1
// @description  This script will show all tickets in a battle
// @author       twitter.com/thes0meguy
// @match        https://rustclash.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rustclash.com
// @grant        none
// @license      WTFPL
// @require https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.5/seedrandom.min.js
// ==/UserScript==

(function() {
    'use strict';

    async function fetchData() {

        if (window.location.href.indexOf("battle") === -1 || window.location.href === "https://rustclash.com/battles") {
            return;
        }
        let currentLink = window.location.href;
        let battleLink = currentLink.toString().replace("https://rustclash.com/battles/", "");
        let battleUrl = "/api/battles/"+battleLink+"/details/";
        if (currentLink.toString().includes("password")){
            let password = currentLink.toString();
            password = password.replace("https://rustclash.com/battles/", "")
            password = password.replace("?password","/details?password")
            battleUrl = "/api/battles/"+password
        }

        const response = await fetch(battleUrl);
        const battleInfo = await response.json();
        let seed = battleInfo.seed;
        if (seed === null){
            return;
        }
        let slots = battleInfo.playerCount;
        let cases = battleInfo.cases;
        let rounds = 0;
        for (let i = 0; i < cases.length;i++){
            rounds = rounds + cases[i].amount;
        }
        let results = "";
        for (let round = 0; round < rounds; round++) {
            results += `<tr><td>#${round + 1}</td>`

            for (let slot = 1; slot <= slots; slot++) {
                const seedX = `${seed}:${round+1}:${slot}`
                const rollNumber = new Math.seedrandom(seedX)()
                const ticket = ~~(rollNumber * 100_000)
                let color = "848B8D";
                if(ticket <= 10){
                    color = "f44336";
                } else if(ticket <= 50){
                    color = "ff5722";
                }else if(ticket <= 200){
                    color = "ff9800";
                }else if(ticket <= 500){
                    color = "ffc107";
                }else if(ticket <= 1000){
                    color = "cddc39";
                }else if(ticket <= 3000){
                    color = "8bc34a";
                }else if(ticket <= 5000){
                    color = "4caf50";
                }
                results += `<td style="color: #${color};">${ticket}</td>`
            }

            results += '</tr>'
        }
        const tieTicket = new Math.seedrandom(seed)()
        const allDivs = Array.from(document.querySelectorAll('div'));
        const targetDivIndex = allDivs.findIndex(div => div.textContent.trim() === 'Provably Fair');

        const existingDiv = document.getElementById('someguy');

        if (!existingDiv && targetDivIndex !== -1 && allDivs[targetDivIndex + 1]) {
            const newDiv = document.createElement('div');
            newDiv.id = 'someguy';
            Object.assign(newDiv.style, {
                display: 'flex',
                alignItems: 'center',
                marginBottom: '1rem',
                gap: '5px',
                flexDirection: 'column'
            });
            newDiv.innerHTML = `<table style="font-size:12px;width: 100%; text-align: center;">
      <thead style="font-weight:800;color:#fff;">
        <th>Round</th>
        ${new Array(slots).fill(0).map((_, i) => `<th>Slot #${i + 1}</th>`).join('')}
      </thead>
      <tbody>${results}</tbody>
    </table><div style="font-size:12px;">
      Tie ticket - ${tieTicket}
    </div>`;


            allDivs[targetDivIndex + 1].insertAdjacentElement('afterbegin', newDiv);
        }
        else if (existingDiv) {
            existingDiv.innerHTML = `<table style="font-size:12px;width: 100%; text-align: center;">
      <thead style="font-weight:800;color:#fff;">
        <th>Round</th>
        ${new Array(slots).fill(0).map((_, i) => `<th>Slot #${i + 1}</th>`).join('')}
      </thead>
      <tbody>${results}</tbody>
    </table><div style="font-size:12px;">
      Tie ticket - ${tieTicket}
    </div>`;
        }

    }
    setTimeout(fetchData, 1000);
    setInterval(fetchData, 5000);
})();