Study.com Quiz Answers

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

安装此脚本?
作者推荐脚本

您可能也喜欢[PATCHED] Symbolab Pro

安装此脚本
  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.4.0
  8. // @author Jonah Lawrence
  9. // @description Highlights correct answers with a green background on Study.com quizes and exams
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. /* jshint esversion: 6 */
  14.  
  15. (function () {
  16. // add styling for highlighting correct 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 the element exists (only on exam pages)
  23. if (!container) {
  24. // exit function since this is not an exam
  25. return;
  26. }
  27. const interval = setInterval(function () {
  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 =
  37. document.querySelector(`li[ng-class*="${x.correctQuizQuestionOptionId}"]`) ||
  38. document.querySelector(`input[id$="${x.correctQuizQuestionOptionId}"]`).closest("li");
  39. // check that element for the correct answer exists on the page
  40. if (correctAnswer) {
  41. // mark answer as correct so it can be highlighted
  42. correctAnswer.dataset.correct = true;
  43. // no need to keep checking
  44. clearInterval(interval);
  45. }
  46. });
  47. }
  48. }, 500);
  49. })();