Created
May 4, 2020 13:41
-
-
Save inomdzhon/ab7c9b6ca6dd7981aeb51e605f87de91 to your computer and use it in GitHub Desktop.
Script for collect all incorrect answers from https://quiz.typeofnan.dev/
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 collectIncorrectAnswersAndCopyToBuffer(withSpoiler) { | |
const elsList = document.querySelector('main > ol'); | |
function getAnswerFromStorage(key) { | |
const value = localStorage.getItem(key); | |
if (!value) { | |
return 'Unknown'; | |
} | |
try { | |
const parsedValue = JSON.parse(value); | |
return parsedValue.selectedAnswer; | |
} catch(e) { | |
throw e; | |
} | |
} | |
const arrOfIncorrectAnswer = Array.prototype.reduce.call(elsList.children, (acc,el,index)=>{ | |
const isIncorrect = !!el.querySelector('i.icon.times'); | |
if (isIncorrect) { | |
const elLink = el.querySelector('a'); | |
const title = elLink.textContent; | |
let result = `${index + 1}: [${title}](${elLink.href})`; | |
if (withSpoiler) { | |
const answer = getAnswerFromStorage(title); | |
result += '\n\n'; | |
result += `<details><summary>Spoiler! Selected answer.</summary>${answer}</details>`; | |
} | |
acc.push(result); | |
} | |
return acc; | |
} | |
, ['# Think about your behavior!<br />']); | |
copy(arrOfIncorrectAnswer.join('\n\n')); | |
} | |
collectIncorrectAnswersAndCopyToBuffer() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment