janitorai reroll

Simply reroll result automatically since all free service are completed shit

Versione datata 28/08/2025. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         janitorai reroll
// @namespace    http://tampermonkey.net/
// @version      1.02
// @description  Simply reroll result automatically since all free service are completed shit
// @author       James
// @icon         https://ella.janitorai.com/hotlink-ok/logo.png
// @license      MIT
// @match        https://janitorai.com/chats/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var inProgress = false;
    var lastMessageText;
    var receivedResponse = false;
    var stop = false;

    var intervalTime = 10;
    var randomInterval = true;
    var responseLength = 200;
    var numberRetry = 50;

    var style = document.createElement('style');
    style.innerHTML = 'body {font-family: Arial, Helvetica, sans-serif;}.my-modal-reroll {display: none; /* Hidden by default */position: fixed; /* Stay in place */z-index: 20; /* Sit on top */padding-top: 100px; /* Location of the box */left: 0;top: 0;width: 100%; /* Full width */height: 100%; /* Full height */overflow: auto; /* Enable scroll if needed */background-color: rgb(0,0,0); /* Fallback color */background-color: rgba(0,0,0,0.4); /* Black w/ opacity */}.my-modal-content-reroll {background-color: black;margin: auto;padding: 20px;border: 1px solid #888;width: 80%;color: #42b01a}.my-close-reroll {color: #aaaaaa;float: right;font-size: 28px;font-weight: bold;}.my-close-reroll:hover,.my-close-reroll:focus {color: red;text-decoration: none;cursor: pointer;}';
    document.head.appendChild(style);

    var elemDiv = document.createElement('div');
    document.body.appendChild(elemDiv);
    elemDiv.innerHTML = '<div id="myModalReroll" class="my-modal-reroll"><div class="my-modal-content-reroll"><span id="my-close-reroll" class="my-close-reroll">&times;</span>Lenght of time (In seconds): <input type="number" id="my-interval-time" value="10"><br>Random interval add (Add 1-5 second to every attempt): <input id="my-random-interval-time" type="checkbox" checked=true><br>Length response (Number of characters): <input type="number" id="my-length-response" value="200"><br>Number of reroll: <input type="number" id="my-number-reroll" value="50"><br><div>In progress: </div><div id="in-progress">❌</div><br><input type="button" id="my-reroll-button" value="Submit">  <input type="button" id="my-reroll-button-stop" value="Stop"></div></div>';

    var modal = document.getElementById("myModalReroll");
    var btn = document.getElementById("myButtonModal");
    var span = document.getElementById("my-close-reroll");

    span.onclick = function() {
        modal.style.display = "none";//The x button to close
    }

    window.onclick = function(event) {
        if (event.target == modal) {
            modal.style.display = "none";//When the user clicks anywhere outside of the modal, close it
        }
    }

    document.onkeydown = function(){
        if(window.event && window.event.keyCode == 112)//F1 keyboard listen
        {
            modal.style.display = "block";//Hidden button to active pop-up
        }
    }

    var myRerollButton = document.getElementById("my-reroll-button");
    myRerollButton.onclick = function() { startRerolling();};

    var myRerollButtonStop = document.getElementById("my-reroll-button-stop");
    myRerollButtonStop.onclick = function() { stopOperation();};

    var listOfMessage;
    var newestMessage;
    var timeoutId;
    var intervalID;

    function startRerolling(){
        myRerollButton.disabled = true;
        document.getElementById("in-progress").innerText = "✅";
        listOfMessage = document.querySelectorAll('[data-index]');
        lastMessageText = listOfMessage[listOfMessage.length - 1].getElementsByClassName('css-ji4crq')[listOfMessage[listOfMessage.length - 1].getElementsByClassName('css-ji4crq').length - 1].outerText;

        intervalTime = parseInt(document.getElementById("my-interval-time").value);
        randomInterval = document.getElementById("my-random-interval-time").checked;
        responseLength = parseInt(document.getElementById("my-length-response").value);
        numberRetry = parseInt(document.getElementById("my-number-reroll").value);

        if(randomInterval){
            intervalTime = intervalTime + Math.floor(Math.random() * 5);
        }

        if(Number.isInteger(intervalTime) && Number.isInteger(responseLength) && Number.isInteger(numberRetry)){
            let retries = numberRetry;//open router daily or gemini, you could change it to higher if you got prenium in either

            intervalID = setInterval(_ => {
                if(document.getElementsByClassName('_stopButton_17cr1_1').length == 0){//Stop button doesn't exist, which mean we are not waiting for a response anymore
                    if(!inProgress){
                        inProgress = true;

                        let randomNumber = Math.floor(Math.random() * 5);
                        if(!randomInterval) randomNumber = 0;

                        timeoutId = setTimeout(_ => {

                            try {
                                listOfMessage = document.querySelectorAll('div[data-index]');//If message error type interfere, may need more precise code here
                                newestMessage = listOfMessage[listOfMessage.length - 1].getElementsByClassName('css-ji4crq')[listOfMessage[listOfMessage.length - 1].getElementsByClassName('css-ji4crq').length - 1];//We need to check if response is minimum length wanted
                                if(lastMessageText != newestMessage.outerText && newestMessage.outerText.length >= responseLength){//response different and of comfort minimum lenght, This mean all reroll gave a succesful response otherwise we keep going
                                    stopOperation();
                                }else{
                                    if(document.getElementsByClassName('_botChoiceButton_nr7g7_21 _right_nr7g7_39').length != 0){//Reroll button from response
                                        document.getElementsByClassName('_botChoiceButton_nr7g7_21 _right_nr7g7_39')[0].click();
                                    }
                                    if(document.querySelectorAll('[aria-label="Re-generate last answer"]').length != 0){//Reroll button from message
                                        document.querySelectorAll('[aria-label="Re-generate last answer"]')[0].click();
                                    }
                                }
                            } catch(error){
                                console.log("error:");
                                console.log(error);
                                /*
                                //Keeping this here, if I rather still doing rerolling if there unknow error
                                if(document.getElementsByClassName('_botChoiceButton_nr7g7_21 _right_nr7g7_39').length != 0){//Reroll button from response
                                    //document.getElementsByClassName('_botChoiceButton_nr7g7_21 _right_nr7g7_39')[0].click();
                                }
                                if(document.querySelectorAll('[aria-label="Re-generate last answer"]').length != 0){//Reroll button from message
                                    //document.querySelectorAll('[aria-label="Re-generate last answer"]')[0].click();
                                }
                                */
                            }

                            retries--;

                            inProgress = false;

                        }, (intervalTime + randomNumber) * 1000);//Transform second to millisecond

                    }

                }

                if(retries <= 0){
                    stopOperation();

                }
            }, 2000);//Every 2 second check current status

        }

    }

    function stopOperation(){
        document.getElementById("in-progress").innerText = "❌";
        inProgress = false;
        myRerollButton.disabled = false;
        clearTimeout(timeoutId);
        clearInterval(intervalID);
    }

})();