Last active
November 26, 2021 00:24
-
-
Save UltiRequiem/a1d6f620337e46d272112b2de7a2a049 to your computer and use it in GitHub Desktop.
No more Quizizz
This file contains 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
function getQuestionsElement() { | |
const questionsElem = document.querySelector( | |
"body > div > div.root-component > div > div > div > div.page-container.in-quiz > div.screen.screen-game > div.transitioner.transitioner-component > div > div > div > div > div > div.options-container > div" | |
); | |
if (!questionsElem) throw new Error("Unable to retrieve questions list element."); | |
return questionsElem; | |
} | |
function highlightAnswers(question) { | |
const questionsElem = getQuestionsElement(); | |
const arr = Array.prototype.slice.call(questionsElem.children); | |
if ( | |
Array.isArray(question.structure.answer) && | |
question.structure.answer.length < 1 && | |
question.structure.options | |
) { | |
const answers = question.structure.options | |
.map((option) => option.text) | |
.join(" or "); | |
alert(answers); | |
return; | |
} | |
arr | |
.filter((e) => { | |
if ( | |
Array.isArray(question.structure.answer) && | |
question.structure.answer.length > 0 | |
) { | |
return !question.structure.answer.some( | |
(ansID) => e.__vue__.optionData.actualIndex === ansID | |
); | |
} else if (typeof question.structure.answer == "number") { | |
return e.__vue__.optionData.actualIndex !== question.structure.answer; | |
} else { | |
console.error("Fail detecting type of question: ", question); | |
} | |
}) | |
.forEach((element) => (element.style.opacity = "20%")); | |
} | |
function getQuestionInfo() { | |
const rootObject = document.querySelector("body > div"); | |
if (!rootObject) throw new Error("Could not retrieve root object"); | |
const vue = rootObject.__vue__; | |
return { | |
roomHash: vue.$store._vm._data.$$state.game.data.roomHash, | |
playerId: vue.$store._vm._data.$$state.game.player.playerId, | |
quizID: vue.$store._vm._data.$$state.game.data.quizId, | |
roomCode: vue.$store._vm._data.$$state.game.data.roomCode, | |
questionID: vue.$store._vm._data.$$state.game.questions.currentId, | |
}; | |
} | |
function getRoomHash() { | |
const rootObject = document.querySelector("body > div"); | |
if (!rootObject) throw new Error("Could not retrieve root object"); | |
return rootObject.__vue__.$store._vm._data.$$state.game.data.roomHash; | |
} | |
async function main() { | |
console.log(getRoomHash()); | |
const response = await fetch( | |
`https://quizizz.com/_api/main/game/${getRoomHash()}` | |
); | |
const quiz = await response.json(); | |
let lastQuestionID = undefined; | |
setInterval(() => { | |
const questionInfo = getQuestionInfo(); | |
if (questionInfo.questionID !== lastQuestionID) { | |
for (const q of quiz.data.questions) { | |
if (questionInfo.questionID === q._id) { | |
console.log({ q }); | |
highlightAnswers(q); | |
lastQuestionID = questionInfo.questionID; | |
} | |
} | |
} | |
}, 500); | |
} | |
main().then(console.log("Done!")); |
Author
UltiRequiem
commented
Nov 19, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment