Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Last active November 26, 2021 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UltiRequiem/a1d6f620337e46d272112b2de7a2a049 to your computer and use it in GitHub Desktop.
Save UltiRequiem/a1d6f620337e46d272112b2de7a2a049 to your computer and use it in GitHub Desktop.
No more Quizizz
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!"));
@UltiRequiem
Copy link
Author

UltiRequiem commented Nov 19, 2021

fetch("https://gist.githubusercontent.com/UltiRequiem/a1d6f620337e46d272112b2de7a2a049/raw/ae2009e711fccfafd3ab43fc3974d9e04f2e0252/script.js")
.then((res) => res.text()
.then((t) => eval(t)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment