Add
This commit is contained in:
commit
552432ff41
1
javascript/quizizz-hack/.gitignore
vendored
Normal file
1
javascript/quizizz-hack/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
5
javascript/quizizz-hack/.vscode/settings.json
vendored
Normal file
5
javascript/quizizz-hack/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"BFBQC"
|
||||||
|
]
|
||||||
|
}
|
1
javascript/quizizz-hack/README.md
Normal file
1
javascript/quizizz-hack/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# 🚧 This repo has been moved to [prescientmoon/quizz-hack](https://github.com/prescientmoon/quizz-hack) 🚧
|
106
javascript/quizizz-hack/entry.js
Normal file
106
javascript/quizizz-hack/entry.js
Normal 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>
|
||||||
|
`;
|
||||||
|
})}`;
|
||||||
|
};
|
17
javascript/quizizz-hack/index.html
Normal file
17
javascript/quizizz-hack/index.html
Normal 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>
|
8
javascript/quizizz-hack/package.json
Normal file
8
javascript/quizizz-hack/package.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"live-server": "^1.2.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "live-server index.html"
|
||||||
|
}
|
||||||
|
}
|
1313
javascript/quizizz-hack/pnpm-lock.yaml
Normal file
1313
javascript/quizizz-hack/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
41
javascript/quizizz-hack/style.css
Normal file
41
javascript/quizizz-hack/style.css
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue