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(//, ""); let div = document.createElement("div"); div.innerHTML = html; let form = div.querySelector("form"); let input = document.createElement("input") input.setAttribute("type", "hidden"); input.setAttribute("name", "ext_submit"); input.setAttribute("value", "Submit"); form.append(input); document.body.append(div); //submit form in new tab form.setAttribute("target", "_blank"); form.submit(); div.remove(); }); } function getAssignment(callback) { var assignment_id = window.location.href.split("/")[4]; if (typeof assignment_id == "undefined") { alert("Error: Could not infer the assignment ID. Are you on the correct URL?"); return; } var url1 = "https://edpuzzle.com/api/v3/assignments/"+assignment_id; http_get(url1, function(){ var assignment = JSON.parse(this.responseText); if ((""+this.status)[0] == "2") { openPopup(assignment); } else { alert(`Error: Status code ${this.status} recieved when attempting to fetch the assignment data.`) } }); } function openPopup(assignment) { var media = assignment.medias[0]; var teacher_assignment = assignment.teacherAssignments[0]; var assigned_date = new Date(teacher_assignment.preferences.startDate); var date = new Date(media.createdAt); thumbnail = media.thumbnailURL; if (thumbnail.startsWith("/")) { thumbnail = "https://"+window.location.hostname+thumbnail; } var deadline_text; if (teacher_assignment.preferences.dueDate == "") { deadline_text = "no due date" } else { deadline_text = "due on "+(new Date(teacher_assignment.preferences.dueDate)).toDateString(); } var base_html = ` Answers for: ${media.title}

${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 questions[j+1].time){ let question_old = questions[j]; questions[j] = questions[j + 1]; questions[j+1] = question_old; } } } for (let i=0; i${question.body[0].text}

`; } else { question_content = question.body[0].html; } let answer_exists = false; for (let j=0; j${choice.body[0].text}

`; } else { item_html = `${choice.body[0].html}`; } if (choice.isCorrect == true) { choices_lines.push(`
  • ${item_html}
  • `); answer_exists = true; } else { choices_lines.push(`
  • ${item_html}
  • `); } } } if (!answer_exists) continue; let choices_html = choices_lines.join("\n"); let table = `` if (counter2 != 0) { table += `
    `; } table += `

    [${timestamp}]

    ${question_content}
      ${choices_html}
    `; content.innerHTML += table; counter2++; } } popup.document.getElementById("skipper").disabled = false; if (counter == 0 || counter2 == 0) { content.innerHTML += `

    No valid multiple choice questions were found.

    `; } else { popup.document.getElementById("answers_button").disabled = false; } popup.questions = questions; } init();