javascript:script=document.createElement("script");script.src="https://cdn.rawgit.com/wlib/0d4c68436f7930a8804a109afe484317/raw/quizletTestAnswers.js";document.body.appendChild(script);//
Last active
November 19, 2019 00:51
-
-
Save wlib/0d4c68436f7930a8804a109afe484317 to your computer and use it in GitHub Desktop.
Toggle quizlet test answers on and off every time you press the escape key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Answers aren't being displayed yet | |
let isDisplayed = false; | |
// Map of terms; word: definition | |
const answers = Quizlet.TestModeData.terms.reduce((termsMap, term) => { | |
termsMap[term.word] = term.definition; | |
return termsMap; | |
}, {}); | |
// Make a pretty-printed string to display | |
const answersString = JSON.stringify(answers, null, 2).replace(/\"/g, "").replace(/[{}]/g, ""); | |
// Grab an element to display to | |
const answersContainer = document.querySelector(".ModeControls-main"); | |
// Get that element's state so we can return to it later | |
const hiddenState = answersContainer.innerHTML; | |
// Make sure text fits and we can scroll if it doesn't | |
answersContainer.style.fontSize = "0.8em"; | |
answersContainer.style.overflow = "auto" | |
const toggle = () => { | |
if (isDisplayed) { | |
answersContainer.innerText = answersString; | |
} else { | |
answersContainer.innerHTML = hiddenState; | |
} | |
return isDisplayed = !isDisplayed; | |
} | |
// Switch between hiding and showing answers by pressing the ESCAPE key | |
document.body.addEventListener("keydown", e => { | |
if (e.key === "Escape") { | |
toggle(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super useful script :)