Show random verification time

show random verification time

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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                Show random verification time
// @namespace           https://greatest.deepsurf.us/users/821661
// @match               https://*.superau.la/*
// @grant               none
// @version             1.0
// @require             https://update.greatest.deepsurf.us/scripts/526417/1540623/USToolkit.js
// @author              hdyzen
// @description         show random verification time
// @license             GPL-3.0-only
// ==/UserScript==

function waitElement(selector) {
    return new Promise((resolve, reject) => {
        const callback = () => {
            const target = document.querySelector(selector);
            if (target) resolve(target);
        };

        const observer = new MutationObserver(callback);

        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    });
}

async function init() {
    try {
        const dataFutura = new Date(JSON.parse(localStorage.getItem("db-v6")).CurrentSession.AulaEmAndamento.ValidacaoAleatoria.CandidatoConvocacoes[0].HoraConvocacaoAleatoria);
        const restante = await waitElement(".chat__header__title:has(> :nth-child(2))");
        const aleatoria = document.createElement("span");
        aleatoria.style.marginLeft = "6px";
        restante.appendChild(aleatoria);

        const intervalo = setInterval(() => {
            const agora = new Date();
            const tempoRestante = dataFutura - agora;

            if (tempoRestante <= 0) {
                clearInterval(intervalo);
                console.log("A data futura foi alcançada!");
            } else {
                const segundos = Math.floor((tempoRestante / 1000) % 60);
                const minutos = Math.floor((tempoRestante / (1000 * 60)) % 60);
                const horas = Math.floor((tempoRestante / (1000 * 60 * 60)) % 24);

                aleatoria.textContent = `• ${horas}h${minutos}m${segundos}s`;
                // console.log(`${horas}h${minutos}m${segundos}s`);
            }
        }, 1000);
    } catch (error) {
        console.error("Error: ", error);
    }
}
init();