MouseHunt AutoBot UPDATED

Script automating MH horn sounding and gifting, mostly functional as of 14/04/2024; updating the outdated script from nobodyrandom, who adapted the original versions by CnN and Ooi.

< Feedback on MouseHunt AutoBot UPDATED

سؤال / تعليق

§
Posted: 05-05-2023

Fix for new KR:

Change

var puzzleAns = document.getElementsByClassName("mousehuntPage-puzzle-form-code")[0];

to

var puzzleAns = document.getElementsByClassName("puzzleView__code")[0];

Change

var puzzleSubmit = document.getElementsByClassName("mousehuntPage-puzzle-form-code-button")[0];

to

var puzzleSubmit = document.getElementsByClassName("puzzleView__solveButton")[0];

Change

if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
}

to

if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
}

puzzleSubmit.classList.remove("disabled");

Change

var inputElementList = document.getElementsByTagName('input');
if (inputElementList) {
        var i;
        for (i = 0; i < inputElementList.length; ++i) {
            // check if it is a resume button
            if (inputElementList[i].getAttribute('name') == "puzzle_answer") {
                inputElementList[i].focus();
                break;
            }
        }
        i = null;
}
inputElementList = null;

to

var inputKingsReward = document.getElementsByClassName('puzzleView__code')[0];
inputKingsReward.focus();
§
Posted: 06-05-2023

This doesn't work.

§
Posted: 06-05-2023

This doesn't work.

It solves the KR, but doesn't click the resume button, as of now. I forgot to code for that.

Below is the code for that:

Change:

var puzzleForm = document.getElementsByClassName("mousehuntPage-puzzle-formContainer")[0];
    if (puzzleForm.classList.contains("noPuzzle")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

to

var puzzleForm = document.getElementsByClassName("puzzleView")[0];
    if (puzzleForm.classList.contains("puzzleView--state-solved")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

Change:

    var resumeButton = document.getElementsByClassName("mousehuntPage-puzzle-form-complete-button")[0];

to

    var resumeButton = document.getElementsByClassName("puzzleView__resumeButton")[0];

Change:

            resumeElement = document.getElementsByClassName('mousehuntPage-puzzle-form-complete-button')[0];

to

            resumeElement = document.getElementsByClassName('puzzleView__resumeButton')[0];

Note that I have not tested this yet, so try it and let me know. The codes from the first comment on this thread have been tested and works (but not clicking the resume button).

If it still doesn't work, please paste the console log of your browser instead of just saying it doesn't work.

§
Posted: 06-05-2023

Also this:

Change:

    var codeError = document.getElementsByClassName("mousehuntPage-puzzle-form-code-error");

to

    var codeError = document.getElementsByClassName("puzzleView__error");

§
Posted: 06-05-2023

caught TypeError: Cannot read properties of null (reading 'querySelector')

frame.src = img.querySelector('img').src;

§
Posted: 06-05-2023
Edited: 06-05-2023

I might have missed a few lines of changes I made myself.

From the current version of the script, v1.7, disregard my comments above, and replace everything between // CNN KR SOLVER START and // CNN KR SOLVER END with

// CNN KR SOLVER START
function FinalizePuzzleImageAnswer(answer) {
if (debug) console.log("RUN FinalizePuzzleImageAnswer()");
    if (debug) console.log(answer);

    var myFrame;
    if (answer.length != 5) {
        //Get a new puzzle
        if (kingsRewardRetry >= kingsRewardRetryMax) {
            kingsRewardRetry = 0;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
            alert(strTemp);
            displayTimer(strTemp, strTemp, strTemp);
            console.perror(strTemp);
            return;
        } else {
            ++kingsRewardRetry;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var tagName = document.getElementsByTagName("a");
            for (var i = 0; i < tagName.length; i++) {
                if (tagName[i].innerText == "Click here to get a new one!") {
                    // TODO IMPORTANT: Find another time to fetch new puzzle
                    fireEvent(tagName[i], 'click');
                    myFrame = document.getElementById('myFrame');
                    if (!isNullOrUndefined(myFrame))
                        document.body.removeChild(myFrame);
                    window.setTimeout(function () {
                        CallKRSolver();
                    }, 6000);
                    return;
                }
            }
        }
    } else {
        if (debug) console.log("Submitting captcha answer: " + answer);
        //Submit answer

        //var puzzleAns = document.getElementById("puzzle_answer");
        var puzzleAns = document.getElementsByClassName("puzzleView__code")[0];

        if (!puzzleAns) {
            if (debug) console.plog("puzzleAns: " + puzzleAns);
            return;
        }
        puzzleAns.value = "";
        puzzleAns.value = answer.toLowerCase();

        //var puzzleSubmit = document.getElementById("puzzle_submit");
        var puzzleSubmit = document.getElementsByClassName("puzzleView__solveButton")[0];

        if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
        }

        puzzleSubmit.classList.remove("disabled");

        fireEvent(puzzleSubmit, 'click');
        kingsRewardRetry = 0;
        setStorage("KingsRewardRetry", kingsRewardRetry);
        myFrame = document.getElementById('myFrame');
        if (myFrame)
            document.body.removeChild(myFrame);

        window.setTimeout(function () {
            CheckKRAnswerCorrectness();
        }, 5000);
    }
}

function receiveMessage(event) {
if (debug) console.debug("Event origin: " + event.origin);

    if (!debugKR && !isAutoSolve)
        return;

    if (event.origin.indexOf("mhcdn") > -1 || event.origin.indexOf("mousehuntgame") > -1 || event.origin.indexOf("dropbox") > -1) {
        if (event.data.indexOf("~") > -1) {
            var result = event.data.substring(0, event.data.indexOf("~"));
            if (saveKRImage) {
                var processedImg = event.data.substring(event.data.indexOf("~") + 1, event.data.length);
                var strKR = "KR" + separator;
                strKR += Date.now() + separator;
                strKR += result + separator;
                strKR += "RETRY" + kingsRewardRetry;
                try {
                    setStorage(strKR, processedImg);
                } catch (e) {
                    console.perror('receiveMessage', e.message);
                }
            }
            FinalizePuzzleImageAnswer(result);
        } else if (event.data.indexOf("#") > -1) {
            var value = event.data.substring(1, event.data.length);
            setStorage("krCallBack", value);
        } else if (event.data.indexOf('Log_') > -1)
            console.plog(event.data.split('_')[1]);
        else if (event.data.indexOf('MHAKRS_') > -1) {
            var temp = event.data.split('_');
            console.plog(temp[0], temp[1]);
            setStorage(temp[0], temp[1]);
        }
    }
}

function CallKRSolver() {
if (debug) console.log("RUN CallKRSolver()");

    var frame = document.createElement('iframe');
    frame.setAttribute("id", "myFrame");
    var img;
    if (debugKR) {
        //frame.src = "https://dl.dropboxusercontent.com/s/4u5msso39hfpo87/Capture.PNG";
        //frame.src = "https://dl.dropboxusercontent.com/s/og73bcdsn2qod63/download%20%2810%29Ori.png";
        frame.src = "https://dl.dropboxusercontent.com/s/ppg0l35h25phrx3/download%20(16).png";
    } else {
        //if (isNewUI) {

        img = document.getElementsByClassName('puzzleView__image')[0];
        if (debug) console.log("Captcha Image fetched:")
        if (debug) console.log(img);

        frame.src = img.querySelector('img').src;
        /*} else {
            img = document.getElementById('puzzleImage');
            frame.src = img.src;
        }*/
    }
    document.body.appendChild(frame);
}

function CheckKRAnswerCorrectness() {
var puzzleForm = document.getElementsByClassName("puzzleView")[0];
    if (puzzleForm.classList.contains("puzzleView--state-solved")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

    var strTemp = '';
    var codeError = document.getElementsByClassName("puzzleView__error");
    for (var i = 0; i < codeError.length; i++) {
        if (codeError[i].innerText.toLowerCase().indexOf("incorrect claim code") > -1) {
            if (kingsRewardRetry >= kingsRewardRetryMax) {
                kingsRewardRetry = 0;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
                alert(strTemp);
                displayTimer(strTemp, strTemp, strTemp);
                console.perror(strTemp);
            } else {
                ++kingsRewardRetry;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                CallKRSolver();
            }
            return;
        }
    }

    window.setTimeout(function () {
        CheckKRAnswerCorrectness();
    }, 1000);
}

function resumeKRAfterSolved() {
if (debug) console.log("RUN resumeKRAfterSolved()");

    var resumeButton = document.getElementsByClassName("puzzleView__resumeButton")[0];
    location.reload(true)
}

function addKREntries() {
var i, temp, maxLen, keyName;
    var replaced = "";
    var nTimezoneOffset = -(new Date().getTimezoneOffset()) * 60000;
    var count = 1;
    var strInnerHTML = '';
    var selectViewKR = document.getElementById('viewKR');
    if (selectViewKR.options.length > 0) {
        // append keyKR for new KR entries under new UI
        for (i = 0; i < window.localStorage.length; i++) {
            keyName = window.localStorage.key(i);
            if (keyName.indexOf("KR" + separator) > -1 && keyKR.indexOf(keyName) < 0)
                keyKR.push(keyName);
        }
    }
    maxLen = keyKR.length.toString().length;
    for (i = 0; i < keyKR.length; i++) {
        if (keyKR[i].indexOf("KR" + separator) > -1) {
            temp = keyKR[i].split(separator);
            temp.splice(0, 1);
            temp[0] = parseInt(temp[0]);
            if (Number.isNaN(temp[0]))
                temp[0] = 0;

            temp[0] += nTimezoneOffset;
            temp[0] = (new Date(temp[0])).toISOString();
            replaced = temp.join("&nbsp;&nbsp;");
            temp = count.toString();
            while (temp.length < maxLen) {
                temp = '0' + temp;
            }
            replaced = temp + '. ' + replaced;
            strInnerHTML += '<option value="' + keyKR[i] + '"' + ((i == keyKR.length - 1) ? ' selected' : '') + '>' + replaced + '</option>';
            count++;
        }
    }
    if (strInnerHTML !== '')
        selectViewKR.innerHTML = strInnerHTML;
}

function setKREntriesColor() {
// set KR entries color
    var i, nCurrent, nNext, strCurrent;
    var selectViewKR = document.getElementById('viewKR');
    for (i = 0; i < selectViewKR.children.length; i++) {
        if (i < selectViewKR.children.length - 1) {
            nCurrent = parseInt(selectViewKR.children[i].value.split('~')[1]);
            nNext = parseInt(selectViewKR.children[i + 1].value.split('~')[1]);
            if (Math.round((nNext - nCurrent) / 60000) < 2)
                selectViewKR.children[i].style = 'color:red';
        }
        strCurrent = selectViewKR.children[i].value.split('~')[2];
        if (strCurrent == strCurrent.toUpperCase() && selectViewKR.children[i].style.color != 'red') {
            selectViewKR.children[i].style = 'color:magenta';
        }
    }
}

window.addEventListener("message", receiveMessage, false);
if (debugKR)
    CallKRSolver();
// CNN KR SOLVER END

and then between // King's Reward Function - Start and // King's Reward Function - End with

// ################################################################################################
//   King's Reward Function - Start
// ################################################################################################

function kingRewardAction() {
if (debug) console.log("RUN %ckingRewardAction()", "color: #bada55");

    // update timer
    displayTimer("King's Reward!", "King's Reward", "King's Reward!");
    displayLocation("-");

    // play music if needed
    playKingRewardSound();

    window.setTimeout(function () {
        // Autopop KR if needed
        if (autoPopupKR) {
            alert("King's Reward NOW");
        }

        // email the captcha away if needed
        emailCaptcha();
    }, 2000);

    // focus on the answer input
    var inputKingsReward = document.getElementsByClassName('puzzleView__code')[0];
    inputKingsReward.focus();

    // record last king's reward time
    var nowDate = new Date();
    setStorage("lastKingRewardDate", nowDate.toString());

    if (!isAutoSolve)
        return;

    if (debug) console.log("START AUTOSOLVE COUNTDOWN");

    var krDelaySec = krDelayMin + Math.floor(Math.random() * (krDelayMax - krDelayMin));
    var krStopHourNormalized = krStopHour;
    var krStartHourNormalized = krStartHour;
    if (krStopHour > krStartHour) { // e.g. Stop to Start => 22 to 06
        var offset = 24 - krStopHour;
        krStartHourNormalized = krStartHour + offset;
        krStopHourNormalized = 0;
        nowDate.setHours(nowDate.getHours() + offset);
    }

    if (nowDate.getHours() >= krStopHourNormalized && nowDate.getHours() < krStartHourNormalized) {
        var krDelayMinute = krStartHourDelayMin + Math.floor(Math.random() * (krStartHourDelayMax - krStartHourDelayMin));
        krDelaySec += krStartHour * 3600 - (nowDate.getHours() * 3600 + nowDate.getMinutes() * 60 + nowDate.getSeconds());
        krDelaySec += krDelayMinute * 60;
        var timeNow = new Date();
        setStorage("Time to start delay", timeNow.toString());
        setStorage("Delay time", timeFormat(krDelaySec))
        kingRewardCountdownTimer(krDelaySec, true);
    } else {
        if (kingsRewardRetry > kingsRewardRetryMax)
            krDelaySec /= (kingsRewardRetry * 2);
        kingRewardCountdownTimer(krDelaySec, false);
    }
}

function emailCaptcha() {
if (kingRewardEmail != null && kingRewardEmail != undefined && kingRewardEmail != "") {
        if (debug) console.log('Attempting to email captcha via Parse now.');
        var un = getPageVariable('user.username');
        if (un == undefined) un = "";

        Parse.initialize("mh-autobot", "unused");
        Parse.serverURL = 'https://mh-autobot.herokuapp.com/parse';

        Parse.Cloud.run('sendKRemail', {
            theEmail: kingRewardEmail,
            user: un
        }, {
            success: function (data) {
                if (debug) console.log(data);
            }, error: function (error) {
                if (debug) console.log(error);
            }
        });
    }
}

function notifyMe(notice, icon, body) {
if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    } else if (Notification.permission === "granted") {
        var notification = new Notification(notice, {'icon': icon, 'body': body});

        notification.onclick = function () {
            window.open("https://www.mousehuntgame.com/");
            notification.close();
        }

        notification.onshow = function () {
            setTimeout(function () {
                notification.close();
            }, 5000);
        }
    } else if (Notification.permission !== 'denied') {
        Notification.requestPermission(function (permission) {
            // Whatever the user answers, we make sure we store the information
            if (!('permission' in Notification)) {
                Notification.permission = permission;
            }

            // If the user is okay, let's create a notification
            if (permission === "granted") {
                var notification = new Notification(notice, {'icon': icon, 'body': body});

                notification.onclick = function () {
                    window.open("https://www.mousehuntgame.com/");
                    notification.close();
                }

                notification.onshow = function () {
                    setTimeout(function () {
                        notification.close();
                    }, 5000);
                }
            }
        });
    }
}

function playKingRewardSound() {
if (isKingWarningSound) {
        unsafeWindow.hornAudio = new Audio(kingWarningSound);
        unsafeWindow.hornAudio.loop = true;
        unsafeWindow.hornAudio.play();
        var targetArea = document.getElementsByTagName('body');
        var child = document.createElement('button');
        child.setAttribute('id', "stopAudio");
        child.setAttribute('style', 'position: fixed; bottom: 0;');
        child.setAttribute('onclick', 'hornAudio.pause();');
        child.innerHTML = "CLICK ME TO STOP THIS ANNOYING MUSIC";
        targetArea[0].appendChild(child);
        targetArea = null;
        child = null;
        snippet = null;
    }
}

function kingRewardCountdownTimer(interval, isReloadToSolve) {
var strTemp = (isReloadToSolve) ? "Reload to solve KR in " : "Solve KR in (extra few sec delay) ";
    strTemp = strTemp + timeFormat(interval);
    displayTimer(strTemp, strTemp, strTemp);
    strTemp = null;
    interval -= timerRefreshInterval;
    if (interval < 0) {
        if (debug) console.log("START AUTOSOLVE NOW");

        if (isReloadToSolve) {
            if (debug) console.log("Reloading to solve KR, clicking on campElement now");

            // simulate mouse click on the camp button
            var campElement = document.getElementsByClassName(campButton)[0];
            fireEvent(campElement, 'click');
            campElement = null;

            // reload the page if click on the camp button fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on camp button. Reloading...", false);
            }, 5000);
        } else {
            var intervalCRB = setInterval(
                function () {
                    if (checkResumeButton()) {
                        clearInterval(intervalCRB);
                        intervalCRB = null;
                        return;
                    }
                }, 1000);
            CallKRSolver();
        }
    } else {
        if (!checkResumeButton()) {
            window.setTimeout(function () {
                kingRewardCountdownTimer(interval, isReloadToSolve);
            }, timerRefreshInterval * 1000);
        }
    }
}

function checkResumeButton() {
var found = false;
    var resumeElement;

    if (isNewUI) {
        var krFormClass = document.getElementsByTagName('form')[0].className;
        if (krFormClass.indexOf("noPuzzle") > -1) {
            // found resume button

            // simulate mouse click on the resume button
            resumeElement = document.getElementsByClassName('puzzleView__resumeButton')[0];
            fireEvent(resumeElement, 'click');
            resumeElement = null;

            // reload url if click fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on resume button. Reloading...", false);
            }, 6000);

            // recheck if the resume button is click because some time even the url reload also fail
            window.setTimeout(function () {
                checkResumeButton();
            }, 10000);

            found = true;
        }
        krFormClass = null;
    } else {
        var linkElementList = document.getElementsByTagName('img');
        if (linkElementList) {
            var i;
            for (i = 0; i < linkElementList.length; ++i) {
                // check if it is a resume button
                if (linkElementList[i].getAttribute('src').indexOf("resume_hunting_blue.gif") != -1) {
                    // found resume button

                    // simulate mouse click on the horn
                    resumeElement = linkElementList[i].parentNode;
                    fireEvent(resumeElement, 'click');
                    resumeElement = null;

                    // reload url if click fail
                    window.setTimeout(function () {
                        reloadWithMessage("Fail to click on resume button. Reloading...", false);
                    }, 6000);

                    // recheck if the resume button is click because some time even the url reload also fail
                    window.setTimeout(function () {
                        checkResumeButton();
                    }, 10000);

                    found = true;
                    break;
                }
            }
            i = null;
        }
    }

    linkElementList = null;

    try {
        return (found);
    } finally {
        found = null;
    }
}

// ################################################################################################
//   King's Reward Function - End
// ################################################################################################

that's all the changes I have made, and it works for me. If it still doesn't work, I might post my whole script as a new script here as the author of this script is not active it seems.

§
Posted: 07-05-2023

I believed you could consider to post the new script instead.

§
Posted: 07-05-2023

I might have missed a few lines of changes I made myself.

From the current version of the script, v1.7, disregard my comments above, and replace everything between // CNN KR SOLVER START and // CNN KR SOLVER END with

// CNN KR SOLVER START
function FinalizePuzzleImageAnswer(answer) {
if (debug) console.log("RUN FinalizePuzzleImageAnswer()");
    if (debug) console.log(answer);

    var myFrame;
    if (answer.length != 5) {
        //Get a new puzzle
        if (kingsRewardRetry >= kingsRewardRetryMax) {
            kingsRewardRetry = 0;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
            alert(strTemp);
            displayTimer(strTemp, strTemp, strTemp);
            console.perror(strTemp);
            return;
        } else {
            ++kingsRewardRetry;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var tagName = document.getElementsByTagName("a");
            for (var i = 0; i < tagName.length; i++) {
                if (tagName[i].innerText == "Click here to get a new one!") {
                    // TODO IMPORTANT: Find another time to fetch new puzzle
                    fireEvent(tagName[i], 'click');
                    myFrame = document.getElementById('myFrame');
                    if (!isNullOrUndefined(myFrame))
                        document.body.removeChild(myFrame);
                    window.setTimeout(function () {
                        CallKRSolver();
                    }, 6000);
                    return;
                }
            }
        }
    } else {
        if (debug) console.log("Submitting captcha answer: " + answer);
        //Submit answer

        //var puzzleAns = document.getElementById("puzzle_answer");
        var puzzleAns = document.getElementsByClassName("puzzleView__code")[0];

        if (!puzzleAns) {
            if (debug) console.plog("puzzleAns: " + puzzleAns);
            return;
        }
        puzzleAns.value = "";
        puzzleAns.value = answer.toLowerCase();

        //var puzzleSubmit = document.getElementById("puzzle_submit");
        var puzzleSubmit = document.getElementsByClassName("puzzleView__solveButton")[0];

        if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
        }

        puzzleSubmit.classList.remove("disabled");

        fireEvent(puzzleSubmit, 'click');
        kingsRewardRetry = 0;
        setStorage("KingsRewardRetry", kingsRewardRetry);
        myFrame = document.getElementById('myFrame');
        if (myFrame)
            document.body.removeChild(myFrame);

        window.setTimeout(function () {
            CheckKRAnswerCorrectness();
        }, 5000);
    }
}

function receiveMessage(event) {
if (debug) console.debug("Event origin: " + event.origin);

    if (!debugKR && !isAutoSolve)
        return;

    if (event.origin.indexOf("mhcdn") > -1 || event.origin.indexOf("mousehuntgame") > -1 || event.origin.indexOf("dropbox") > -1) {
        if (event.data.indexOf("~") > -1) {
            var result = event.data.substring(0, event.data.indexOf("~"));
            if (saveKRImage) {
                var processedImg = event.data.substring(event.data.indexOf("~") + 1, event.data.length);
                var strKR = "KR" + separator;
                strKR += Date.now() + separator;
                strKR += result + separator;
                strKR += "RETRY" + kingsRewardRetry;
                try {
                    setStorage(strKR, processedImg);
                } catch (e) {
                    console.perror('receiveMessage', e.message);
                }
            }
            FinalizePuzzleImageAnswer(result);
        } else if (event.data.indexOf("#") > -1) {
            var value = event.data.substring(1, event.data.length);
            setStorage("krCallBack", value);
        } else if (event.data.indexOf('Log_') > -1)
            console.plog(event.data.split('_')[1]);
        else if (event.data.indexOf('MHAKRS_') > -1) {
            var temp = event.data.split('_');
            console.plog(temp[0], temp[1]);
            setStorage(temp[0], temp[1]);
        }
    }
}

function CallKRSolver() {
if (debug) console.log("RUN CallKRSolver()");

    var frame = document.createElement('iframe');
    frame.setAttribute("id", "myFrame");
    var img;
    if (debugKR) {
        //frame.src = "https://dl.dropboxusercontent.com/s/4u5msso39hfpo87/Capture.PNG";
        //frame.src = "https://dl.dropboxusercontent.com/s/og73bcdsn2qod63/download%20%2810%29Ori.png";
        frame.src = "https://dl.dropboxusercontent.com/s/ppg0l35h25phrx3/download%20(16).png";
    } else {
        //if (isNewUI) {

        img = document.getElementsByClassName('puzzleView__image')[0];
        if (debug) console.log("Captcha Image fetched:")
        if (debug) console.log(img);

        frame.src = img.querySelector('img').src;
        /*} else {
            img = document.getElementById('puzzleImage');
            frame.src = img.src;
        }*/
    }
    document.body.appendChild(frame);
}

function CheckKRAnswerCorrectness() {
var puzzleForm = document.getElementsByClassName("puzzleView")[0];
    if (puzzleForm.classList.contains("puzzleView--state-solved")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

    var strTemp = '';
    var codeError = document.getElementsByClassName("puzzleView__error");
    for (var i = 0; i < codeError.length; i++) {
        if (codeError[i].innerText.toLowerCase().indexOf("incorrect claim code") > -1) {
            if (kingsRewardRetry >= kingsRewardRetryMax) {
                kingsRewardRetry = 0;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
                alert(strTemp);
                displayTimer(strTemp, strTemp, strTemp);
                console.perror(strTemp);
            } else {
                ++kingsRewardRetry;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                CallKRSolver();
            }
            return;
        }
    }

    window.setTimeout(function () {
        CheckKRAnswerCorrectness();
    }, 1000);
}

function resumeKRAfterSolved() {
if (debug) console.log("RUN resumeKRAfterSolved()");

    var resumeButton = document.getElementsByClassName("puzzleView__resumeButton")[0];
    location.reload(true)
}

function addKREntries() {
var i, temp, maxLen, keyName;
    var replaced = "";
    var nTimezoneOffset = -(new Date().getTimezoneOffset()) * 60000;
    var count = 1;
    var strInnerHTML = '';
    var selectViewKR = document.getElementById('viewKR');
    if (selectViewKR.options.length > 0) {
        // append keyKR for new KR entries under new UI
        for (i = 0; i < window.localStorage.length; i++) {
            keyName = window.localStorage.key(i);
            if (keyName.indexOf("KR" + separator) > -1 && keyKR.indexOf(keyName) < 0)
                keyKR.push(keyName);
        }
    }
    maxLen = keyKR.length.toString().length;
    for (i = 0; i < keyKR.length; i++) {
        if (keyKR[i].indexOf("KR" + separator) > -1) {
            temp = keyKR[i].split(separator);
            temp.splice(0, 1);
            temp[0] = parseInt(temp[0]);
            if (Number.isNaN(temp[0]))
                temp[0] = 0;

            temp[0] += nTimezoneOffset;
            temp[0] = (new Date(temp[0])).toISOString();
            replaced = temp.join("&nbsp;&nbsp;");
            temp = count.toString();
            while (temp.length < maxLen) {
                temp = '0' + temp;
            }
            replaced = temp + '. ' + replaced;
            strInnerHTML += '<option value="' + keyKR[i] + '"' + ((i == keyKR.length - 1) ? ' selected' : '') + '>' + replaced + '</option>';
            count++;
        }
    }
    if (strInnerHTML !== '')
        selectViewKR.innerHTML = strInnerHTML;
}

function setKREntriesColor() {
// set KR entries color
    var i, nCurrent, nNext, strCurrent;
    var selectViewKR = document.getElementById('viewKR');
    for (i = 0; i < selectViewKR.children.length; i++) {
        if (i < selectViewKR.children.length - 1) {
            nCurrent = parseInt(selectViewKR.children[i].value.split('~')[1]);
            nNext = parseInt(selectViewKR.children[i + 1].value.split('~')[1]);
            if (Math.round((nNext - nCurrent) / 60000) < 2)
                selectViewKR.children[i].style = 'color:red';
        }
        strCurrent = selectViewKR.children[i].value.split('~')[2];
        if (strCurrent == strCurrent.toUpperCase() && selectViewKR.children[i].style.color != 'red') {
            selectViewKR.children[i].style = 'color:magenta';
        }
    }
}

window.addEventListener("message", receiveMessage, false);
if (debugKR)
    CallKRSolver();
// CNN KR SOLVER END

and then between // King's Reward Function - Start and // King's Reward Function - End with

// ################################################################################################
//   King's Reward Function - Start
// ################################################################################################

function kingRewardAction() {
if (debug) console.log("RUN %ckingRewardAction()", "color: #bada55");

    // update timer
    displayTimer("King's Reward!", "King's Reward", "King's Reward!");
    displayLocation("-");

    // play music if needed
    playKingRewardSound();

    window.setTimeout(function () {
        // Autopop KR if needed
        if (autoPopupKR) {
            alert("King's Reward NOW");
        }

        // email the captcha away if needed
        emailCaptcha();
    }, 2000);

    // focus on the answer input
    var inputKingsReward = document.getElementsByClassName('puzzleView__code')[0];
    inputKingsReward.focus();

    // record last king's reward time
    var nowDate = new Date();
    setStorage("lastKingRewardDate", nowDate.toString());

    if (!isAutoSolve)
        return;

    if (debug) console.log("START AUTOSOLVE COUNTDOWN");

    var krDelaySec = krDelayMin + Math.floor(Math.random() * (krDelayMax - krDelayMin));
    var krStopHourNormalized = krStopHour;
    var krStartHourNormalized = krStartHour;
    if (krStopHour > krStartHour) { // e.g. Stop to Start => 22 to 06
        var offset = 24 - krStopHour;
        krStartHourNormalized = krStartHour + offset;
        krStopHourNormalized = 0;
        nowDate.setHours(nowDate.getHours() + offset);
    }

    if (nowDate.getHours() >= krStopHourNormalized && nowDate.getHours() < krStartHourNormalized) {
        var krDelayMinute = krStartHourDelayMin + Math.floor(Math.random() * (krStartHourDelayMax - krStartHourDelayMin));
        krDelaySec += krStartHour * 3600 - (nowDate.getHours() * 3600 + nowDate.getMinutes() * 60 + nowDate.getSeconds());
        krDelaySec += krDelayMinute * 60;
        var timeNow = new Date();
        setStorage("Time to start delay", timeNow.toString());
        setStorage("Delay time", timeFormat(krDelaySec))
        kingRewardCountdownTimer(krDelaySec, true);
    } else {
        if (kingsRewardRetry > kingsRewardRetryMax)
            krDelaySec /= (kingsRewardRetry * 2);
        kingRewardCountdownTimer(krDelaySec, false);
    }
}

function emailCaptcha() {
if (kingRewardEmail != null && kingRewardEmail != undefined && kingRewardEmail != "") {
        if (debug) console.log('Attempting to email captcha via Parse now.');
        var un = getPageVariable('user.username');
        if (un == undefined) un = "";

        Parse.initialize("mh-autobot", "unused");
        Parse.serverURL = 'https://mh-autobot.herokuapp.com/parse';

        Parse.Cloud.run('sendKRemail', {
            theEmail: kingRewardEmail,
            user: un
        }, {
            success: function (data) {
                if (debug) console.log(data);
            }, error: function (error) {
                if (debug) console.log(error);
            }
        });
    }
}

function notifyMe(notice, icon, body) {
if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    } else if (Notification.permission === "granted") {
        var notification = new Notification(notice, {'icon': icon, 'body': body});

        notification.onclick = function () {
            window.open("https://www.mousehuntgame.com/");
            notification.close();
        }

        notification.onshow = function () {
            setTimeout(function () {
                notification.close();
            }, 5000);
        }
    } else if (Notification.permission !== 'denied') {
        Notification.requestPermission(function (permission) {
            // Whatever the user answers, we make sure we store the information
            if (!('permission' in Notification)) {
                Notification.permission = permission;
            }

            // If the user is okay, let's create a notification
            if (permission === "granted") {
                var notification = new Notification(notice, {'icon': icon, 'body': body});

                notification.onclick = function () {
                    window.open("https://www.mousehuntgame.com/");
                    notification.close();
                }

                notification.onshow = function () {
                    setTimeout(function () {
                        notification.close();
                    }, 5000);
                }
            }
        });
    }
}

function playKingRewardSound() {
if (isKingWarningSound) {
        unsafeWindow.hornAudio = new Audio(kingWarningSound);
        unsafeWindow.hornAudio.loop = true;
        unsafeWindow.hornAudio.play();
        var targetArea = document.getElementsByTagName('body');
        var child = document.createElement('button');
        child.setAttribute('id', "stopAudio");
        child.setAttribute('style', 'position: fixed; bottom: 0;');
        child.setAttribute('onclick', 'hornAudio.pause();');
        child.innerHTML = "CLICK ME TO STOP THIS ANNOYING MUSIC";
        targetArea[0].appendChild(child);
        targetArea = null;
        child = null;
        snippet = null;
    }
}

function kingRewardCountdownTimer(interval, isReloadToSolve) {
var strTemp = (isReloadToSolve) ? "Reload to solve KR in " : "Solve KR in (extra few sec delay) ";
    strTemp = strTemp + timeFormat(interval);
    displayTimer(strTemp, strTemp, strTemp);
    strTemp = null;
    interval -= timerRefreshInterval;
    if (interval < 0) {
        if (debug) console.log("START AUTOSOLVE NOW");

        if (isReloadToSolve) {
            if (debug) console.log("Reloading to solve KR, clicking on campElement now");

            // simulate mouse click on the camp button
            var campElement = document.getElementsByClassName(campButton)[0];
            fireEvent(campElement, 'click');
            campElement = null;

            // reload the page if click on the camp button fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on camp button. Reloading...", false);
            }, 5000);
        } else {
            var intervalCRB = setInterval(
                function () {
                    if (checkResumeButton()) {
                        clearInterval(intervalCRB);
                        intervalCRB = null;
                        return;
                    }
                }, 1000);
            CallKRSolver();
        }
    } else {
        if (!checkResumeButton()) {
            window.setTimeout(function () {
                kingRewardCountdownTimer(interval, isReloadToSolve);
            }, timerRefreshInterval * 1000);
        }
    }
}

function checkResumeButton() {
var found = false;
    var resumeElement;

    if (isNewUI) {
        var krFormClass = document.getElementsByTagName('form')[0].className;
        if (krFormClass.indexOf("noPuzzle") > -1) {
            // found resume button

            // simulate mouse click on the resume button
            resumeElement = document.getElementsByClassName('puzzleView__resumeButton')[0];
            fireEvent(resumeElement, 'click');
            resumeElement = null;

            // reload url if click fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on resume button. Reloading...", false);
            }, 6000);

            // recheck if the resume button is click because some time even the url reload also fail
            window.setTimeout(function () {
                checkResumeButton();
            }, 10000);

            found = true;
        }
        krFormClass = null;
    } else {
        var linkElementList = document.getElementsByTagName('img');
        if (linkElementList) {
            var i;
            for (i = 0; i < linkElementList.length; ++i) {
                // check if it is a resume button
                if (linkElementList[i].getAttribute('src').indexOf("resume_hunting_blue.gif") != -1) {
                    // found resume button

                    // simulate mouse click on the horn
                    resumeElement = linkElementList[i].parentNode;
                    fireEvent(resumeElement, 'click');
                    resumeElement = null;

                    // reload url if click fail
                    window.setTimeout(function () {
                        reloadWithMessage("Fail to click on resume button. Reloading...", false);
                    }, 6000);

                    // recheck if the resume button is click because some time even the url reload also fail
                    window.setTimeout(function () {
                        checkResumeButton();
                    }, 10000);

                    found = true;
                    break;
                }
            }
            i = null;
        }
    }

    linkElementList = null;

    try {
        return (found);
    } finally {
        found = null;
    }
}

// ################################################################################################
//   King's Reward Function - End
// ################################################################################################

that's all the changes I have made, and it works for me. If it still doesn't work, I might post my whole script as a new script here as the author of this script is not active it seems.

works! thank you good Sir!

§
Posted: 07-05-2023

I might have missed a few lines of changes I made myself.

From the current version of the script, v1.7, disregard my comments above, and replace everything between // CNN KR SOLVER START and // CNN KR SOLVER END with

// CNN KR SOLVER START
function FinalizePuzzleImageAnswer(answer) {
if (debug) console.log("RUN FinalizePuzzleImageAnswer()");
    if (debug) console.log(answer);

    var myFrame;
    if (answer.length != 5) {
        //Get a new puzzle
        if (kingsRewardRetry >= kingsRewardRetryMax) {
            kingsRewardRetry = 0;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
            alert(strTemp);
            displayTimer(strTemp, strTemp, strTemp);
            console.perror(strTemp);
            return;
        } else {
            ++kingsRewardRetry;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var tagName = document.getElementsByTagName("a");
            for (var i = 0; i < tagName.length; i++) {
                if (tagName[i].innerText == "Click here to get a new one!") {
                    // TODO IMPORTANT: Find another time to fetch new puzzle
                    fireEvent(tagName[i], 'click');
                    myFrame = document.getElementById('myFrame');
                    if (!isNullOrUndefined(myFrame))
                        document.body.removeChild(myFrame);
                    window.setTimeout(function () {
                        CallKRSolver();
                    }, 6000);
                    return;
                }
            }
        }
    } else {
        if (debug) console.log("Submitting captcha answer: " + answer);
        //Submit answer

        //var puzzleAns = document.getElementById("puzzle_answer");
        var puzzleAns = document.getElementsByClassName("puzzleView__code")[0];

        if (!puzzleAns) {
            if (debug) console.plog("puzzleAns: " + puzzleAns);
            return;
        }
        puzzleAns.value = "";
        puzzleAns.value = answer.toLowerCase();

        //var puzzleSubmit = document.getElementById("puzzle_submit");
        var puzzleSubmit = document.getElementsByClassName("puzzleView__solveButton")[0];

        if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
        }

        puzzleSubmit.classList.remove("disabled");

        fireEvent(puzzleSubmit, 'click');
        kingsRewardRetry = 0;
        setStorage("KingsRewardRetry", kingsRewardRetry);
        myFrame = document.getElementById('myFrame');
        if (myFrame)
            document.body.removeChild(myFrame);

        window.setTimeout(function () {
            CheckKRAnswerCorrectness();
        }, 5000);
    }
}

function receiveMessage(event) {
if (debug) console.debug("Event origin: " + event.origin);

    if (!debugKR && !isAutoSolve)
        return;

    if (event.origin.indexOf("mhcdn") > -1 || event.origin.indexOf("mousehuntgame") > -1 || event.origin.indexOf("dropbox") > -1) {
        if (event.data.indexOf("~") > -1) {
            var result = event.data.substring(0, event.data.indexOf("~"));
            if (saveKRImage) {
                var processedImg = event.data.substring(event.data.indexOf("~") + 1, event.data.length);
                var strKR = "KR" + separator;
                strKR += Date.now() + separator;
                strKR += result + separator;
                strKR += "RETRY" + kingsRewardRetry;
                try {
                    setStorage(strKR, processedImg);
                } catch (e) {
                    console.perror('receiveMessage', e.message);
                }
            }
            FinalizePuzzleImageAnswer(result);
        } else if (event.data.indexOf("#") > -1) {
            var value = event.data.substring(1, event.data.length);
            setStorage("krCallBack", value);
        } else if (event.data.indexOf('Log_') > -1)
            console.plog(event.data.split('_')[1]);
        else if (event.data.indexOf('MHAKRS_') > -1) {
            var temp = event.data.split('_');
            console.plog(temp[0], temp[1]);
            setStorage(temp[0], temp[1]);
        }
    }
}

function CallKRSolver() {
if (debug) console.log("RUN CallKRSolver()");

    var frame = document.createElement('iframe');
    frame.setAttribute("id", "myFrame");
    var img;
    if (debugKR) {
        //frame.src = "https://dl.dropboxusercontent.com/s/4u5msso39hfpo87/Capture.PNG";
        //frame.src = "https://dl.dropboxusercontent.com/s/og73bcdsn2qod63/download%20%2810%29Ori.png";
        frame.src = "https://dl.dropboxusercontent.com/s/ppg0l35h25phrx3/download%20(16).png";
    } else {
        //if (isNewUI) {

        img = document.getElementsByClassName('puzzleView__image')[0];
        if (debug) console.log("Captcha Image fetched:")
        if (debug) console.log(img);

        frame.src = img.querySelector('img').src;
        /*} else {
            img = document.getElementById('puzzleImage');
            frame.src = img.src;
        }*/
    }
    document.body.appendChild(frame);
}

function CheckKRAnswerCorrectness() {
var puzzleForm = document.getElementsByClassName("puzzleView")[0];
    if (puzzleForm.classList.contains("puzzleView--state-solved")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

    var strTemp = '';
    var codeError = document.getElementsByClassName("puzzleView__error");
    for (var i = 0; i < codeError.length; i++) {
        if (codeError[i].innerText.toLowerCase().indexOf("incorrect claim code") > -1) {
            if (kingsRewardRetry >= kingsRewardRetryMax) {
                kingsRewardRetry = 0;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
                alert(strTemp);
                displayTimer(strTemp, strTemp, strTemp);
                console.perror(strTemp);
            } else {
                ++kingsRewardRetry;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                CallKRSolver();
            }
            return;
        }
    }

    window.setTimeout(function () {
        CheckKRAnswerCorrectness();
    }, 1000);
}

function resumeKRAfterSolved() {
if (debug) console.log("RUN resumeKRAfterSolved()");

    var resumeButton = document.getElementsByClassName("puzzleView__resumeButton")[0];
    location.reload(true)
}

function addKREntries() {
var i, temp, maxLen, keyName;
    var replaced = "";
    var nTimezoneOffset = -(new Date().getTimezoneOffset()) * 60000;
    var count = 1;
    var strInnerHTML = '';
    var selectViewKR = document.getElementById('viewKR');
    if (selectViewKR.options.length > 0) {
        // append keyKR for new KR entries under new UI
        for (i = 0; i < window.localStorage.length; i++) {
            keyName = window.localStorage.key(i);
            if (keyName.indexOf("KR" + separator) > -1 && keyKR.indexOf(keyName) < 0)
                keyKR.push(keyName);
        }
    }
    maxLen = keyKR.length.toString().length;
    for (i = 0; i < keyKR.length; i++) {
        if (keyKR[i].indexOf("KR" + separator) > -1) {
            temp = keyKR[i].split(separator);
            temp.splice(0, 1);
            temp[0] = parseInt(temp[0]);
            if (Number.isNaN(temp[0]))
                temp[0] = 0;

            temp[0] += nTimezoneOffset;
            temp[0] = (new Date(temp[0])).toISOString();
            replaced = temp.join("&nbsp;&nbsp;");
            temp = count.toString();
            while (temp.length < maxLen) {
                temp = '0' + temp;
            }
            replaced = temp + '. ' + replaced;
            strInnerHTML += '<option value="' + keyKR[i] + '"' + ((i == keyKR.length - 1) ? ' selected' : '') + '>' + replaced + '</option>';
            count++;
        }
    }
    if (strInnerHTML !== '')
        selectViewKR.innerHTML = strInnerHTML;
}

function setKREntriesColor() {
// set KR entries color
    var i, nCurrent, nNext, strCurrent;
    var selectViewKR = document.getElementById('viewKR');
    for (i = 0; i < selectViewKR.children.length; i++) {
        if (i < selectViewKR.children.length - 1) {
            nCurrent = parseInt(selectViewKR.children[i].value.split('~')[1]);
            nNext = parseInt(selectViewKR.children[i + 1].value.split('~')[1]);
            if (Math.round((nNext - nCurrent) / 60000) < 2)
                selectViewKR.children[i].style = 'color:red';
        }
        strCurrent = selectViewKR.children[i].value.split('~')[2];
        if (strCurrent == strCurrent.toUpperCase() && selectViewKR.children[i].style.color != 'red') {
            selectViewKR.children[i].style = 'color:magenta';
        }
    }
}

window.addEventListener("message", receiveMessage, false);
if (debugKR)
    CallKRSolver();
// CNN KR SOLVER END

and then between // King's Reward Function - Start and // King's Reward Function - End with

// ################################################################################################
//   King's Reward Function - Start
// ################################################################################################

function kingRewardAction() {
if (debug) console.log("RUN %ckingRewardAction()", "color: #bada55");

    // update timer
    displayTimer("King's Reward!", "King's Reward", "King's Reward!");
    displayLocation("-");

    // play music if needed
    playKingRewardSound();

    window.setTimeout(function () {
        // Autopop KR if needed
        if (autoPopupKR) {
            alert("King's Reward NOW");
        }

        // email the captcha away if needed
        emailCaptcha();
    }, 2000);

    // focus on the answer input
    var inputKingsReward = document.getElementsByClassName('puzzleView__code')[0];
    inputKingsReward.focus();

    // record last king's reward time
    var nowDate = new Date();
    setStorage("lastKingRewardDate", nowDate.toString());

    if (!isAutoSolve)
        return;

    if (debug) console.log("START AUTOSOLVE COUNTDOWN");

    var krDelaySec = krDelayMin + Math.floor(Math.random() * (krDelayMax - krDelayMin));
    var krStopHourNormalized = krStopHour;
    var krStartHourNormalized = krStartHour;
    if (krStopHour > krStartHour) { // e.g. Stop to Start => 22 to 06
        var offset = 24 - krStopHour;
        krStartHourNormalized = krStartHour + offset;
        krStopHourNormalized = 0;
        nowDate.setHours(nowDate.getHours() + offset);
    }

    if (nowDate.getHours() >= krStopHourNormalized && nowDate.getHours() < krStartHourNormalized) {
        var krDelayMinute = krStartHourDelayMin + Math.floor(Math.random() * (krStartHourDelayMax - krStartHourDelayMin));
        krDelaySec += krStartHour * 3600 - (nowDate.getHours() * 3600 + nowDate.getMinutes() * 60 + nowDate.getSeconds());
        krDelaySec += krDelayMinute * 60;
        var timeNow = new Date();
        setStorage("Time to start delay", timeNow.toString());
        setStorage("Delay time", timeFormat(krDelaySec))
        kingRewardCountdownTimer(krDelaySec, true);
    } else {
        if (kingsRewardRetry > kingsRewardRetryMax)
            krDelaySec /= (kingsRewardRetry * 2);
        kingRewardCountdownTimer(krDelaySec, false);
    }
}

function emailCaptcha() {
if (kingRewardEmail != null && kingRewardEmail != undefined && kingRewardEmail != "") {
        if (debug) console.log('Attempting to email captcha via Parse now.');
        var un = getPageVariable('user.username');
        if (un == undefined) un = "";

        Parse.initialize("mh-autobot", "unused");
        Parse.serverURL = 'https://mh-autobot.herokuapp.com/parse';

        Parse.Cloud.run('sendKRemail', {
            theEmail: kingRewardEmail,
            user: un
        }, {
            success: function (data) {
                if (debug) console.log(data);
            }, error: function (error) {
                if (debug) console.log(error);
            }
        });
    }
}

function notifyMe(notice, icon, body) {
if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    } else if (Notification.permission === "granted") {
        var notification = new Notification(notice, {'icon': icon, 'body': body});

        notification.onclick = function () {
            window.open("https://www.mousehuntgame.com/");
            notification.close();
        }

        notification.onshow = function () {
            setTimeout(function () {
                notification.close();
            }, 5000);
        }
    } else if (Notification.permission !== 'denied') {
        Notification.requestPermission(function (permission) {
            // Whatever the user answers, we make sure we store the information
            if (!('permission' in Notification)) {
                Notification.permission = permission;
            }

            // If the user is okay, let's create a notification
            if (permission === "granted") {
                var notification = new Notification(notice, {'icon': icon, 'body': body});

                notification.onclick = function () {
                    window.open("https://www.mousehuntgame.com/");
                    notification.close();
                }

                notification.onshow = function () {
                    setTimeout(function () {
                        notification.close();
                    }, 5000);
                }
            }
        });
    }
}

function playKingRewardSound() {
if (isKingWarningSound) {
        unsafeWindow.hornAudio = new Audio(kingWarningSound);
        unsafeWindow.hornAudio.loop = true;
        unsafeWindow.hornAudio.play();
        var targetArea = document.getElementsByTagName('body');
        var child = document.createElement('button');
        child.setAttribute('id', "stopAudio");
        child.setAttribute('style', 'position: fixed; bottom: 0;');
        child.setAttribute('onclick', 'hornAudio.pause();');
        child.innerHTML = "CLICK ME TO STOP THIS ANNOYING MUSIC";
        targetArea[0].appendChild(child);
        targetArea = null;
        child = null;
        snippet = null;
    }
}

function kingRewardCountdownTimer(interval, isReloadToSolve) {
var strTemp = (isReloadToSolve) ? "Reload to solve KR in " : "Solve KR in (extra few sec delay) ";
    strTemp = strTemp + timeFormat(interval);
    displayTimer(strTemp, strTemp, strTemp);
    strTemp = null;
    interval -= timerRefreshInterval;
    if (interval < 0) {
        if (debug) console.log("START AUTOSOLVE NOW");

        if (isReloadToSolve) {
            if (debug) console.log("Reloading to solve KR, clicking on campElement now");

            // simulate mouse click on the camp button
            var campElement = document.getElementsByClassName(campButton)[0];
            fireEvent(campElement, 'click');
            campElement = null;

            // reload the page if click on the camp button fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on camp button. Reloading...", false);
            }, 5000);
        } else {
            var intervalCRB = setInterval(
                function () {
                    if (checkResumeButton()) {
                        clearInterval(intervalCRB);
                        intervalCRB = null;
                        return;
                    }
                }, 1000);
            CallKRSolver();
        }
    } else {
        if (!checkResumeButton()) {
            window.setTimeout(function () {
                kingRewardCountdownTimer(interval, isReloadToSolve);
            }, timerRefreshInterval * 1000);
        }
    }
}

function checkResumeButton() {
var found = false;
    var resumeElement;

    if (isNewUI) {
        var krFormClass = document.getElementsByTagName('form')[0].className;
        if (krFormClass.indexOf("noPuzzle") > -1) {
            // found resume button

            // simulate mouse click on the resume button
            resumeElement = document.getElementsByClassName('puzzleView__resumeButton')[0];
            fireEvent(resumeElement, 'click');
            resumeElement = null;

            // reload url if click fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on resume button. Reloading...", false);
            }, 6000);

            // recheck if the resume button is click because some time even the url reload also fail
            window.setTimeout(function () {
                checkResumeButton();
            }, 10000);

            found = true;
        }
        krFormClass = null;
    } else {
        var linkElementList = document.getElementsByTagName('img');
        if (linkElementList) {
            var i;
            for (i = 0; i < linkElementList.length; ++i) {
                // check if it is a resume button
                if (linkElementList[i].getAttribute('src').indexOf("resume_hunting_blue.gif") != -1) {
                    // found resume button

                    // simulate mouse click on the horn
                    resumeElement = linkElementList[i].parentNode;
                    fireEvent(resumeElement, 'click');
                    resumeElement = null;

                    // reload url if click fail
                    window.setTimeout(function () {
                        reloadWithMessage("Fail to click on resume button. Reloading...", false);
                    }, 6000);

                    // recheck if the resume button is click because some time even the url reload also fail
                    window.setTimeout(function () {
                        checkResumeButton();
                    }, 10000);

                    found = true;
                    break;
                }
            }
            i = null;
        }
    }

    linkElementList = null;

    try {
        return (found);
    } finally {
        found = null;
    }
}

// ################################################################################################
//   King's Reward Function - End
// ################################################################################################

that's all the changes I have made, and it works for me. If it still doesn't work, I might post my whole script as a new script here as the author of this script is not active it seems.

It works but it doesn't work on incognito mode of browser. Thanks!

§
Posted: 07-05-2023

@Marauding0679, what browser are you using? I'm using Brave.

§
Posted: 07-05-2023

@Marauding0679, what browser are you using? I'm using Brave.

It's not working for me too. Goolge Chrome btw.

§
Posted: 07-05-2023
Edited: 07-05-2023

I'm using Firefox. If it doesn't work, please please please post the console logs. Or else I can't know what the problem is.

§
Posted: 07-05-2023

I'm using Firefox. If it doesn't work, please please please post the console logs. Or else I can't know what the problem is.

Oh, so sorry. Forgot to paste it here. But after I restart the browser, it seems working now for incognito mode.
Anyways, I will observe and if it doesn't work, will surely paste the logs here. Thanks, mate!

§
Posted: 08-05-2023
Edited: 08-05-2023

Am on chrome (not incognito) and am getting the following message in console upon kr solving :/ Can you fix it?

START AUTOSOLVE NOW
userscript.html?name=MouseHunt%2520AutoBot%2520UPDATED.user.js&id=6730acbf-7013-4a4d-9a27-d49b19e86a14:5633 RUN CallKRSolver()
download%20(16).png:1 Error handling response: Error: Failed to read the 'cookie' property from 'Document': The document is sandboxed and lacks the 'allow-same-origin' flag.

§
Posted: 08-05-2023

Am on chrome (not incognito) and am getting the following message in console upon kr solving :/ Can you fix it?START AUTOSOLVE NOWuserscript.html?name=MouseHunt%2520AutoBot%2520UPDATED.user.js&id=6730acbf-7013-4a4d-9a27-d49b19e86a14:5633 RUN CallKRSolver()download%20(16).png:1 Error handling response: Error: Failed to read the 'cookie' property from 'Document': The document is sandboxed and lacks the 'allow-same-origin' flag.

Is it possible for you to post a screenshot of that part? It's hard to read which line is which. I suspect that the error is from other scripts, not this. What's written on the right side of the same row as the error?

§
Posted: 09-05-2023

I might have missed a few lines of changes I made myself.

From the current version of the script, v1.7, disregard my comments above, and replace everything between // CNN KR SOLVER START and // CNN KR SOLVER END with

// CNN KR SOLVER START
function FinalizePuzzleImageAnswer(answer) {
if (debug) console.log("RUN FinalizePuzzleImageAnswer()");
    if (debug) console.log(answer);

    var myFrame;
    if (answer.length != 5) {
        //Get a new puzzle
        if (kingsRewardRetry >= kingsRewardRetryMax) {
            kingsRewardRetry = 0;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
            alert(strTemp);
            displayTimer(strTemp, strTemp, strTemp);
            console.perror(strTemp);
            return;
        } else {
            ++kingsRewardRetry;
            setStorage("KingsRewardRetry", kingsRewardRetry);
            var tagName = document.getElementsByTagName("a");
            for (var i = 0; i < tagName.length; i++) {
                if (tagName[i].innerText == "Click here to get a new one!") {
                    // TODO IMPORTANT: Find another time to fetch new puzzle
                    fireEvent(tagName[i], 'click');
                    myFrame = document.getElementById('myFrame');
                    if (!isNullOrUndefined(myFrame))
                        document.body.removeChild(myFrame);
                    window.setTimeout(function () {
                        CallKRSolver();
                    }, 6000);
                    return;
                }
            }
        }
    } else {
        if (debug) console.log("Submitting captcha answer: " + answer);
        //Submit answer

        //var puzzleAns = document.getElementById("puzzle_answer");
        var puzzleAns = document.getElementsByClassName("puzzleView__code")[0];

        if (!puzzleAns) {
            if (debug) console.plog("puzzleAns: " + puzzleAns);
            return;
        }
        puzzleAns.value = "";
        puzzleAns.value = answer.toLowerCase();

        //var puzzleSubmit = document.getElementById("puzzle_submit");
        var puzzleSubmit = document.getElementsByClassName("puzzleView__solveButton")[0];

        if (!puzzleSubmit) {
            if (debug) console.plog("puzzleSubmit: " + puzzleSubmit);
            return;
        }

        puzzleSubmit.classList.remove("disabled");

        fireEvent(puzzleSubmit, 'click');
        kingsRewardRetry = 0;
        setStorage("KingsRewardRetry", kingsRewardRetry);
        myFrame = document.getElementById('myFrame');
        if (myFrame)
            document.body.removeChild(myFrame);

        window.setTimeout(function () {
            CheckKRAnswerCorrectness();
        }, 5000);
    }
}

function receiveMessage(event) {
if (debug) console.debug("Event origin: " + event.origin);

    if (!debugKR && !isAutoSolve)
        return;

    if (event.origin.indexOf("mhcdn") > -1 || event.origin.indexOf("mousehuntgame") > -1 || event.origin.indexOf("dropbox") > -1) {
        if (event.data.indexOf("~") > -1) {
            var result = event.data.substring(0, event.data.indexOf("~"));
            if (saveKRImage) {
                var processedImg = event.data.substring(event.data.indexOf("~") + 1, event.data.length);
                var strKR = "KR" + separator;
                strKR += Date.now() + separator;
                strKR += result + separator;
                strKR += "RETRY" + kingsRewardRetry;
                try {
                    setStorage(strKR, processedImg);
                } catch (e) {
                    console.perror('receiveMessage', e.message);
                }
            }
            FinalizePuzzleImageAnswer(result);
        } else if (event.data.indexOf("#") > -1) {
            var value = event.data.substring(1, event.data.length);
            setStorage("krCallBack", value);
        } else if (event.data.indexOf('Log_') > -1)
            console.plog(event.data.split('_')[1]);
        else if (event.data.indexOf('MHAKRS_') > -1) {
            var temp = event.data.split('_');
            console.plog(temp[0], temp[1]);
            setStorage(temp[0], temp[1]);
        }
    }
}

function CallKRSolver() {
if (debug) console.log("RUN CallKRSolver()");

    var frame = document.createElement('iframe');
    frame.setAttribute("id", "myFrame");
    var img;
    if (debugKR) {
        //frame.src = "https://dl.dropboxusercontent.com/s/4u5msso39hfpo87/Capture.PNG";
        //frame.src = "https://dl.dropboxusercontent.com/s/og73bcdsn2qod63/download%20%2810%29Ori.png";
        frame.src = "https://dl.dropboxusercontent.com/s/ppg0l35h25phrx3/download%20(16).png";
    } else {
        //if (isNewUI) {

        img = document.getElementsByClassName('puzzleView__image')[0];
        if (debug) console.log("Captcha Image fetched:")
        if (debug) console.log(img);

        frame.src = img.querySelector('img').src;
        /*} else {
            img = document.getElementById('puzzleImage');
            frame.src = img.src;
        }*/
    }
    document.body.appendChild(frame);
}

function CheckKRAnswerCorrectness() {
var puzzleForm = document.getElementsByClassName("puzzleView")[0];
    if (puzzleForm.classList.contains("puzzleView--state-solved")) {
        // KR is solved clicking continue now
        location.reload(true)
        resumeKRAfterSolved();
        return;
    }

    var strTemp = '';
    var codeError = document.getElementsByClassName("puzzleView__error");
    for (var i = 0; i < codeError.length; i++) {
        if (codeError[i].innerText.toLowerCase().indexOf("incorrect claim code") > -1) {
            if (kingsRewardRetry >= kingsRewardRetryMax) {
                kingsRewardRetry = 0;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                strTemp = 'Max ' + kingsRewardRetryMax + 'retries. Pls solve it manually ASAP.';
                alert(strTemp);
                displayTimer(strTemp, strTemp, strTemp);
                console.perror(strTemp);
            } else {
                ++kingsRewardRetry;
                setStorage("KingsRewardRetry", kingsRewardRetry);
                CallKRSolver();
            }
            return;
        }
    }

    window.setTimeout(function () {
        CheckKRAnswerCorrectness();
    }, 1000);
}

function resumeKRAfterSolved() {
if (debug) console.log("RUN resumeKRAfterSolved()");

    var resumeButton = document.getElementsByClassName("puzzleView__resumeButton")[0];
    location.reload(true)
}

function addKREntries() {
var i, temp, maxLen, keyName;
    var replaced = "";
    var nTimezoneOffset = -(new Date().getTimezoneOffset()) * 60000;
    var count = 1;
    var strInnerHTML = '';
    var selectViewKR = document.getElementById('viewKR');
    if (selectViewKR.options.length > 0) {
        // append keyKR for new KR entries under new UI
        for (i = 0; i < window.localStorage.length; i++) {
            keyName = window.localStorage.key(i);
            if (keyName.indexOf("KR" + separator) > -1 && keyKR.indexOf(keyName) < 0)
                keyKR.push(keyName);
        }
    }
    maxLen = keyKR.length.toString().length;
    for (i = 0; i < keyKR.length; i++) {
        if (keyKR[i].indexOf("KR" + separator) > -1) {
            temp = keyKR[i].split(separator);
            temp.splice(0, 1);
            temp[0] = parseInt(temp[0]);
            if (Number.isNaN(temp[0]))
                temp[0] = 0;

            temp[0] += nTimezoneOffset;
            temp[0] = (new Date(temp[0])).toISOString();
            replaced = temp.join("&nbsp;&nbsp;");
            temp = count.toString();
            while (temp.length < maxLen) {
                temp = '0' + temp;
            }
            replaced = temp + '. ' + replaced;
            strInnerHTML += '<option value="' + keyKR[i] + '"' + ((i == keyKR.length - 1) ? ' selected' : '') + '>' + replaced + '</option>';
            count++;
        }
    }
    if (strInnerHTML !== '')
        selectViewKR.innerHTML = strInnerHTML;
}

function setKREntriesColor() {
// set KR entries color
    var i, nCurrent, nNext, strCurrent;
    var selectViewKR = document.getElementById('viewKR');
    for (i = 0; i < selectViewKR.children.length; i++) {
        if (i < selectViewKR.children.length - 1) {
            nCurrent = parseInt(selectViewKR.children[i].value.split('~')[1]);
            nNext = parseInt(selectViewKR.children[i + 1].value.split('~')[1]);
            if (Math.round((nNext - nCurrent) / 60000) < 2)
                selectViewKR.children[i].style = 'color:red';
        }
        strCurrent = selectViewKR.children[i].value.split('~')[2];
        if (strCurrent == strCurrent.toUpperCase() && selectViewKR.children[i].style.color != 'red') {
            selectViewKR.children[i].style = 'color:magenta';
        }
    }
}

window.addEventListener("message", receiveMessage, false);
if (debugKR)
    CallKRSolver();
// CNN KR SOLVER END

and then between // King's Reward Function - Start and // King's Reward Function - End with

// ################################################################################################
//   King's Reward Function - Start
// ################################################################################################

function kingRewardAction() {
if (debug) console.log("RUN %ckingRewardAction()", "color: #bada55");

    // update timer
    displayTimer("King's Reward!", "King's Reward", "King's Reward!");
    displayLocation("-");

    // play music if needed
    playKingRewardSound();

    window.setTimeout(function () {
        // Autopop KR if needed
        if (autoPopupKR) {
            alert("King's Reward NOW");
        }

        // email the captcha away if needed
        emailCaptcha();
    }, 2000);

    // focus on the answer input
    var inputKingsReward = document.getElementsByClassName('puzzleView__code')[0];
    inputKingsReward.focus();

    // record last king's reward time
    var nowDate = new Date();
    setStorage("lastKingRewardDate", nowDate.toString());

    if (!isAutoSolve)
        return;

    if (debug) console.log("START AUTOSOLVE COUNTDOWN");

    var krDelaySec = krDelayMin + Math.floor(Math.random() * (krDelayMax - krDelayMin));
    var krStopHourNormalized = krStopHour;
    var krStartHourNormalized = krStartHour;
    if (krStopHour > krStartHour) { // e.g. Stop to Start => 22 to 06
        var offset = 24 - krStopHour;
        krStartHourNormalized = krStartHour + offset;
        krStopHourNormalized = 0;
        nowDate.setHours(nowDate.getHours() + offset);
    }

    if (nowDate.getHours() >= krStopHourNormalized && nowDate.getHours() < krStartHourNormalized) {
        var krDelayMinute = krStartHourDelayMin + Math.floor(Math.random() * (krStartHourDelayMax - krStartHourDelayMin));
        krDelaySec += krStartHour * 3600 - (nowDate.getHours() * 3600 + nowDate.getMinutes() * 60 + nowDate.getSeconds());
        krDelaySec += krDelayMinute * 60;
        var timeNow = new Date();
        setStorage("Time to start delay", timeNow.toString());
        setStorage("Delay time", timeFormat(krDelaySec))
        kingRewardCountdownTimer(krDelaySec, true);
    } else {
        if (kingsRewardRetry > kingsRewardRetryMax)
            krDelaySec /= (kingsRewardRetry * 2);
        kingRewardCountdownTimer(krDelaySec, false);
    }
}

function emailCaptcha() {
if (kingRewardEmail != null && kingRewardEmail != undefined && kingRewardEmail != "") {
        if (debug) console.log('Attempting to email captcha via Parse now.');
        var un = getPageVariable('user.username');
        if (un == undefined) un = "";

        Parse.initialize("mh-autobot", "unused");
        Parse.serverURL = 'https://mh-autobot.herokuapp.com/parse';

        Parse.Cloud.run('sendKRemail', {
            theEmail: kingRewardEmail,
            user: un
        }, {
            success: function (data) {
                if (debug) console.log(data);
            }, error: function (error) {
                if (debug) console.log(error);
            }
        });
    }
}

function notifyMe(notice, icon, body) {
if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
    } else if (Notification.permission === "granted") {
        var notification = new Notification(notice, {'icon': icon, 'body': body});

        notification.onclick = function () {
            window.open("https://www.mousehuntgame.com/");
            notification.close();
        }

        notification.onshow = function () {
            setTimeout(function () {
                notification.close();
            }, 5000);
        }
    } else if (Notification.permission !== 'denied') {
        Notification.requestPermission(function (permission) {
            // Whatever the user answers, we make sure we store the information
            if (!('permission' in Notification)) {
                Notification.permission = permission;
            }

            // If the user is okay, let's create a notification
            if (permission === "granted") {
                var notification = new Notification(notice, {'icon': icon, 'body': body});

                notification.onclick = function () {
                    window.open("https://www.mousehuntgame.com/");
                    notification.close();
                }

                notification.onshow = function () {
                    setTimeout(function () {
                        notification.close();
                    }, 5000);
                }
            }
        });
    }
}

function playKingRewardSound() {
if (isKingWarningSound) {
        unsafeWindow.hornAudio = new Audio(kingWarningSound);
        unsafeWindow.hornAudio.loop = true;
        unsafeWindow.hornAudio.play();
        var targetArea = document.getElementsByTagName('body');
        var child = document.createElement('button');
        child.setAttribute('id', "stopAudio");
        child.setAttribute('style', 'position: fixed; bottom: 0;');
        child.setAttribute('onclick', 'hornAudio.pause();');
        child.innerHTML = "CLICK ME TO STOP THIS ANNOYING MUSIC";
        targetArea[0].appendChild(child);
        targetArea = null;
        child = null;
        snippet = null;
    }
}

function kingRewardCountdownTimer(interval, isReloadToSolve) {
var strTemp = (isReloadToSolve) ? "Reload to solve KR in " : "Solve KR in (extra few sec delay) ";
    strTemp = strTemp + timeFormat(interval);
    displayTimer(strTemp, strTemp, strTemp);
    strTemp = null;
    interval -= timerRefreshInterval;
    if (interval < 0) {
        if (debug) console.log("START AUTOSOLVE NOW");

        if (isReloadToSolve) {
            if (debug) console.log("Reloading to solve KR, clicking on campElement now");

            // simulate mouse click on the camp button
            var campElement = document.getElementsByClassName(campButton)[0];
            fireEvent(campElement, 'click');
            campElement = null;

            // reload the page if click on the camp button fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on camp button. Reloading...", false);
            }, 5000);
        } else {
            var intervalCRB = setInterval(
                function () {
                    if (checkResumeButton()) {
                        clearInterval(intervalCRB);
                        intervalCRB = null;
                        return;
                    }
                }, 1000);
            CallKRSolver();
        }
    } else {
        if (!checkResumeButton()) {
            window.setTimeout(function () {
                kingRewardCountdownTimer(interval, isReloadToSolve);
            }, timerRefreshInterval * 1000);
        }
    }
}

function checkResumeButton() {
var found = false;
    var resumeElement;

    if (isNewUI) {
        var krFormClass = document.getElementsByTagName('form')[0].className;
        if (krFormClass.indexOf("noPuzzle") > -1) {
            // found resume button

            // simulate mouse click on the resume button
            resumeElement = document.getElementsByClassName('puzzleView__resumeButton')[0];
            fireEvent(resumeElement, 'click');
            resumeElement = null;

            // reload url if click fail
            window.setTimeout(function () {
                reloadWithMessage("Fail to click on resume button. Reloading...", false);
            }, 6000);

            // recheck if the resume button is click because some time even the url reload also fail
            window.setTimeout(function () {
                checkResumeButton();
            }, 10000);

            found = true;
        }
        krFormClass = null;
    } else {
        var linkElementList = document.getElementsByTagName('img');
        if (linkElementList) {
            var i;
            for (i = 0; i < linkElementList.length; ++i) {
                // check if it is a resume button
                if (linkElementList[i].getAttribute('src').indexOf("resume_hunting_blue.gif") != -1) {
                    // found resume button

                    // simulate mouse click on the horn
                    resumeElement = linkElementList[i].parentNode;
                    fireEvent(resumeElement, 'click');
                    resumeElement = null;

                    // reload url if click fail
                    window.setTimeout(function () {
                        reloadWithMessage("Fail to click on resume button. Reloading...", false);
                    }, 6000);

                    // recheck if the resume button is click because some time even the url reload also fail
                    window.setTimeout(function () {
                        checkResumeButton();
                    }, 10000);

                    found = true;
                    break;
                }
            }
            i = null;
        }
    }

    linkElementList = null;

    try {
        return (found);
    } finally {
        found = null;
    }
}

// ################################################################################################
//   King's Reward Function - End
// ################################################################################################

that's all the changes I have made, and it works for me. If it still doesn't work, I might post my whole script as a new script here as the author of this script is not active it seems.

This has worked for me on Google Chrome, did not try on incognito. Thank you for the amazing work. Wonder if you have more scripts up your sleeves!

nevocaineمؤلف
§
Posted: 09-05-2023

@Marauding0679: Would you be up to post the script yourself? I can update it, though if you'd be keen, I would love to have you join as a co-author of the script so that you can have edit and posting permissions as well. I have become less active on MH due to IRL commitments, and it would be nice to have someone else help to carry on the updating of the bot (especially seeing as you are certainly more adept at coding than me, hahaha)

§
Posted: 09-05-2023

@Marauding0679 here's an error that I've encountered during KR:

erscript.html?name=MouseHunt%2520AutoBot%2520UPDATED.user.js&id=aa8714b1-fd62-44f4-a8eb-f497cd61bc43:5519 Before exeScript Cannot read properties of undefined (reading 'id')
console.perror @ userscript.html?name=MouseHunt%2520AutoBot%2520UPDATED.user.js&id=aa8714b1-fd62-44f4-a8eb-f497cd61bc43:5519

§
Posted: 09-05-2023

@nevocaine It would be cool if you add me as a co-author. I'm actually not that good at JavaScript, but I do what I can.

§
Posted: 09-05-2023

@blindmustbe I can recreate that on Chromium, but it doesn't interfere with the script for me. Everything including KR solving works despite the error. Is it also like that for you? If it doesn't interfere with other stuff and KR solving still works, I probably won't fix that.

§
Posted: 09-05-2023

Hi, everyone the script is working for you all? I've installed the 2.0 yet it cant solve the KR. Tried in Chrome, Fox and Edge.

§
Posted: 10-05-2023

I have tested on Firefox and Chromium, works on both with Tampermonkey. Post a screenshot of console log to see what's wrong with your setup.

§
Posted: 11-05-2023

WARNIIIIIIINNGG!!!


The devs are now banning users!! Please use it cautiously.

§
Posted: 13-05-2023

WARNIIIIIIINNGG!!!


The devs are now banning users!! Please use it cautiously.

any source on this?

§
Posted: 25-05-2023

Hi, everyone the script is working for you all? I've installed the 2.0 yet it cant solve the KR. Tried in Chrome, Fox and Edge.

me too, but when I switch to "new navigation button style" in game settings, everythings run smoothly.

@Marauding0679 can you make the script to run on old navigation button style?

§
Posted: 31-05-2023

@rampfox unfortunately I won't be making it run on old UI because I'm not using it. What is the reason that you need old UI?

Post reply

تسجيل الدخول إلى مرحلة ما بعد الرد.