Last active
October 18, 2023 12:42
-
-
Save tolik518/d15c568727c7f7075f302d26c9a4e0c0 to your computer and use it in GitHub Desktop.
Get solutions for H5P quizzes on moodle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let json = JSON.parse(H5PIntegration.contents[Object.keys(H5PIntegration.contents)].jsonContent); | |
function removeTrash(string) { | |
return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/ /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