Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inomdzhon/ab7c9b6ca6dd7981aeb51e605f87de91 to your computer and use it in GitHub Desktop.
Save inomdzhon/ab7c9b6ca6dd7981aeb51e605f87de91 to your computer and use it in GitHub Desktop.
Script for collect all incorrect answers from https://quiz.typeofnan.dev/
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