Last active
December 10, 2024 04:27
-
-
Save jacc/da9666994e7286c9de0b6ebad36dd526 to your computer and use it in GitHub Desktop.
Download all questions and (correct) answers from a Canvas quiz to a text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cleanText(e){return e.trim().replace(/\s+/g," ")}function downloadText(e){const t=new Blob([e],{type:"text/plain"}),o=window.URL.createObjectURL(t),n=document.createElement("a");n.href=o,n.download=document.querySelector("#quiz_title").textContent.trim().replace(/\s+/g," ").replace(/[^a-z0-9]/gi,"_").toLowerCase()+".txt",document.body.appendChild(n),n.click(),document.body.removeChild(n),window.URL.revokeObjectURL(o)}let questions=document.querySelectorAll(".question_text.user_content"),output=[];questions.forEach(e=>{let t=cleanText(e.textContent),o=e.closest(".question").querySelector(".answers_wrapper").querySelector('div[class*="correct_answer"]');if(o){let e=o.querySelector(".answer_text");if(e){let o=cleanText(e.textContent);output.push(`${t} - ${o}`)}}}),output.length>0&&downloadText(output.join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment