janitorai reroll

Simply reroll result automatically since all free service are completed shit

目前為 2025-08-28 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         janitorai reroll
// @namespace    http://tampermonkey.net/
// @version      1.01
// @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('[data-index]');
                                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){
                                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);
    }

})();