Study.com Quiz Answers

Highlights correct answers with a green background on Study.com quizes and exams

目前為 2021-04-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Study.com Quiz Answers
  3. // @namespace https://greasyfork.org/en/users/668659-denvercoder1
  4. // @match *://*.study.com/*
  5. // @include https://study.com/*
  6. // @grant none
  7. // @version 1.2
  8. // @author Jonah Lawrence
  9. // @description Highlights correct answers with a green background on Study.com quizes and exams
  10. // ==/UserScript==
  11.  
  12. /* jshint esversion: 6 */
  13.  
  14. (function () {
  15. const interval = setInterval(function () {
  16. // add styling for highlighting quiz answers
  17. // quiz answers will at this point already be highlighted since they have this attribute
  18. const styles = '[data-correct="true"] { background: #c5ff81; box-shadow: 0 0 0 14px #c5ff81; border-radius: 2px; }';
  19. document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", `<style>${styles}</style>`);
  20. // get exam container
  21. const container = document.querySelector("#practice-exam-container");
  22. // check if element exists (only on exam pages)
  23. if (!container) {
  24. // disable interval since this is not an exam
  25. return clearInterval(interval);
  26. }
  27. // if this is an exam, get the controller
  28. const controller = angular.element(container).controller();
  29. // wait for controller to be loaded
  30. if (controller) {
  31. // get questions
  32. const questions = controller.questionByQuestionInstanceId;
  33. // highlight the answer to each question
  34. Object.values(questions).forEach(function (x) {
  35. const correctAnswer = document.querySelector(`li[ng-class*="${x.correctQuizQuestionOptionId}"]`);
  36. // check that element for the correct answer exists on the page
  37. if (correctAnswer) {
  38. // mark answer as correct so it can be highlighted
  39. correctAnswer.setAttribute("data-correct", "true");
  40. // no need to keep checking
  41. clearInterval(interval);
  42. }
  43. });
  44. }
  45. }, 500);
  46. })();