var popup = null; var base_url; if (typeof document.dev_env != "undefined") { base_url = document.dev_env; } else { //get resources off of github to not inflate the jsdelivr stats base_url = "https://raw.githubusercontent.com/ading2210/edpuzzle-answers/main"; } function http_get(url, callback, headers=[], method="GET", content=null) { var request = new XMLHttpRequest(); request.addEventListener("load", callback); request.open(method, url, true); if (window.__EDPUZZLE_DATA__ && window.__EDPUZZLE_DATA__.token) { headers.push(["authorization", window.__EDPUZZLE_DATA__.token]); } for (const header of headers) { request.setRequestHeader(header[0], header[1]); } request.send(content); } function init() { if (window.location.hostname == "edpuzzle.hs.vc") { alert("To use this, drag this button into your bookmarks bar. Then, run it when you're on an Edpuzzle assignment."); } else if ((/https{0,1}:\/\/edpuzzle.com\/assignments\/[a-f0-9]{1,30}\/watch/).test(window.location.href)) { getAssignment(); } else if (window.canvasReadyState) { handleCanvasURL(); } else if (window.schoologyMoreLess) { handleSchoologyURL(); } else { alert("Please run this script on an Edpuzzle assignment. For reference, the URL should look like this:\nhttps://edpuzzle.com/assignments/{ASSIGNMENT_ID}/watch"); } } function handleCanvasURL() { let location_split = window.location.href.split("/"); let url = `/api/v1/courses/${location_split[4]}/assignments/${location_split[6]}`; http_get(url, function(){ let data = JSON.parse(this.responseText); let url2 = data.url; http_get(url2, function() { let data = JSON.parse(this.responseText); let url3 = data.url; alert(`Please re-run this script in the newly opened tab. If nothing happens, then allow popups on Canvas and try again.`); open(url3); }); }); } function handleSchoologyURL() { let assignment_id = window.location.href.split("/")[4]; let url = `/external_tool/${assignment_id}/launch/iframe`; http_get(url, function() { alert(`Please re-run this script in the newly opened tab. If nothing happens, then allow popups on Schoology and try again.`); //strip js tags from response and add to dom let html = this.responseText.replace(/
${media.title}
Uploaded by ${media.user.name} on ${date.toDateString()}
Assigned on ${assigned_date.toDateString()}, ${deadline_text}
Correct choices are underlined.
Made by: ading2210 on Github | Website: edpuzzle.hs.vc | Source code: ading2210/edpuzzle-answers
Licenced under the GNU GPL v3. Do not reupload or redistribute without abiding by those terms.
Available now from our Discord server: An open beta of a completely overhauled GUI, with proper mobile support, ChatGPT integration for open-ended questions, and more.
`; popup = window.open("about:blank", "", "width=600, height=400"); popup.document.write(base_html); popup.document.assignment = assignment; popup.document.dev_env = document.dev_env; popup.document.edpuzzle_data = window.__EDPUZZLE_DATA__; getMedia(assignment); } function getMedia(assignment) { var text = popup.document.getElementById("loading_text"); text.innerHTML = `Fetching assignments...`; var media_id = assignment.teacherAssignments[0].contentId; var url2 = `https://edpuzzle.com/api/v3/media/${media_id}`; fetch(url2, {credentials: "omit"}) .then(response => { if (!response.ok) { var text = popup.document.getElementById("loading_text"); var content = popup.document.getElementById("content"); popup.document.questions = questions; text.remove(); content.innerHTML += `Error: Status code ${response.status} received when attempting to fetch the answers.`; } else return response.json(); }) .then(media => { parseQuestions(media.questions); }) } function parseQuestions(questions) { var text = popup.document.getElementById("loading_text"); var content = popup.document.getElementById("content"); popup.document.questions = questions; text.remove(); if (questions == null) { content.innerHTML += `Error: Could not get the media for this assignment.
`; return; } var question; var counter = 0; var counter2 = 0; for (let i=0; i|
[${timestamp}] |
${question_content} |
|
No valid multiple choice questions were found.
`; } else { popup.document.getElementById("answers_button").disabled = false; } popup.questions = questions; } init();