RustClash.com - Check tickets

This script will show all tickets in a battle

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==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);
})();