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 Violentmonkey Scripts
  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. const controller = angular.element(container).controller();
  25. if (controller) {
  26. // get questions
  27. const questions = controller.questionByQuestionInstanceId;
  28. // highlight the answer to each question
  29. Object.values(questions).forEach(function (x) {
  30. const correctAnswer = document.querySelector(`li[ng-class*="${x.correctQuizQuestionOptionId}"]`);
  31. if (correctAnswer) {
  32. // mark answer as correct so it can be highlighted
  33. correctAnswer.setAttribute("data-correct", "true");
  34. // no need to keep checking
  35. clearInterval(interval);
  36. }
  37. });
  38. }
  39. }
  40. else {
  41. // disable interval since this is not an exam
  42. clearInterval(interval);
  43. }
  44. }, 500);
  45. })();