CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
gbaranski

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: gbaranski/quizizz-cheat
Path: blob/master/src/index.ts
Views: 2223
1
/*
2
Quizizz-cheat
3
Copyright (C) gbaranski
4
5
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
7
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10
11
github repository: https://github.com/gbaranski/quizizz-cheat
12
email: [email protected]
13
*/
14
15
16
17
18
import { VueElement, QuizQuestion, QuizInfo } from "./types";
19
20
const getQuestionsElement = () => {
21
const questionsElem = document.querySelector(
22
"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"
23
);
24
if (!questionsElem)
25
throw new Error("Unable to retreive questions list element");
26
27
return questionsElem;
28
};
29
30
const changeElementOpacity = (elem: HTMLElement) => {
31
elem.style.opacity = "20%";
32
};
33
34
const highlightAnswers = (question: QuizQuestion) => {
35
const questionsElem = getQuestionsElement();
36
const arr: VueElement[] = Array.prototype.slice.call(questionsElem.children);
37
38
if (Array.isArray(question.structure.answer) && question.structure.answer.length < 1 && question.structure.options) {
39
const answers = question.structure.options.map((option) => option.text).join(" or ");
40
alert(answers);
41
42
return;
43
}
44
45
arr.filter((e) => {
46
if (Array.isArray(question.structure.answer) && question.structure.answer.length > 0) {
47
return !(question.structure.answer.some((ansID) => e.__vue__.optionData.actualIndex === ansID));
48
} else if(typeof question.structure.answer == "number") {
49
return e.__vue__.optionData.actualIndex !== question.structure.answer
50
} else {
51
console.error("Fail detecting type of question: ", question);
52
}
53
}).forEach(changeElementOpacity);
54
}
55
56
const getQuestionInfo = (): {
57
questionID: string;
58
roomHash: string;
59
playerId: string;
60
quizID: string;
61
roomCode: string;
62
} => {
63
const rootObject = document.querySelector("body > div") as VueElement | null;
64
if (!rootObject) throw new Error("Could not retrieve root object");
65
const vue = rootObject.__vue__;
66
67
return {
68
roomHash: vue.$store._vm._data.$$state.game.data.roomHash,
69
playerId: vue.$store._vm._data.$$state.game.player.playerId,
70
quizID: vue.$store._vm._data.$$state.game.data.quizId,
71
roomCode: vue.$store._vm._data.$$state.game.data.roomCode,
72
questionID: vue.$store._vm._data.$$state.game.questions.currentId,
73
};
74
};
75
76
const getRoomHash = (): string => {
77
const rootObject = document.querySelector("body > div") as VueElement | null;
78
if (!rootObject) throw new Error("Could not retrieve root object");
79
const vue = rootObject.__vue__;
80
81
return vue.$store._vm._data.$$state.game.data.roomHash;
82
}
83
84
const msg = `%c
85
Script created by gbaranski#5119!
86
https://github.com/gbaranski/quizizz-cheat
87
`;
88
89
90
(async () => {
91
console.log(msg, "color: red;");
92
93
const quiz: QuizInfo = await (await fetch(`https://quizizz.com/_api/main/game/${getRoomHash()}`)).json();
94
95
let lastQuestionID: string | undefined = undefined;
96
97
setInterval(() => {
98
const questionInfo = getQuestionInfo();
99
if (questionInfo.questionID !== lastQuestionID) {
100
for (const q of quiz.data.questions) {
101
if (questionInfo.questionID === q._id) {
102
console.log({q});
103
highlightAnswers(q);
104
lastQuestionID = questionInfo.questionID;
105
}
106
}
107
}
108
}, 500)
109
110
})();
111
112