Skip to content

Instantly share code, notes, and snippets.

@tolik518
Last active October 18, 2023 12:42
Show Gist options
  • Save tolik518/d15c568727c7f7075f302d26c9a4e0c0 to your computer and use it in GitHub Desktop.
Save tolik518/d15c568727c7f7075f302d26c9a4e0c0 to your computer and use it in GitHub Desktop.
Get solutions for H5P quizzes on moodle
let json = JSON.parse(H5PIntegration.contents[Object.keys(H5PIntegration.contents)].jsonContent);
function removeTrash(string) {
return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/&nbsp;/g, "").replace(/\*/g, "▓")
}
if (json.questions !== undefined) {
if (json.questions[0].params === undefined) {
console.log(removeTrash(json.questions[0]));
} else {
json.questions.forEach((question, key) => {
console.log("Frage " + key + ": " + question.params.question);
question.params.answers.forEach(answer => {
if (answer.correct) {
console.log("%cAntwort " + key + ": " + answer.text, 'background: #222; color: #baff55');
}
});
})
}
} else if (json.textField !== undefined) {
console.log(removeTrash(json.textField));
} else if (json.words !== undefined) { // Crossword
json.words.forEach(
(e) => {
console.log(e.clue + " %c" + e.answer, 'background: #222; color: #baff55')
}
);
} else if (json.wordList !== undefined) { // Wordgrid
console.log(removeTrash(json.wordList));
} else {
console.log("kp, lol");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment