1
Fork 0
This commit is contained in:
prescientmoon 2024-05-28 03:27:08 +02:00
commit 552432ff41
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
8 changed files with 1492 additions and 0 deletions

1
javascript/quizizz-hack/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

View file

@ -0,0 +1,5 @@
{
"cSpell.words": [
"BFBQC"
]
}

View file

@ -0,0 +1 @@
# 🚧 This repo has been moved to [prescientmoon/quizz-hack](https://github.com/prescientmoon/quizz-hack) 🚧

View file

@ -0,0 +1,106 @@
import { render, html } from "https://cdn.skypack.dev/lit-html";
const tags = ["p", "strong", "em", "sub", "sup", "span", "br", "sub"];
function removeTags(input) {
let copy = input.replace('"', '\\"');
for (const tag of tags)
copy = copy.replace(`<${tag}>`, "").replace(`</${tag}>`, "");
return copy;
}
// Here is the function to parse the json object.
// It returns object with key/value pair where key is the question and value is the answer
function parseQuestions(fileObject) {
const allAnswers = {};
for (const question of fileObject.data.quiz.info.questions) {
let answer;
if (question.type === "MCQ") {
if (question.structure.options[question.structure.answer].text == "") {
answer =
question.structure.options[question.structure.answer].media[0].url;
} else {
answer = removeTags(
question.structure.options[question.structure.answer].text
);
}
} else if (question.type == "MSQ") {
answer = question.structure.answer
.map((answerC) => {
if (question.structure.options[answerC].text == "") {
return question.structure.options[answerC].media[0].url;
} else {
return removeTags(question.structure.options[answerC].text);
}
})
.filter((a) => a !== undefined);
} else if (question.type == "BLANK") {
answer = question.structure.options.map((o) => removeTags(o.text));
}
const questionStr =
question.structure.query.text === ""
? question.structure.query.media[0].url
: removeTags(question.structure.query.text);
allAnswers[questionStr] = answer;
}
return allAnswers;
}
async function main(id) {
const res = await fetch(
`https://api.allorigins.win/get?url=${encodeURIComponent(
`https://quizizz.com/quiz/${id}`
)}`,
{}
);
const jsonObject = await res.json();
const parsedJson = JSON.parse(jsonObject.contents);
console.log(parsedJson.data);
const answers = parseQuestions(parsedJson);
const sorted = Object.entries(answers).sort();
console.log(answers);
render(renderQuestions(sorted), rootElement);
}
const inputElement = document.getElementById("id");
const rootElement = document.getElementById("root");
inputElement.addEventListener("keypress", (e) => {
if (e.key === "Enter") {
main(e.target.value).catch(console.error);
}
});
const renderQuestions = (questions) => {
return html`${questions.map(([question, answer]) => {
return html`
<div class="question-container">
<div class="question">
${question.startsWith("http")
? html`<img src=${question} />`
: question}
</div>
${Array.isArray(answer)
? html`
<ul>
${answer.map((correct) => {
return html`<li class="answer">${correct}</li> `;
})}
</ul>
`
: html` <div class="answer answer-single">${answer}</div> `}
</div>
`;
})}`;
};

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BFBQC</title>
<script defer type="module" src="./entry.js"></script>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div id="input-container">
<span id="input-label">Quizz id</span>
<input type="text" id="id" />
</div>
<div id="root"></div>
</body>
</html>

View file

@ -0,0 +1,8 @@
{
"devDependencies": {
"live-server": "^1.2.1"
},
"scripts": {
"dev": "live-server index.html"
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,41 @@
body,
html {
height: 100%;
padding: 0;
margin: 0;
background: #241b2f;
}
#input-container {
color: white;
padding: 1rem;
font-size: 1.7rem;
display: flex;
align-items: center;
}
#id {
margin: 1rem;
padding: 0.5rem;
background: transparent;
border: 1px solid white;
outline: none;
color: white;
}
.question-container {
padding: 0.7rem;
}
.question-container .question {
color: #1ad6d9;
}
.question-container .answer {
margin-top: 0.5rem;
color: #23e30e;
}
.answer.answer-single {
margin-left: 1.5rem;
}