AP Classroom Hide Correct MCQ Answer

3/23/2025, 11:51:22 AM

  1. // ==UserScript==
  2. // @name AP Classroom Hide Correct MCQ Answer
  3. // @namespace Violentmonkey Scripts
  4. // @match *://apclassroom.collegeboard.org/*
  5. // @grant none
  6. // @version 1.0
  7. // @author murpyh
  8. // @license MIT
  9. // @description 3/23/2025, 11:51:22 AM
  10. // ==/UserScript==
  11.  
  12. const css = `
  13. .mcq-option.--correct ,
  14. .mcq-option.--incorrect
  15. {
  16. background-color: rgba(255,255,255,1) !important;
  17. border: 0 !important
  18. }
  19.  
  20. .response-analysis-wrapper > .icon
  21. {
  22. display: none;
  23. }
  24.  
  25. .--chosen
  26. {
  27. color: inherit !important;
  28. background-color: inherit !important;
  29. }
  30.  
  31. .LearnosityDistractor
  32. {
  33. display: none !important;
  34. }
  35. `;
  36.  
  37. // taken from https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
  38. function waitForElm(selector) {
  39. return new Promise(resolve => {
  40. if (document.querySelector(selector)) {
  41. return resolve(document.querySelector(selector));
  42. }
  43.  
  44. const observer = new MutationObserver(mutations => {
  45. if (document.querySelector(selector)) {
  46. observer.disconnect();
  47. resolve(document.querySelector(selector));
  48. }
  49. });
  50.  
  51. observer.observe(document.body, {
  52. childList: true,
  53. subtree: true
  54. });
  55. });
  56. }
  57.  
  58. let toggle, style;
  59.  
  60. function onToggleAnswerShowClicked() {
  61. if (toggle.checked) {
  62. style.media = 'all';
  63. } else {
  64. style.media = 'not all';
  65. }
  66. }
  67.  
  68. function initElements() {
  69. const head = document.head || document.getElementsByTagName('head')[0];
  70. style = document.createElement('style');
  71.  
  72. head.appendChild(style);
  73. style.type = 'text/css';
  74. style.appendChild(document.createTextNode(css));
  75.  
  76. toggle = document.createElement('input');
  77. toggle.type = 'checkbox';
  78. toggle.name = 'toggleShowAnswer';
  79. toggle.checked = true;
  80. toggle.onclick = onToggleAnswerShowClicked;
  81.  
  82. const label = document.createElement('label');
  83. label.for = toggle;
  84. label.innerHTML = 'Hide correct answer';
  85.  
  86. waitForElm('.RI_header').then((header) => {
  87. header.appendChild(toggle);
  88. header.appendChild(label);
  89. });
  90. }
  91.  
  92. initElements();
  93.