-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuizizzAssistantV2.js
159 lines (153 loc) · 8.07 KB
/
QuizizzAssistantV2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// ==UserScript==
// @name Quizizz Assistant
// @namespace https://github.com/Jev1337
// @version 2.9.9
// @description Assist with Quizizz by marking correct answers
// @author Malek
// @match https://quizizz.com/join/game/*
// @grant GM_xmlhttpRequest
// @connect api.quizit.online
// ==/UserScript==
//ZeroGPT :)
(function() {
'use strict';
function unescape(html) {
const divElement = document.createElement("div");
divElement.innerHTML = html;
return divElement.textContent;
}
function main() {
const processResponse = (apiResponse) => {
const questionElement = document.querySelector(".resizeable.gap-x-2.question-text-color.text-light");
if (questionElement) {
var questionText = questionElement.textContent;
const answer = apiResponse.data.answers.find((answer) => unescape(answer.question.text) === questionText);
if (answer) {
const correctAnswerText = answer.answers.map(answer => answer.text).join(', ');
console.log('%c Answer(s): ' + unescape(correctAnswerText), 'background: #222; color: #bada55');
var i = 0;
for (const a of document.querySelectorAll("p[style='display:inline']")) {
for (const b of correctAnswerText.split(", ")) {
console.debug(a.textContent + " === " + unescape(b));
if (a.textContent === unescape(b)) {
a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.classList.add("option-pressed");
i++;
}
}
}
if (i < correctAnswerText.split(", ").length) {
console.error("Failed to tag all answers to the question! Retrying with alternate method...");
i = 0;
for (const a of document.querySelectorAll("p[style='display:inline']")) {
for (const b of correctAnswerText.split(", ")) {
console.debug(a.textContent + ".includes(" + unescape(b) + ")");
if (a.textContent.includes(unescape(b))) {
a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.classList.add("option-pressed");
i++;
}
}
}
if (i < correctAnswerText.split(", ").length)
console.error("Failed to tag answer! Over and Out.");
else
console.log("%c Alternate Method Successful!", 'background: #222; color: #bada55');
}
} else {
console.error("Failed to find answer to the question! Retrying with alternate method...");
answer = apiResponse.data.answers.find((answer) => unescape(answer.question.text).includes(questionText));
if (answer) {
const correctAnswerText = answer.answers.map(answer => answer.text).join(', ');
console.log('%c Answer(s): ' + unescape(correctAnswerText), 'background: #222; color: #bada55');
var i = 0;
for (const a of document.querySelectorAll("p[style='display:inline']")) {
for (const b of correctAnswerText.split(", ")) {
console.debug(a.textContent + " === " + unescape(b));
if (a.textContent === unescape(b)) {
a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.classList.add("option-pressed");
i++;
}
}
}
if (i < correctAnswerText.split(", ").length) {
console.error("Failed to tag all answers to the question! Retrying with alternate method...");
i = 0;
for (const a of document.querySelectorAll("p[style='display:inline']")) {
for (const b of correctAnswerText.split(", ")) {
console.debug(a.textContent + ".includes(" + unescape(b) + ")");
if (a.textContent.includes(unescape(b))) {
a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.classList.add("option-pressed");
i++;
}
}
}
if (i < correctAnswerText.split(", ").length)
console.error("Failed to tag answer! Over and Out.");
else
console.log("%c Alternate Method Successful!", 'background: #222; color: #bada55');
}
} else
console.error("Failed to find answer to the question! Over and Out.");
}
} else
console.error("Failed to find question element!");
};
const retrieveAnswersButton = document.createElement("button");
retrieveAnswersButton.innerHTML = '<i class="game-end-icon icon-fas-flag-checkered"></i>';
retrieveAnswersButton.id = "retrieveAnswersButton";
retrieveAnswersButton.addEventListener("click", () => processResponse(apiResponse));
document.getElementsByClassName("actions-container")[0].appendChild(retrieveAnswersButton);
document.addEventListener('keydown', (event) => {
if (event.key === 'h') {
if (retrieveAnswersButton.style.visibility == "hidden") {
retrieveAnswersButton.style.visibility = "visible";
} else {
retrieveAnswersButton.style.visibility = "hidden";
}
}
if (event.key === 'p') {
processResponse(apiResponse);
}
});
}
function level1() {
console.log("Trying to get answers of room code: " + code);
//keep trying to get answers from api until it works, then call main()
GM_xmlhttpRequest({
method: "GET",
url: `https://api.quizit.online/quizizz/answers?pin=${code}`,
onload: (response) => {
if (response.status === 200) {
apiResponse = JSON.parse(response.responseText);
console.log('%c Answers Retrieved! ', 'background: #222; color: #bada55');
console.debug(apiResponse);
main();
} else {
level1();
console.error("Failed to retrieve answers. Please check the room code.");
}
},
onerror: () => {
level1();
console.error("Failed to retrieve answers. Please try again.");
}
});
}
let apiResponse = null;
var code = "";
let interval = setInterval(function() {
console.log("Checking for room code...");
if (document.getElementsByClassName("room-code").length > 0) {
clearInterval(interval);
code = document.getElementsByClassName("room-code")[0].innerText;
level1();
console.log("Code found: " + code);
}
if (document.getElementsByClassName("code").length > 0) {
clearInterval(interval);
code = document.getElementsByClassName("code")[0].innerText;
code = code.replace(/\s/g, '');
level1();
console.log("Code found: " + code);
}
}, 1000);
})();