Khan Academy Answer Hack
yo bro can u teach me how to change the code of the original script to this cause i legit need khanhack for im fucked in my class would appreciate a tutorial on yt or smth bro, i tried copy and pasting it on tampermonkey but shit still wont work for some damn reason i need ur help bro pls.
yo bro can u teach me how to change the code of the original script to this cause i legit need khanhack for im fucked in my class would appreciate a tutorial on yt or smth bro, i tried copy and pasting it on tampermonkey but shit still wont work for some damn reason i need ur help bro pls.
Open Tampermonkey → go to Installed Scripts → click the little pen icon (edit).
Press Ctrl+A → Backspace to wipe the old code.
Paste the new code → Ctrl+S to save.
Then refresh Khan Academy.
If it still doesn’t run, it’s other browser extensions interfering
yo bro can u teach me how to change the code of the original script to this cause i legit need khanhack for im fucked in my class would appreciate a tutorial on yt or smth bro, i tried copy and pasting it on tampermonkey but shit still wont work for some damn reason i need ur help bro pls.
Yo, There's a mistake in your code and it doesn't work properly, how can I fix it?
yo have you found any solutions yet?
@UnknownSigma @whatever pigeon @broohootspoot @ChaoticPanda
Try this and tell me if it works here: `https://pastebin.com/t6whBJxT`
also if there's any issues that occur tell me and i'll try to see if i can fix them like bugs
@UnknownSigma @whatever pigeon @broohootspoot @ChaoticPanda
Try this and tell me if it works here: `https://pastebin.com/t6whBJxT`
also if there's any issues that occur tell me and i'll try to see if i can fix them like bugs
Works good for me, tysm man
yo is there anyway or method to bypass the videos and get 100% sometimes its too long
@UnknownSigma @whatever pigeon @broohootspoot @ChaoticPanda
Try this and tell me if it works here: `https://pastebin.com/t6whBJxT`
also if there's any issues that occur tell me and i'll try to see if i can fix them like bugs
yo bro is it still working?
Fixed the Script Since it wasnt working and added some new features
// ==UserScript==
// @name KhanHack v7.0 - Community Edition
// @namespace https://greasyfork.org/users/783447
// @version 7.0
// @description Khan Academy Answer Hack - Auto-Clear + Bug Fixes
// @author Logzilla6 - IlyTobias - Illusions | Community Updates by RobertoEvilCousin285087
// @match https://*.khanacademy.org/*
// @icon https://i.ibb.co/K5g1KMq/Untitled-drawing-3.png
// ==/UserScript==
//ALL FOLLOWING CODE IS UNDER THE KHANHACK TRADEMARK. UNAUTHORIZED DISTRIBUTION CAN/WILL RESULT IN LEGAL ACTION
//Note that KhanHack™ is an independent initiative and is not affiliated with or endorsed by Khan Academy. We respect the work of Khan Academy and its mission to provide free education, but KhanHack™ operates separately with its own unique goals.
// ============================================
// PATCH NOTES - v7.0 (Community Edition)
// ============================================
//
// 🆕 NEW FEATURES:
// - Auto-Clear on URL Change: Menu automatically clears all answers when navigating to different pages/assignments
// - Auto-Clear on Lesson Change: Detects lesson/unit switches and clears menu automatically
// - URL monitoring system checks every 500ms for navigation changes
//
// 🔧 IMPROVEMENTS:
// - Better Chemistry Support: Added mhchem extension for KaTeX to properly render chemistry notation (e.g., \ce{} commands)
// - Enhanced Widget Detection: Improved checks for all possible data paths (assessmentItem, assessmentItemById, assessmentItemByProblemNumber)
// - Smarter Widget Filtering: Now properly skips widgets that aren't graded (filters out graded:false and static:true to avoid decoy data)
// - Improved Error Handling: Better fallback logic for expression widgets when answerForms doesn't exist
//
// 🐛 BUG FIXES:
// - Fixed issue where answers from pre-loaded future questions could appear
// - Fixed KaTeX rendering errors with throwOnError: false option
// - Fixed image URL extraction for radio choices with standard markdown image syntax
// - Fixed potential crashes from undefined/null answer content in radio widgets
//
// 📋 TECHNICAL CHANGES:
// - Added lastUrl and lastPageTitle tracking variables
// - Integrated setInterval() checker for URL and lesson title changes
// - Added comprehensive null/undefined checks in handleRadio()
// - Enhanced regex pattern for image URL extraction
// - Added mhchem script loading for chemistry notation
//
// Original version by: Logzilla6, IlyTobias, Illusions
// Community maintenance by: RobertoEvilCousin285087
//
// ============================================
let mainMenu = document.createElement('div');
mainMenu.id = 'mainMenu';
mainMenu.style.position = 'fixed';
mainMenu.style.bottom = '.5vw';
mainMenu.style.left = '12vw';
mainMenu.style.width = '300px';
mainMenu.style.height = '400px';
mainMenu.style.backgroundColor = '#123576';
mainMenu.style.border = '3px solid #07152e';
mainMenu.style.borderRadius = '20px';
mainMenu.style.padding = '10px';
mainMenu.style.color = "white";
mainMenu.style.fontFamily = "Noto sans";
mainMenu.style.fontWeight = "500";
mainMenu.style.transition = "all 0.3s ease";
mainMenu.style.zIndex = '1000';
mainMenu.style.display = 'flex';
mainMenu.style.flexDirection = 'column';
let answerBlocks = [];
let currentCombinedAnswer = '';
let isGhostModeEnabled = false;
let blockTick = 0;
let firstAns;
let secondAns;
// AUTO-CLEAR VARIABLES
let lastUrl = location.href;
let lastPageTitle = "";
const setMainMenuContent = () => {
mainMenu.innerHTML =`
`;
addToggle();
addSettings();
addDiscord();
addClear();
const answerList = document.getElementById('answerList');
if (isGhostModeEnabled) {
enableGhostMode();
}
};
let isMenuVisible = true;
const addToggle = () => {
document.getElementById('toggleButton').addEventListener('click', function() {
const clearButton = document.getElementById('clearButton');
if (isMenuVisible) {
mainMenu.style.height = '15px';
mainMenu.style.width = '15px';
document.getElementById('menuContent').style.opacity = '0';
clearButton.style.opacity = '0';
setTimeout(() => {
document.getElementById('menuContent').style.display = 'none';
clearButton.style.display = 'none';
}, 50);
} else {
mainMenu.style.height = '400px';
mainMenu.style.width = '300px';
document.getElementById('menuContent').style.display = 'flex';
clearButton.style.display = 'block';
setTimeout(() => {
document.getElementById('menuContent').style.opacity = '1';
clearButton.style.opacity = '1';
}, 100);
}
isMenuVisible = !isMenuVisible;
});
};
const addSettings = () => {
document.getElementById('gearIcon').addEventListener('click', function() {
let saveHtml = document.getElementById('mainMenu').innerHTML
mainMenu.innerHTML = `
Settings Menu
Ghost Mode:
Auto Answer: BETA
Point Farmer: BETA
Beta Access In Discord
KhanHack™ | v7.0 Community
`;
document.getElementById('backArrow').addEventListener('click', () => {mainMenu.innerHTML = saveHtml; addSettings(); addToggle(); addDiscord(); addClear();});
document.getElementById('ghostModeToggle').addEventListener('change', function() {
isGhostModeEnabled = this.checked;
if (isGhostModeEnabled) {
enableGhostMode();
} else {
disableGhostMode();
}
});
});
};
const enableGhostMode = () => {
mainMenu.style.opacity = '0';
mainMenu.addEventListener('mouseenter', handleMouseEnter);
mainMenu.addEventListener('mouseleave', handleMouseLeave);
};
const disableGhostMode = () => {
mainMenu.style.opacity = '1';
mainMenu.removeEventListener('mouseenter', handleMouseEnter);
mainMenu.removeEventListener('mouseleave', handleMouseLeave);
};
const handleMouseEnter = () => {
mainMenu.style.opacity = '1';
};
const handleMouseLeave = () => {
mainMenu.style.opacity = '0';
};
const addDiscord = () => {
document.getElementById('discordIcon').addEventListener('click', function() {
window.open('https://discord.gg/khanhack', '_blank');
});
};
const addClear = () => {
document.getElementById('clearButton').addEventListener('click', function() {
location.reload();
});
};
const script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js";
document.head.appendChild(script);
const katexStyle = document.createElement("link");
katexStyle.rel = "stylesheet";
katexStyle.href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css";
document.head.appendChild(katexStyle);
// Load mhchem extension for chemistry notation
const mhchemScript = document.createElement("script");
mhchemScript.src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js";
document.head.appendChild(mhchemScript);
const getCurrentQuestion = () => {
const container = document.querySelector(`div[data-testid="content-library-footer"]`)
let firstChar = container.querySelectorAll("div")[5].children[0].innerText.charAt(0)
let lastChar = container.querySelectorAll("div")[5].children[0].innerText.slice(-1)
if(firstChar == lastChar-1) {
console.log(true)
container.querySelectorAll("button")[3].onclick = function() {;
firstAns = document.getElementById(`blockNum${blockTick-1}`)
console.log(firstAns)
secondAns = document.getElementById(`blockNum${blockTick}`)
secondAns.style.opacity = "100%";
firstAns.remove()
answerBlocks.shift()
}
} else {
console.log(false)
}
}
const addNewAnswerBlock = (answer, imgSrc, isImg) => {
const answerList = document.getElementById('answerList');
const block = document.createElement('div');
blockTick ++
//console.log(' blockTick: ' + blockTick)
if(isImg == true) {
block.className = 'block imgBlock';
const img = document.createElement('img');
img.src = imgSrc;
block.id = `blockNum${blockTick}`
block.innerHTML = `${answer}`;
block.style.display = "inline-block"
block.style.color = "black";
block.appendChild(img);
answerList.appendChild(block);
answerBlocks.push({ type: 'image', content: block.id });
//console.log('num: ' + block.id)
}
else {
block.className = 'block no-select';
block.id = `blockNum${blockTick}`
block.style.cursor = "pointer";
block.addEventListener("click", () => {
console.log('clicked')
navigator.clipboard.writeText(answer);
});
const ansVal = document.createElement('a');
ansVal.className = 'answer';
const latexPattern = /\\frac|\\sqrt|\\times|\\cdot|\\degree|\\dfrac|\\vec|\\leq|\\left|\\right|\^|\$|\{|\}|\\ce/;
if (latexPattern.test(answer)) {
ansVal.innerHTML = '';
try {
katex.render(answer, ansVal, {
throwOnError: false,
trust: true // Allow \ce and other chemistry commands
});
} catch (e) {
// If KaTeX fails, just display as plain text
ansVal.innerHTML = answer;
}
} else {
ansVal.innerHTML = `${answer}`;
}
ansVal.style.fontSize = "16px";
block.appendChild(ansVal);
answerList.appendChild(block);
answerBlocks.push({ type: 'text', content: block.id });
//console.log('num: ' + block.id)
}
const runList = () => {
if(answerBlocks.length == 3) {
//console.log(`length is ${answerBlocks.length}`)
firstAns = document.getElementById(`blockNum${blockTick-2}`)
secondAns = document.getElementById(`blockNum${blockTick-1}`)
secondAns.style.opacity = "100%";
firstAns.remove()
answerBlocks.shift()
getCurrentQuestion()
//console.log(`shifted is ${answerBlocks.length}`)
runList()
} else if(answerBlocks.length == 2) {
//console.log(`length is ${answerBlocks.length}`)
firstAns = document.getElementById(`blockNum${blockTick-1}`)
secondAns = document.getElementById(`blockNum${blockTick}`)
if(secondAns.style.opacity == "0%") {
firstAns.remove()
answerBlocks.shift()
secondAns.style.opacity = "100%";
} else{
secondAns.style.opacity = "0%";
}
}
}
runList()
}
document.body.appendChild(mainMenu);
setMainMenuContent();
let originalJson = JSON.parse;
JSON.parse = function (jsonString) {
let parsedData = originalJson(jsonString);
try {
// FIXED: Check for all possible data paths
let assessmentItem = null;
if (parsedData.data) {
assessmentItem = parsedData.data.assessmentItem ||
parsedData.data.assessmentItemById ||
parsedData.data.assessmentItemByProblemNumber;
}
if (assessmentItem && assessmentItem.item) {
let itemData = JSON.parse(assessmentItem.item.itemData);
// FIXED: More flexible check for widgets
let hasWidgets = itemData.question &&
itemData.question.widgets &&
Object.keys(itemData.question.widgets).length > 0;
if (hasWidgets) {
for (let widgetKey in itemData.question.widgets) {
let widget = itemData.question.widgets[widgetKey];
// CRITICAL: Skip widgets that aren't actually graded (dummy/decoy data)
if (widget.graded === false || widget.static === true) {
continue;
}
switch (widget.type) {
case "numeric-input":
handleNumeric(widget);
break;
case "radio":
handleRadio(widget);
break;
case "expression":
handleExpression(widget);
break;
case "dropdown":
handleDropdown(widget);
break;
case "interactive-graph":
handleIntGraph(widget);
break;
case "grapher":
handleGrapher(widget);
break;
case "input-number":
handleInputNum(widget);
break;
case "matcher":
handleMatcher(widget);
break;
case "categorizer":
handleCateg(widget);
break;
case "label-image":
handleLabel(widget);
break;
case "matrix":
handleMatrix(widget);
break;
case "definition":
case "explanation":
case "image":
// Skip supplementary widgets that don't contain answers
break;
default:
console.log("Unknown widget type:", widget.type);
break;
}
}
if (currentCombinedAnswer.trim() !== '') {
if(currentCombinedAnswer.slice(-4) == '
') {
addNewAnswerBlock(currentCombinedAnswer.slice(0, -4), null, false)
currentCombinedAnswer = '';
} else {
addNewAnswerBlock(currentCombinedAnswer, null, false)
currentCombinedAnswer = '';
}
}
}
}
} catch (error) {
console.log("Error parsing JSON:", error);
}
return parsedData;
};
function cleanLatexExpression(answer) {
return answer
.replace('begin{align}', 'begin{aligned}')
.replace('end{align}', 'end{aligned}')
.replace(/\$/g, '');
}
function handleRadio(widget) {
let corAns = widget.options.choices.filter(item => item.correct === true).map(item => item.content);
let ansArr = [];
let isNone = widget.options.choices.filter(item => item.isNoneOfTheAbove === true && item.correct === true)
if (isNone.length > 0) {
currentCombinedAnswer += "None of the above";
return;
}
corAns.forEach(answer => {
// Check if answer is undefined or null
if (!answer) {
return;
}
const hasGraphie = answer.includes('web+graphie')
const hasImage = answer.includes(';
const text = split[0].slice(2)
const midUrl = split[1].split(')')[0];
const finalUrl = 'https' + midUrl + '.svg';
addNewAnswerBlock(text || "Image", finalUrl, true);
} else if(hasImage) {
// Better image URL extraction
const urlMatch = answer.match(/\((https?:\/\/[^\)]+)\)/);
if (urlMatch && urlMatch[1]) {
const finalUrl = urlMatch[1];
addNewAnswerBlock(null, finalUrl, true);
}
}
} else {
// Only process as text if it doesn't contain images
let cleaned = cleanLatexExpression(answer)
ansArr.push(cleaned)
}
})
if(ansArr.length) {
currentCombinedAnswer += ansArr.join(", ")
}
}
function handleLabel(widget) {
let corAns = widget.options.markers.filter(item => item.answers).map(item => item.answers)
let labels = widget.options.markers.filter(item => item.label).map(item => item.label)
let ansArr = []
corAns.forEach((answer, index) => {
if(labels == 0) {
let cleaned = cleanLatexExpression(answer.toString());
ansArr.push(cleaned)
} else {
let cleaned = cleanLatexExpression(answer.toString());
let finLabel = labels[index].replace('Point ', '').replace(/[.]/g, '').trim() || "";
let labeledAnswer = `${finLabel}: ${cleaned}`;
ansArr.push(labeledAnswer)
}
})
if(ansArr.length) {
currentCombinedAnswer += ansArr.join("|")
}
}
function handleNumeric(widget) {
const numericAnswer = widget.options.answers[0].value;
currentCombinedAnswer += `${numericAnswer}
`;
}
function handleExpression(widget) {
// Check if answerForms exists and has data
if (!widget.options || !widget.options.answerForms || !widget.options.answerForms[0]) {
// Try alternative answer locations
if (widget.options && widget.options.answers && widget.options.answers[0]) {
let expressionAnswer = widget.options.answers[0].value;
let cleaned = cleanLatexExpression(expressionAnswer);
currentCombinedAnswer += ` ${cleaned} `;
return;
}
return;
}
let expressionAnswer = widget.options.answerForms[0].value;
let cleaned = cleanLatexExpression(expressionAnswer);
currentCombinedAnswer += ` ${cleaned} `;
}
function handleDropdown(widget) {
let content = widget.options.choices.filter(item => item.correct === true).map(item => item.content);
currentCombinedAnswer += ` ${content[0]} `;
}
function handleIntGraph(widget) {
let coords = widget.options.correct.coords;
let validCoords = coords.filter(coord => coord !== undefined);
currentCombinedAnswer += ` ${validCoords.join(' | ')} `;
}
function handleInputNum(widget) {
let inputNumAnswer = widget.options.value;
console.log(inputNumAnswer)
currentCombinedAnswer += ` ${inputNumAnswer} `;
}
function handleMatcher(widget) {
let matchAnswer = widget.options.right;
let cleaned = cleanLatexExpression(matchAnswer)
currentCombinedAnswer += ` ${matchAnswer} `;
}
function handleGrapher(widget) {
let coords = widget.options.correct.coords;
currentCombinedAnswer += ` ${coords.join(' | ')} `;
}
function handleCateg(widget) {
let values = widget.options.values;
let categories = widget.options.categories;
let labeledValues = values.map(value => categories[value]);
currentCombinedAnswer += ` ${labeledValues} `
}
function handleMatrix(widget) {
let arrs = widget.options.answers;
currentCombinedAnswer += ` ${arrs.join(' | ')} `
}
// ============================================
// AUTO-CLEAR ON URL CHANGE - v7.0 FEATURE
// ============================================
setInterval(() => {
if (location.href !== lastUrl) {
lastUrl = location.href;
console.log('%c[KhanHack v7.0] URL Changed - Clearing menu', 'color: #ff6b6b; font-weight: bold;');
// Clear the answer list
const answerList = document.getElementById('answerList');
if (answerList) {
answerList.innerHTML = '';
}
// Reset all variables
answerBlocks = [];
blockTick = 0;
currentCombinedAnswer = '';
}
// Also check for lesson title changes
const header = document.querySelector('[data-test-id="lesson-title-header"]');
if (header) {
const currentTitle = header.innerText;
if (currentTitle !== lastPageTitle && lastPageTitle !== "") {
console.log('%c[KhanHack v7.0] Lesson Changed - Clearing menu', 'color: #ff6b6b; font-weight: bold;');
const answerList = document.getElementById('answerList');
if (answerList) {
answerList.innerHTML = '';
}
answerBlocks = [];
blockTick = 0;
currentCombinedAnswer = '';
}
lastPageTitle = currentTitle;
}
}, 500);