Last active
April 14, 2024 07:22
-
-
Save arnav-kr/586c4b8e80b280ebab3f91d3bb7dfdd0 to your computer and use it in GitHub Desktop.
Extract 2024 JEE Mains Score from Answer Key Challenge
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
| // to be run on the answer key challenge page after loggin into student dashboard (https://jeemain.ntaonline.in/*) | |
| // updated as per new answer key scheme | |
| let answerKey = {}; | |
| $$(".form-options-item").forEach(i => { | |
| let questionId = i.querySelector(".vcenter:nth-child(2)").innerHTML; | |
| let correct = i.querySelector(".vcenter:nth-child(3)").innerHTML; | |
| answerKey[questionId] = correct; | |
| }); | |
| copy(answerKey); |
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
| // After getting answerKey from above script, this is to be pasted in the console of devtools (ctrl + shift + j) opened in your response sheet page (https://cdn3.digialm.com//per/*) | |
| // updated as per new answer key scheme | |
| let answerKey = { | |
| // define the answer key here | |
| } | |
| let name = $$(".main-info-pnl")[0].querySelector("tr:nth-child(2)>td:last-child").innerHTML; | |
| let applicationNumber = $$(".main-info-pnl")[0].querySelector("tr:nth-child(1)>td:last-child").innerHTML; | |
| let rollNumber = $$(".main-info-pnl")[0].querySelector("tr:nth-child(3)>td:last-child").innerHTML; | |
| let testDate = $$(".main-info-pnl")[0].querySelector("tr:nth-child(4)>td:last-child").innerHTML; | |
| let responses = {}; | |
| $$("table.menu-tbl").forEach(t => { | |
| let questionType = t.querySelector("tr:nth-child(1)>td.bold").innerHTML; | |
| let questionId = t.querySelector("tr:nth-child(2)>td.bold").innerHTML; | |
| let answer = ""; | |
| if (questionType == "MCQ") { | |
| let choosenAns = t.querySelector(`tr:last-child>td.bold`).innerHTML.trim(); | |
| if (choosenAns == "--") { | |
| responses[questionId] = null; | |
| return; | |
| }; | |
| let choosenAnsId = t.querySelector(`tr:nth-child(${2 + parseInt(choosenAns)})>td.bold`).innerHTML.trim(); | |
| answer = choosenAnsId; | |
| } | |
| else { | |
| answer = t.parentElement.querySelector("table").querySelector("tr:last-child>td.bold").innerHTML.trim(); | |
| if (answer == "--") { | |
| responses[questionId] = null; | |
| return; | |
| } | |
| } | |
| responses[questionId] = answer; | |
| }) | |
| function getResults(answerKey) { | |
| let score = 0; | |
| let total = Object.keys(answerKey).length; | |
| let correct = 0; | |
| let incorrect = 0; | |
| let unanswered = 0; | |
| let commomPart = parseInt(Object.keys(answerKey).reduce((a, b) => a < b ? a : b)) - 1; | |
| let subjectWiseScore = { | |
| physics: { | |
| score: 0, | |
| total: 30, | |
| correct: 0, | |
| incorrect: 0, | |
| unanswered: 0 | |
| }, | |
| chemistry: { | |
| score: 0, | |
| total: 30, | |
| correct: 0, | |
| incorrect: 0, | |
| unanswered: 0 | |
| }, | |
| mathematics: { | |
| score: 0, | |
| total: 30, | |
| correct: 0, | |
| incorrect: 0, | |
| unanswered: 0 | |
| }, | |
| } | |
| for (let questionId in answerKey) { | |
| let questionNumber = parseInt(questionId) - commomPart; | |
| let questionRows = $$(".rw"); | |
| let currentQuestionRow = questionRows.filter(row => row.innerHTML.includes(questionId))[0]; | |
| let menuBox = currentQuestionRow.querySelector(".menu-tbl"); | |
| let correctAnswer = "" | |
| if (menuBox.innerHTML.includes("MCQ")) { | |
| let optionIds = []; | |
| for (let n = 3; n <= 6; n++) { | |
| optionIds.push(menuBox.querySelector(`tr:nth-child(${n})>td.bold`).innerHTML.trim()); | |
| } | |
| correctAnswer = optionIds.indexOf(answerKey[questionId]) + 1; | |
| } | |
| else { | |
| correctAnswer = answerKey[questionId]; | |
| } | |
| let tr = document.createElement("tr"); | |
| tr.innerHTML = `<td align="right">Correct Option:</td><td class="bold">${correctAnswer}</td>` | |
| menuBox.querySelector("tbody").appendChild(tr); | |
| if (responses[questionId] == null) { | |
| unanswered++; | |
| if (questionNumber <= 30) { | |
| // maths | |
| subjectWiseScore.mathematics.unanswered++; | |
| } | |
| else if (questionNumber <= 60 && questionNumber > 30) { | |
| // physics | |
| subjectWiseScore.physics.unanswered++; | |
| } | |
| else { | |
| // chemistry | |
| subjectWiseScore.chemistry.unanswered++; | |
| } | |
| } | |
| else if ((answerKey[questionId].toString() == responses[questionId].toString()) || (answerKey[questionId].toString().toLowerCase() == "drop")) { | |
| correct++; | |
| currentQuestionRow.style.background = "#4ADE80"; | |
| if (questionNumber <= 30) { | |
| // maths | |
| subjectWiseScore.mathematics.correct++; | |
| } | |
| else if (questionNumber <= 60 && questionNumber > 30) { | |
| // physics | |
| subjectWiseScore.physics.correct++; | |
| } | |
| else { | |
| // chemistry | |
| subjectWiseScore.chemistry.correct++; | |
| } | |
| } | |
| else { | |
| incorrect++; | |
| currentQuestionRow.style.background = "#F87171"; | |
| if (questionNumber <= 30) { | |
| // maths | |
| subjectWiseScore.mathematics.incorrect++; | |
| } | |
| else if (questionNumber <= 60 && questionNumber > 30) { | |
| // physics | |
| subjectWiseScore.physics.incorrect++; | |
| } | |
| else { | |
| // chemistry | |
| subjectWiseScore.chemistry.incorrect++; | |
| } | |
| } | |
| } | |
| score = (correct * 4) + (unanswered * 0) + (incorrect * -1); | |
| subjectWiseScore.physics.score = (subjectWiseScore.physics.correct * 4) + (subjectWiseScore.physics.unanswered * 0) + (subjectWiseScore.physics.incorrect * -1); | |
| subjectWiseScore.chemistry.score = (subjectWiseScore.chemistry.correct * 4) + (subjectWiseScore.chemistry.unanswered * 0) + (subjectWiseScore.chemistry.incorrect * -1); | |
| subjectWiseScore.mathematics.score = (subjectWiseScore.mathematics.correct * 4) + (subjectWiseScore.mathematics.unanswered * 0) + (subjectWiseScore.mathematics.incorrect * -1); | |
| return { | |
| studentDetails: { | |
| name, applicationNumber, rollNumber, testDate | |
| }, | |
| score, | |
| total, | |
| correct, | |
| incorrect, | |
| unanswered, | |
| subjectWiseScore, | |
| }; | |
| } | |
| let results = getResults(answerKey); | |
| console.log(results); | |
| copy(results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment