Advertisement
tonyissocool

Edpuzzle auto doer picker upper

Sep 28th, 2022 (edited)
1,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function postRequest(url = "https://edpuzzle.com/api/v3/classrooms/6356dd65994d2a416ee2eef0/students", body, type = "json") {
  2.     return (await fetch(url, {
  3.         "headers": {
  4.             "content-type": "application/json",
  5.             "x-csrf-token": token,
  6.         },
  7.         "body": JSON.stringify(body),
  8.         "method": "POST",
  9.     }))[type]();
  10. }
  11. async function getAssignmentData() {
  12.     return (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/attempt`)).json();
  13. }
  14. async function getCSRFToken() {
  15.     return (await (await fetch("https://edpuzzle.com/api/v3/csrf")).json()).CSRFToken;
  16. }
  17. async function watch(timeIntervalNumber = 10) {
  18.     return postRequest(`https://edpuzzle.com/api/v4/media_attempts/${id}/watch`, { timeIntervalNumber }, "text");
  19. }
  20. async function getQuestions() {
  21.     return (await (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/questions`)).json()).questions;
  22. }
  23. async function answerQuestion(questionId, choices) {
  24.     return postRequest(`https://edpuzzle.com/api/v3/attempts/${id}/answers`, { answers: [{ type: "multiple-choice", questionId, choices }] });
  25. }
  26. async function getClass() {
  27.     return (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/classroom`)).json();
  28. }
  29. async function getClassData(id) {
  30.     return (await fetch(`https://edpuzzle.com/api/v3/assignments/classrooms/${id}/students`)).json();
  31. }
  32. var id, token, assignment, pageId = window.location.href.split("/")[4], questions, data, answers = {}, classroom, media;
  33. (async function () {
  34.     token = await getCSRFToken();
  35.     postRequest();
  36.     assignment = await getAssignmentData();
  37.     id = assignment._id;
  38.     for(var i=0;i<11;i++) if(!assignment.timeIntervals[i%11].views) watch(i%11);
  39.     questions = await getQuestions();
  40.     classroom = await getClass();
  41.     data = await getClassData(classroom._id);
  42.     media = data.medias.filter(media => media.teacherAssignments.find(a => a == pageId))[0];
  43.     media.questions.forEach(question => answers[question._id] = question);
  44.     console.warn(answers);
  45.     for (var question of questions) {
  46.         var answer = answers[question._id];
  47.         if (!answer || answer.type !== "multiple-choice" || question.choices.filter(choice => choice.isCorrect).length) continue;
  48.         var choices = answer.choices.filter(choice => choice.isCorrect);
  49.         console.warn(question.body[0].html, choices.map(choice => choice.body[0].html));
  50.         console.warn(await answerQuestion(question._id, choices.map(choice => choice._id)));
  51.     }
  52.     window.location.reload();
  53. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement