KhanHack

Khan Academy Answer Hack

< Feedback on KhanHack

مراجعة: Good - script works

Deleted user 1336565
§
Posted: 19-07-2024

i fixed the code. it may have a bit of bugs but when you are on a question it should answer it. here it is:// ==UserScript==
// @name KhanHack
// @version 3.9
// @description Here is a Khan Academy Solver!
// @author Logzilla6
// @match https://www.khanacademy.org/*
// @grant none
// @namespace https://greasyfork.org/users/783447
// @downloadURL https://update.greasyfork.org/scripts/427964/KhanHack.user.js
// @updateURL https://update.greasyfork.org/scripts/427964/KhanHack.meta.js
// ==/UserScript==

(function () {
const overlayHTML = `


Toggle

KhanHack

Reset Answer List

-Answers-

 
 
M also toggles Menu

`;

function get(x) {
return document.getElementById(x);
}

const overlay = document.createElement("div");
overlay.innerHTML = overlayHTML;
document.body.appendChild(overlay);

const acc = get("accordian");

acc.onclick = function () {
const panel = get("box2");
if (panel.style.display === "grid") {
panel.style.display = "none";
} else {
panel.style.display = "grid";
}
};

document.addEventListener('keydown', (event) => {
if (event.key === 'm') {
const panel = get("box2");
if (panel.style.display === "grid") {
panel.style.display = "none";
} else {
panel.style.display = "grid";
}
}
});

'use strict';

window.loaded = false;

class Answer {
constructor(answer, type) {
this.body = answer;
this.type = type;
}

get isMultiChoice() {
return this.type === "multiple_choice";
}

get isFreeResponse() {
return this.type === "free_response";
}

get isExpression() {
return this.type === "expression";
}

get isDropdown() {
return this.type === "dropdown";
}

log() {
const answer = this.body;

answer.forEach((ans, index) => {
if (typeof ans === "string") {
if (ans.includes("web+graphie")) {
this.body[index] = "";
this.printImage(ans);
} else {
answer[index] = ans.replaceAll("$", "");
}
}
});
}
}

const originalFetch = window.fetch;
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();
const item = json.data.assessmentItem.item.itemData;
const question = JSON.parse(item).question;

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

if (!window.loaded) {
console.clear();
window.loaded = true;
}

return res;
});
};

let curAns = 1;

function freeResponseAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.answers) {
return widget.options.answers.map(answer => {
if (answer.status === "correct") {
const createPar = document.createElement('section');
createPar.innerHTML = answer.value;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
}).filter(val => val !== undefined);

return new Answer(answer, "free_response");
}

function multipleChoiceAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.choices) {
return widget.options.choices.map(choice => {
if (choice.correct) {
const createPar = document.createElement('section');
createPar.innerHTML = choice.content;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
}).filter(val => val !== undefined);

return new Answer(answer, "multiple_choice");
}

function expressionAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.answerForms) {
return widget.options.answerForms.map(answer => {
if (Object.values(answer).includes("correct")) {
const createPar = document.createElement('section');
createPar.innerHTML = answer.value;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
});

return new Answer(answer, "expression");
}

function dropdownAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.choices) {
return widget.options.choices.map(choice => {
if (choice.correct) {
const createPar = document.createElement('section');
createPar.innerHTML = choice.content;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
});

return new Answer(answer, "dropdown");
}
})();

Deleted user 1336565
§
Posted: 19-07-2024
Edited: 19-07-2024

sorry that was the wrong code heres the right code. if it still doesnt work then ill look through it again and see if there are any more errors:


// ==UserScript==
// @name KhanHack
// @version 3.9
// @description Here is a Khan Academy Solver!
// @author Logzilla6
// @match https://www.khanacademy.org/*
// @grant none
// @namespace https://greasyfork.org/users/783447
// @downloadURL https://update.greasyfork.org/scripts/427964/KhanHack.user.js
// @updateURL https://update.greasyfork.org/scripts/427964/KhanHack.meta.js
// ==/UserScript==

(function () {
'use strict';

document.addEventListener('DOMContentLoaded', (event) => {
console.log("DOM fully loaded and parsed");

const overlayHTML = `


Toggle

KhanHack

Reset Answer List

-Answers-

 
 
M also toggles Menu

`;

function get(x) {
return document.getElementById(x);
}

const overlay = document.createElement("div");
overlay.innerHTML = overlayHTML;
document.body.appendChild(overlay);

const acc = get("accordian");

acc.onclick = function () {
const panel = get("box2");
if (panel.style.display === "grid") {
panel.style.display = "none";
} else {
panel.style.display = "grid";
}
};

document.addEventListener('keydown', (event) => {
if (event.key === 'm') {
const panel = get("box2");
if (panel.style.display === "grid") {
panel.style.display = "none";
} else {
panel.style.display = "grid";
}
}
});

window.loaded = false;

class Answer {
constructor(answer, type) {
this.body = answer;
this.type = type;
}

get isMultiChoice() {
return this.type === "multiple_choice";
}

get isFreeResponse() {
return this.type === "free_response";
}

get isExpression() {
return this.type === "expression";
}

get isDropdown() {
return this.type === "dropdown";
}

log() {
const answer = this.body;
answer.forEach((ans, index) => {
if (typeof ans === "string") {
if (ans.includes("web+graphie")) {
this.body[index] = "";
this.printImage(ans);
} else {
answer[index] = ans.replaceAll("$", "");
}
}
});
}
}

const originalFetch = window.fetch;
window.fetch = function () {
return originalFetch.apply(this, arguments).then(async (res) => {
console.log("Fetch intercepted:", res.url);

if (res.url.includes("/getAssessmentItem")) {
const clone = res.clone();
const json = await clone.json();
const item = json.data.assessmentItem.item.itemData;
const question = JSON.parse(item).question;

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

if (!window.loaded) {
console.clear();
window.loaded = true;
}

return res;
});
};

let curAns = 1;

function freeResponseAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.answers) {
return widget.options.answers.map(answer => {
if (answer.status === "correct") {
const createPar = document.createElement('section');
createPar.innerHTML = answer.value;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
}).filter(val => val !== undefined);

return new Answer(answer, "free_response");
}

function multipleChoiceAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.choices) {
return widget.options.choices.map(choice => {
if (choice.correct) {
const createPar = document.createElement('section');
createPar.innerHTML = choice.content;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
}).filter(val => val !== undefined);

return new Answer(answer, "multiple_choice");
}

function expressionAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.answerForms) {
return widget.options.answerForms.map(answer => {
if (Object.values(answer).includes("correct")) {
const createPar = document.createElement('section');
createPar.innerHTML = answer.value;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
});

return new Answer(answer, "expression");
}

function dropdownAnswerFrom(question) {
const answer = Object.values(question.widgets).flatMap((widget) => {
if (widget.options?.choices) {
return widget.options.choices.map(choice => {
if (choice.correct) {
const createPar = document.createElement('section');
createPar.innerHTML = choice.content;
document.getElementById('ansBreak').append(createPar);
curAns++;
}
});
}
});

return new Answer(answer, "dropdown");
}
});
})();

§
Posted: 19-07-2024

the code doesnt work use the above one he messed up and it wont show the toggle button. just copy the actual old script error fix it or use ai and try and see if that works.

Post reply

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