Study.com Quiz Answers

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

Versione datata 07/04/2021. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Study.com Quiz Answers
// @namespace   Violentmonkey Scripts
// @match       *://*.study.com/*
// @include     https://study.com/*
// @grant       none
// @version     1.2
// @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 () {
    // add styling for highlighting quiz answers
    // quiz answers will at this point already be highlighted since they have this attribute
    const styles = '[data-correct="true"] { background: #c5ff81; box-shadow: 0 0 0 14px #c5ff81; border-radius: 2px; }';
    document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", `<style>${styles}</style>`);
    // get exam container
    const container = document.querySelector("#practice-exam-container");
    // check if 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) {
            // mark answer as correct so it can be highlighted
            correctAnswer.setAttribute("data-correct", "true");
            // no need to keep checking
            clearInterval(interval);
          }
        });
      }
    }
    else {
      // disable interval since this is not an exam
      clearInterval(interval);
    }
  }, 500);
})();