adubov1 / khanacademy_bot

An answer revealer userscript for Khan Academy
GNU General Public License v3.0
107 stars 40 forks source link

The script is starting but the answers arent showing #17

Open ludotavio opened 1 year ago

ludotavio commented 1 year ago

Instead of showing the answers, it shows two error messages (corresponding to the answers):

Uncaught (in promise) DOMException: The user aborted a request.

can anyone help me?

tykind commented 1 year ago

One of my friends wanted me to look at it; it seemed like a promise error. Pretty scuffed.

But here is a quick fix, just replace the window.fetch with the one below. (Tested in tamper monkey, chrome)

window.fetch = function() {
    return originalFetch.apply(this, arguments).then(async (res) => {
        if (res.url.includes("/getAssessmentItem")) {
            const clone = res.clone();
            const json = await clone.json()

            let item, question;

            try {
                item = json.data.assessmentItem.item.itemData;
                question = JSON.parse(item).question;
            } catch {
                let errorIteration = () => {
                    return localStorage.getItem("error_iter") || 0;
                }
                localStorage.setItem("error_iter", errorIteration() + 1);

                if (errorIteration() < 4) {
                    return location.reload();
                } else {
                    return console.log("%c An error occurred", "color: red; font-weight: bolder; font-size: 20px;");
                }
            }

            if (!question) return;

            Object.keys(question.widgets).map(widgetName => {
                switch (widgetName.split(" ")[0]) {
                    case "numeric-input":
                        return freeResponseAnswerFrom(question).log();
                    case "radio":
                        return multipleChoiceAnswerFrom(question).log();
                    case "expression":
                        return expressionAnswerFrom(question).log();
                    case "dropdown":
                        return dropdownAnswerFrom(question).log();
                }
            });
        }

        if (!window.loaded) {
            console.clear();
            console.log("%c Answer Revealer ", "color: mediumvioletred; -webkit-text-stroke: .5px black; font-size:40px; font-weight:bolder; padding: .2rem;");
            console.log("%cCreated by Alex Dubov (@adubov1)", "color: white; -webkit-text-stroke: .5px black; font-size:15px; font-weight:bold;");
            window.loaded = true;
        }

        return res;
    })
}
Hedikamals360 commented 1 year ago

auzt1e

I tried this I replaced the window.fetch but it still doesnt work. Maybe its because I use tamper monkey but idk

Kingsab15 commented 1 year ago

Doesn't work