Last active
October 24, 2020 19:54
-
-
Save Chovin/21df06540d574fa127211b76afca6030 to your computer and use it in GitHub Desktop.
Turn Udemy's review pages into flashcards by skipping the test, opening devtools, then pasting this in console
This file contains 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
function addCSSRule(selector, rules, index) { | |
if (!window.the_added_sheet) { | |
style = document.createElement('style') | |
style.appendChild(document.createTextNode("")) | |
document.head.appendChild(style) | |
if ("insertRule" in sheet) { | |
sheet.insertRule(selector + "{" + rules + "}", index); | |
} else if ("addRule" in sheet) { | |
sheet.addRule(selector, rules, index); | |
} | |
window.the_added_sheet = style.sheet | |
sheet = the_added_sheet; | |
} | |
} | |
addCSSRule('div[class*="--correct--"]', "background-color: transparent !important;") | |
addCSSRule('[data-completed=true] div[class*="--correct--"]', "background-color: #e9f7f1 !important;"); | |
addCSSRule( | |
'div[class*="--correct--"] div[class^="mc-quiz-answer--correctness--"], [data-hidden-explanation=true], span[class^="mc-quiz-question--skipped--"]', | |
"display: none;" | |
); | |
addCSSRule( | |
'[data-completed=true] div[class*="--correct--"] div[class^="mc-quiz-answer--correctness--"]', | |
"display: inline !important;" | |
); | |
function bumpTotal() { | |
document.querySelectorAll('[class*="detailed-result-panel--question-container--"]').forEach((q, i) => { | |
correct = true | |
q.querySelectorAll('div[class*="--correct--"] input').forEach((ip) => { | |
if (!ip.checked) { | |
correct = false | |
} | |
}) | |
quiz_total[i] = correct | |
nqs = Object.keys(quiz_total).length; | |
correct = Object.values(quiz_total).filter(t => t).length; | |
document.querySelector('.final-total').innerHTML = `Total correct: <b>${correct}</b> / ${nqs}` | |
}) | |
} | |
function revealFactory(question) { | |
return () => { | |
bumpTotal(); | |
question.querySelector('[class^="mc-quiz-question--explanation--"]').removeAttribute('data-hidden-explanation'); | |
question.setAttribute('data-completed', true); | |
} | |
} | |
function setupQuiz() { | |
document.querySelectorAll('[class*="detailed-result-panel--question-container--"]').forEach((q, i) => { | |
q.removeAttribute("data-completed"); | |
q.querySelector('[class^="mc-quiz-question--explanation--"]').setAttribute('data-hidden-explanation', true) | |
q.querySelectorAll('input[name="answer"]').forEach((input) => {input.disabled = false; input.checked = false; input.onclick = revealFactory(q)}) | |
}) | |
window.quiz_total = {} | |
if (document.querySelector('.final-total')) { | |
total = document.querySelector(".final-total"); | |
} else { | |
total = document.createElement('div') | |
total.className = 'final-total' | |
document.querySelector('[class*="footer__center"').appendChild(total); | |
} | |
bumpTotal() | |
} | |
setupQuiz() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment