Skip to content

Instantly share code, notes, and snippets.

View NateLevin1's full-sized avatar

Nate Levin NateLevin1

View GitHub Profile
@NateLevin1
NateLevin1 / ! Canvas Quiz To JSON.md
Last active May 30, 2022 02:25
Convert Canvas quiz results to JSON instantly!

Canvas Quiz -> JSON Converter

To run, copy and paste the script below into the browser console on the quiz results page, then click enter to execute. It will automatically skip any non-multiple choice questions.

// copy+paste into browser devtools to execute -- see canvasquiztojson.js for non-minifed version
{const e=document.getElementsByClassName("question"),t=[];for(const o of e){if(!o.classList.contains("multiple_choice_question")){console.warn("Encountered non-multiple choice question. Skipping!");continue}const e=o.id.replace("question_",""),r=o.classList.contains("correct"),s=o.querySelector(".text"),n=s.querySelector(".question_text"),c=n.textContent.trim(),l=Array.from(n.querySelectorAll("img")).map(e=>e.src),i=s.querySelector(".answers").querySelector(".answers_wrapper").querySelectorAll(".answer"),a=[];for(const e of i){const t=e.querySelector(".select_answer").querySelector("label").querySelector(".answer_text").textContent,o=e.classList.contains("correct_answer");a.push({text:t,correct:o