CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/src/index.ts
Views: 2223
/*1Quizizz-cheat2Copyright (C) gbaranski34This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.56This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.78You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.910github repository: https://github.com/gbaranski/quizizz-cheat11email: [email protected]12*/1314151617import { VueElement, QuizQuestion, QuizInfo } from "./types";1819const getQuestionsElement = () => {20const questionsElem = document.querySelector(21"body > div > div.root-component > div > div > div > div.page-container.in-quiz > div.screen.screen-game > div.transitioner.transitioner-component > div > div > div > div > div > div.options-container > div"22);23if (!questionsElem)24throw new Error("Unable to retreive questions list element");2526return questionsElem;27};2829const changeElementOpacity = (elem: HTMLElement) => {30elem.style.opacity = "20%";31};3233const highlightAnswers = (question: QuizQuestion) => {34const questionsElem = getQuestionsElement();35const arr: VueElement[] = Array.prototype.slice.call(questionsElem.children);3637if (Array.isArray(question.structure.answer) && question.structure.answer.length < 1 && question.structure.options) {38const answers = question.structure.options.map((option) => option.text).join(" or ");39alert(answers);4041return;42}4344arr.filter((e) => {45if (Array.isArray(question.structure.answer) && question.structure.answer.length > 0) {46return !(question.structure.answer.some((ansID) => e.__vue__.optionData.actualIndex === ansID));47} else if(typeof question.structure.answer == "number") {48return e.__vue__.optionData.actualIndex !== question.structure.answer49} else {50console.error("Fail detecting type of question: ", question);51}52}).forEach(changeElementOpacity);53}5455const getQuestionInfo = (): {56questionID: string;57roomHash: string;58playerId: string;59quizID: string;60roomCode: string;61} => {62const rootObject = document.querySelector("body > div") as VueElement | null;63if (!rootObject) throw new Error("Could not retrieve root object");64const vue = rootObject.__vue__;6566return {67roomHash: vue.$store._vm._data.$$state.game.data.roomHash,68playerId: vue.$store._vm._data.$$state.game.player.playerId,69quizID: vue.$store._vm._data.$$state.game.data.quizId,70roomCode: vue.$store._vm._data.$$state.game.data.roomCode,71questionID: vue.$store._vm._data.$$state.game.questions.currentId,72};73};7475const getRoomHash = (): string => {76const rootObject = document.querySelector("body > div") as VueElement | null;77if (!rootObject) throw new Error("Could not retrieve root object");78const vue = rootObject.__vue__;7980return vue.$store._vm._data.$$state.game.data.roomHash;81}8283const msg = `%c84Script created by gbaranski#5119!85https://github.com/gbaranski/quizizz-cheat86`;878889(async () => {90console.log(msg, "color: red;");9192const quiz: QuizInfo = await (await fetch(`https://quizizz.com/_api/main/game/${getRoomHash()}`)).json();9394let lastQuestionID: string | undefined = undefined;9596setInterval(() => {97const questionInfo = getQuestionInfo();98if (questionInfo.questionID !== lastQuestionID) {99for (const q of quiz.data.questions) {100if (questionInfo.questionID === q._id) {101console.log({q});102highlightAnswers(q);103lastQuestionID = questionInfo.questionID;104}105}106}107}, 500)108109})();110111112