Skip to content

Instantly share code, notes, and snippets.

@PlanetTheCloud
Last active April 13, 2022 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlanetTheCloud/445b0f50ee675c88e4767234b9fddb6f to your computer and use it in GitHub Desktop.
Save PlanetTheCloud/445b0f50ee675c88e4767234b9fddb6f to your computer and use it in GitHub Desktop.
Calculate Accuracy Score in Google Forms
var GoogleFormsTool = {
getScore() {
let correct = document.getElementsByClassName('freebirdFormviewerViewItemsItemCorrect'),
incorrect = document.getElementsByClassName('freebirdFormviewerViewItemsItemIncorrect'),
total = correct.length + incorrect.length,
incorrectDisplay = [],
yIncrement = 0;
for (let k of incorrect) {
k.parentElement.id = "gfcs_incorrect_" + yIncrement++;
incorrectDisplay.push({
id: k.parentElement.id,
text: k.innerText.trim()
});
}
if (total === 0) {
return false;
}
return {
correctCount: correct.length,
incorrectCount: incorrect.length,
incorrectDisplay: incorrectDisplay,
totalCount: total,
score: Number(((correct.length / total) * 100).toFixed(2))
};
},
displayScore() {
let score = this.getScore();
if (!score) {
return;
}
document.querySelectorAll('[role="listitem"]')[0].innerHTML += `<div class="freebirdFormviewerViewItemsItemItem freebirdFormviewerViewItemsTextTextItem">
<h1 style="margin-top:0%">Score: ${score.score.toFixed(0)}</h1>
<hr>
<ul>
<li>Correct: <b>${score.correctCount}</b></li>
<li>Incorrect: <b>${score.incorrectCount}</b></li>
<li>Question Count: <b>${score.totalCount}</b></li>
<li>Score: <b>${score.score}</b></li>
</ul>
<hr>
<h3>Incorrect Answers</h2>
<ul>
${score.incorrectDisplay.map(i => `<li><a href="#${i.id}">${i.text}</a></li>`).join('')}
</ul>
</div>`;
},
run() {
if (window.location.pathname.split('/').pop() === 'viewscore') {
setTimeout(() => {
this.displayScore();
}, 1000);
}
}
}
GoogleFormsTool.run();
@PlanetTheCloud
Copy link
Author

PlanetTheCloud commented Aug 28, 2021

Here's a screenshot:
image
It will only show on the view score page after 1 second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment