Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
UndercoverGoose
GitHub Repository: UndercoverGoose/classroom-cheats
Path: blob/master/scripts/quizlet_live.js
853 views
1
try {
2
async function getSetId(pin) {
3
const res = await fetch(`https://quizlet.com/webapi/3.8/multiplayer/game-instance?gameCode=${pin}`);
4
const json = await res.json();
5
if(json.error) throw new Error(json.error.message);
6
return json.gameInstance.itemId;
7
}
8
async function getSetData(setId) {
9
const res = await fetch(`https://quizlet.com/${setId}`);
10
const text = await res.text();
11
const data = text.match(/\\"termIdToTermsMap\\":{.+?{.+?\\"termSort\\":/gi)?.[0];
12
if(!data) throw new Error("Failed to parse set data.");
13
const parsed = JSON.parse(data.slice(21, -14).replaceAll(`\\"`,`"`));
14
return [Object.fromEntries(Object.values(parsed).map(({word, definition}) => [word, definition])), Object.fromEntries(Object.values(parsed).map(({word, definition}) => [definition, word]))];
15
}
16
function getActiveQuestion() {
17
try {
18
const question = document.querySelector(".StudentPrompt-text").textContent;
19
const answers = Array.from(document.querySelectorAll(".StudentAnswerOption-text"));
20
return [question, answers];
21
}catch {}
22
return [null, null];
23
}
24
(async() => {
25
const pin = prompt("Enter PIN, like: XXX-XXX", "").match(/[0-9a-zA-Z]/g).join("");
26
if(pin.length !== 6) throw new Error("Pin must be 6 characters in length.");
27
const setId = await getSetId(pin);
28
const [term2Def, def2Term] = await getSetData(setId);
29
setInterval(async function() {
30
const [question, choices] = getActiveQuestion();
31
if(!question || !choices) return;
32
if(question in term2Def) {
33
choices.forEach((choice) => {
34
if(choice.textContent === term2Def[question]) choice.style.fontWeight = "bolder";
35
});
36
}else if(question in def2Term) {
37
choices.forEach((choice) => {
38
if(choice.textContent === def2Term[question]) choice.style.fontWeight = "bolder";
39
});
40
}else {
41
choices.forEach((choice) => {
42
choice.style.fontWeight = "normal";
43
});
44
}
45
}, 0);
46
})();
47
}catch(err) {
48
alert(err);
49
}
50