Last active
April 13, 2022 01:51
-
-
Save PlanetTheCloud/445b0f50ee675c88e4767234b9fddb6f to your computer and use it in GitHub Desktop.
Calculate Accuracy Score in Google Forms
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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a screenshot:

It will only show on the view score page after 1 second.