Study.com Quiz Answers

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

目前为 2022-02-28 提交的版本,查看 最新版本

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