Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function postRequest(url = "https://edpuzzle.com/api/v3/classrooms/6356dd65994d2a416ee2eef0/students", body, type = "json") {
- return (await fetch(url, {
- "headers": {
- "content-type": "application/json",
- "x-csrf-token": token,
- },
- "body": JSON.stringify(body),
- "method": "POST",
- }))[type]();
- }
- async function getAssignmentData() {
- return (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/attempt`)).json();
- }
- async function getCSRFToken() {
- return (await (await fetch("https://edpuzzle.com/api/v3/csrf")).json()).CSRFToken;
- }
- async function watch(timeIntervalNumber = 10) {
- return postRequest(`https://edpuzzle.com/api/v4/media_attempts/${id}/watch`, { timeIntervalNumber }, "text");
- }
- async function getQuestions() {
- return (await (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/questions`)).json()).questions;
- }
- async function answerQuestion(questionId, choices) {
- return postRequest(`https://edpuzzle.com/api/v3/attempts/${id}/answers`, { answers: [{ type: "multiple-choice", questionId, choices }] });
- }
- async function getClass() {
- return (await fetch(`https://edpuzzle.com/api/v3/assignments/${pageId}/classroom`)).json();
- }
- async function getClassData(id) {
- return (await fetch(`https://edpuzzle.com/api/v3/assignments/classrooms/${id}/students`)).json();
- }
- var id, token, assignment, pageId = window.location.href.split("/")[4], questions, data, answers = {}, classroom, media;
- (async function () {
- token = await getCSRFToken();
- postRequest();
- assignment = await getAssignmentData();
- id = assignment._id;
- for(var i=0;i<11;i++) if(!assignment.timeIntervals[i%11].views) watch(i%11);
- questions = await getQuestions();
- classroom = await getClass();
- data = await getClassData(classroom._id);
- media = data.medias.filter(media => media.teacherAssignments.find(a => a == pageId))[0];
- media.questions.forEach(question => answers[question._id] = question);
- console.warn(answers);
- for (var question of questions) {
- var answer = answers[question._id];
- if (!answer || answer.type !== "multiple-choice" || question.choices.filter(choice => choice.isCorrect).length) continue;
- var choices = answer.choices.filter(choice => choice.isCorrect);
- console.warn(question.body[0].html, choices.map(choice => choice.body[0].html));
- console.warn(await answerQuestion(question._id, choices.map(choice => choice._id)));
- }
- window.location.reload();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement