Study.com Quiz Answers

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

当前为 2021-04-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Study.com Quiz Answers
// @namespace   Violentmonkey Scripts
// @match       *://*.study.com/*
// @include     https://study.com/*
// @grant       none
// @version     1.1
// @author      Jonah Lawrence
// @description Highlights correct answers with a green background on Study.com quizes and exams
// ==/UserScript==

/* jshint esversion: 6 */

(function () {
  const interval = setInterval(function () {
    const container = document.querySelector("#practice-exam-container");
    // check if practice-exam-container element exists (only on exam pages)
    if (container) {
      const controller = angular.element(container).controller();
      if (controller) {
        // get questions
        const questions = controller.questionByQuestionInstanceId;
        // highlight the answer to each question
        Object.values(questions).forEach(function (x) {
          const correctAnswer = document.querySelector(`li[ng-class*="${x.correctQuizQuestionOptionId}"]`);
          if (correctAnswer) {
            correctAnswer.style.background = "#c5ff81";
            correctAnswer.style.borderRadius = "2px";
            correctAnswer.style.boxShadow = "0 0 0 6px #c5ff81";
            // no need to keep checking
            clearInterval(interval);
          }
        });
      }
    }
    else {
      // add styling for showing quiz answers
      const styles = 'label[data-correct="true"] { background: #c5ff81; box-shadow: 0 0 0 14px #c5ff81; }';
      document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", `<style>${styles}</style>`);
      // disable interval since this is not an exam
      clearInterval(interval);
    }
  }, 500);
})();