1
Fork 0

javascript(quizizz-hack): feat: website

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2020-11-05 09:44:45 +02:00 committed by prescientmoon
parent 71cb49a7e4
commit 9de9482700
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
7 changed files with 1412 additions and 103 deletions

View file

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

View file

@ -1,16 +1,6 @@
const fetch = require("node-fetch");
const chalk = require("chalk");
const { default: readline } = require("readline-promise");
import { render, html } from "https://cdn.skypack.dev/lit-html";
const id = process.argv[2];
const rlp = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true,
});
const tags = ["p", "strong", "em"];
const tags = ["p", "strong", "em", "sub", "sup", "span", "br"];
function removeTags(input) {
let copy = input.replace('"', '\\"');
@ -23,7 +13,7 @@ function removeTags(input) {
// 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 parseFile(fileObject) {
function parseQuestions(fileObject) {
const allAnswers = {};
for (const question of fileObject.data.quiz.info.questions) {
@ -59,51 +49,51 @@ function parseFile(fileObject) {
return allAnswers;
}
function printQuestion(question) {
console.log(chalk.italic(chalk.blue(question[0])));
console.log(chalk.green(question[1]));
}
async function repl(o) {
const answer = await rlp.questionAsync(">");
if (answer === "all") {
for (const question of o) {
printQuestion(question);
}
} else {
console.log(chalk.underline(answer));
for (const question of o) {
let ok = true;
for (let i = 0; i < question[0].length; i++) {
if (answer[i] === undefined) break;
if (question[0][i] !== answer[i]) {
ok = false;
break;
}
}
if (ok) {
printQuestion(question);
}
}
}
repl(o);
}
async function main() {
const res = await fetch(`https://quizizz.com/quiz/${id}`);
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 answers = parseFile(jsonObject);
const parsedJson = JSON.parse(jsonObject.contents);
console.log(parsedJson.data);
const answers = parseQuestions(parsedJson);
const sorted = Object.entries(answers).sort();
repl(sorted);
render(renderQuestions(sorted), rootElement);
}
main();
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);
}
});
console.log("here");
const renderQuestions = (questions) => {
return html`${questions.map(([question, answer]) => {
return html`
<div class="question-container">
<div class="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>
`;
})}`;
};

File diff suppressed because one or more lines are too long

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

@ -1 +1,8 @@
{"dependencies":{"chalk":"^4.1.0","node-fetch":"^2.6.1","readline-promise":"^1.0.4"}}
{
"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;
}