Advertisement
RedstoneKing106

Untitled

Nov 20th, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Edpuzzle Helper
  3. // @version 1
  4. // @description Gets answers for multiple choices!
  5. // @author Prime
  6. // @match *://edpuzzle.com/assignments/*
  7. // @run-at document-end
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. let tries = 0;
  12. let isSuccess = false;
  13.  
  14.  
  15. function getAssignment() {
  16. console.log(`[✔️] got the assignment id`)
  17. return new URL(document.URL).pathname.split("/")[2];
  18. }
  19.  
  20.  
  21. function sendRequest() {
  22. if (tries == 3) {
  23. console.log(`[Edpuzzle] something went wrong..`);
  24. return;
  25. }
  26. const edpuzzle = new XMLHttpRequest();
  27. edpuzzle.open('GET', `https://edpuzzle.com/api/v3/assignments/${getAssignment()}`, true);
  28.  
  29. edpuzzle.onerror = data => {
  30. isSuccess = false;
  31. tries++;
  32. console.log(`[❌] retrying..`);
  33. sendRequest();
  34. }
  35.  
  36. edpuzzle.onload = data => {
  37. parseData(edpuzzle.response);
  38. }
  39.  
  40. edpuzzle.send();
  41. }
  42.  
  43. function parseData(unParsed) {
  44. console.clear();
  45. let data = JSON.parse(unParsed);
  46. console.log(`[✔️] Got the answers! 😉`);
  47. data.medias[0].questions.forEach(questions => {
  48. if (questions.type.includes("multiple")) {
  49. questions.choices.forEach(choice => {
  50. if(choice.isCorrect) {
  51. console.log(`Q: ${questions.body[0].text}
  52. A: ${choice.body[0].html}
  53. `)
  54. }
  55. });
  56. }
  57. });
  58. }
  59.  
  60.  
  61. setTimeout(() => {
  62. console.clear();
  63. sendRequest();
  64. }, 1000);
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement