AP Classroom Hide Correct MCQ Answer

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        AP Classroom Hide Correct MCQ Answer
// @namespace   Violentmonkey Scripts
// @match       *://apclassroom.collegeboard.org/*
// @grant       none
// @version     1.0
// @author      murpyh
// @license     MIT
// @description 3/23/2025, 11:51:22 AM
// ==/UserScript==

const css = `
.mcq-option.--correct ,
.mcq-option.--incorrect
{
  background-color: rgba(255,255,255,1) !important;
  border: 0 !important
}

.response-analysis-wrapper > .icon
{
  display: none;
}

.--chosen
{
  color: inherit !important;
  background-color: inherit !important;
}

.LearnosityDistractor
{
  display: none !important;
}
`;

// taken from https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                observer.disconnect();
                resolve(document.querySelector(selector));
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}

let toggle, style;

function onToggleAnswerShowClicked() {
  if (toggle.checked) {
    style.media = 'all';
  } else {
    style.media = 'not all';
  }
}

function initElements() {
  const head = document.head || document.getElementsByTagName('head')[0];
  style = document.createElement('style');

  head.appendChild(style);
  style.type = 'text/css';
  style.appendChild(document.createTextNode(css));

  toggle = document.createElement('input');
  toggle.type = 'checkbox';
  toggle.name = 'toggleShowAnswer';
  toggle.checked = true;
  toggle.onclick = onToggleAnswerShowClicked;

  const label = document.createElement('label');
  label.for = toggle;
  label.innerHTML = 'Hide correct answer';

  waitForElm('.RI_header').then((header) => {
    header.appendChild(toggle);
    header.appendChild(label);
  });
}

initElements();