KhanHack

Khan Academy Answer Hack

< 腳本KhanHack的回應

評論:正評 - 腳本一切正常

§
發表於:2025-07-13

i have fixed it but it shows a little bit of gibberish

// ==UserScript==
// @name KhanHack
// @namespace https://gf.qytechs.cn/users/783447
// @version 6.5
// @description Khan Academy Answer Hack (Red, unified answer list — clean display)
// @author Logzilla6 - IlyTobias - Illusions
// @match https://*.khanacademy.org/*
// @icon https://i.ibb.co/K5g1KMq/Untitled-drawing-3.png
// ==/UserScript==

(function () {
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);

let mainMenu = document.createElement('div');
mainMenu.id = 'mainMenu';
Object.assign(mainMenu.style, {
position: 'fixed', bottom: '.5vw', left: '12vw', width: '300px', height: '400px',
backgroundColor: '#123576', border: '3px solid #07152e', borderRadius: '20px',
padding: '10px', color: 'white', fontFamily: 'Noto sans', fontWeight: '500',
transition: 'all 0.3s ease', zIndex: '1000', display: 'flex', flexDirection: 'column'
});

let isGhostModeEnabled = false;
let isMenuVisible = true;
let shownAnswers = new Set();

function enableGhostMode() {
mainMenu.style.opacity = '0';
mainMenu.addEventListener('mouseenter', () => mainMenu.style.opacity = '1');
mainMenu.addEventListener('mouseleave', () => mainMenu.style.opacity = '0');
}

function disableGhostMode() {
mainMenu.style.opacity = '1';
mainMenu.removeEventListener('mouseenter', () => {});
mainMenu.removeEventListener('mouseleave', () => {});
}

function addToggle() {
document.getElementById('toggleButton').addEventListener('click', () => {
const clearButton = document.getElementById('clearButton');
const content = document.getElementById('menuContent');
if (isMenuVisible) {
mainMenu.style.width = '15px';
mainMenu.style.height = '15px';
content.style.opacity = '0';
clearButton.style.opacity = '0';
setTimeout(() => {
content.style.display = 'none';
clearButton.style.display = 'none';
}, 50);
} else {
mainMenu.style.width = '300px';
mainMenu.style.height = '400px';
content.style.display = 'flex';
clearButton.style.display = 'block';
setTimeout(() => {
content.style.opacity = '1';
clearButton.style.opacity = '1';
}, 100);
}
isMenuVisible = !isMenuVisible;
});
}

function addSettings() {
document.getElementById('gearIcon').addEventListener('click', () => {
let backup = mainMenu.cloneNode(true);
mainMenu.innerHTML = `


Settings Menu

Ghost Mode:

`;
document.getElementById('backArrow').addEventListener('click', () => {
mainMenu.replaceWith(backup);
mainMenu = backup;
setMainMenuContent();
});
document.getElementById('ghostModeToggle').addEventListener('change', function () {
isGhostModeEnabled = this.checked;
isGhostModeEnabled ? enableGhostMode() : disableGhostMode();
});
});
}

function setMainMenuContent() {
mainMenu.innerHTML = `




Click to copy



`;
addToggle();
addSettings();
addDiscord();
addClear();
if (isGhostModeEnabled) enableGhostMode();
}

function addDiscord() {
document.getElementById('discordIcon').addEventListener('click', () => {
window.open('https://discord.gg/khanhack', '_blank');
});
}

function addClear() {
document.getElementById('clearButton').addEventListener('click', () => location.reload());
}

function addNewAnswerBlock(answer) {
const normalized = answer.trim().replace(/\s+/g, ' ');
if (shownAnswers.has(normalized)) return;
shownAnswers.add(normalized);

const answerList = document.getElementById('answerList');
const block = document.createElement('div');
block.className = 'block';
Object.assign(block.style, {
cursor: 'pointer',
backgroundColor: '#f0f0f0',
padding: '10px',
borderRadius: '10px',
color: 'red',
marginBottom: '10px',
fontWeight: 'bold',
wordBreak: 'break-word'
});

const ansVal = document.createElement('a');
ansVal.className = 'answer';
ansVal.innerText = answer;
ansVal.style.fontSize = '16px';
block.appendChild(ansVal);
block.addEventListener('click', () => navigator.clipboard.writeText(answer));
answerList.appendChild(block);
}

document.body.appendChild(mainMenu);
setMainMenuContent();

const originalParse = JSON.parse;
JSON.parse = function (jsonString) {
let parsed = originalParse(jsonString);
try {
if (parsed?.data?.assessmentItem?.item) {
let itemData = JSON.parse(parsed.data.assessmentItem.item.itemData);
let widgets = itemData?.question?.widgets || {};

for (let key in widgets) {
let w = widgets[key];
let extracted = [];

if (w.options?.value) extracted.push(w.options.value);
if (w.options?.answers) extracted.push(...w.options.answers.map(a => typeof a === 'object' ? JSON.stringify(a) : a));
if (w.options?.answerForms) extracted.push(...w.options.answerForms.map(f => f.value));
if (w.options?.choices) {
extracted.push(...w.options.choices.filter(c => c.correct).map(c => c.content || ''));
}

extracted.filter(Boolean).forEach(ans => addNewAnswerBlock(ans));
}
}
} catch (e) {
console.warn('Failed to parse KA widget JSON:', e);
}
return parsed;
};
})();

發表回覆

登入以回覆

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址