Skip to content

Instantly share code, notes, and snippets.

@KorigamiK
Last active August 4, 2022 18:46
Show Gist options
  • Save KorigamiK/7b3e51a06c7be34ec47b8dc0d29c2502 to your computer and use it in GitHub Desktop.
Save KorigamiK/7b3e51a06c7be34ec47b8dc0d29c2502 to your computer and use it in GitHub Desktop.
This script will calculate your marks of jee mains from their website. The steps and usage is mentioned in the script
/*
USAGE:
1. Go to `Display Question paper and answer key` on the jeemain.nta.nic.in and log in
2. Open the question paper and the answer key in two different tabs on your browser
3. Question Paper should be a `digialm.com` webspage and the answer key would be a `testservices.nic.in` site
4. Open the developer tools on both the tabs (`ctrl + shift + I` or `F12` is a shortcut for this)
5. Go to the console tab in the developer tools of each tab
6. Now open the question paper tab
7. Copy and then PASTE this file from the start and end of `Get Answers` on the console tab. Press enter
8. Now right click the output that you see and click `Copy Object`
9. Now got the the answer key tab of the browser
10. Now type `answered = ` and then paste what you copied. Press enter
11. Copy, Paste and enter till the start and end of `Get Corrrect Answers` in this file
12. Copy, Paste and enter till the start and end of `Calculate Marks` in this file
13. You get the marks
*/
// START Get Answers
var get_answered = () => {
let answers = []
for (let table of document.querySelectorAll('table.menu-tbl > tbody')) {
let question_id = table.querySelector('tr:nth-child(2) > td:nth-child(2)').textContent
let question_type = table.querySelector('tr:nth-child(1) > td:nth-child(2)').textContent
if (question_type == 'SUBJECTIVE') continue
if (question_type !== 'MCQ') {
let status = table.querySelector('tr:nth-last-child(1) > td:nth-child(2)').textContent
let integer_answer = table.parentElement.parentElement.querySelector('.questionRowTbl > tbody > tr:last-child > td:last-child').textContent
answers.push({
question_id: question_id,
question_type: question_type,
status: status,
integer_answer: integer_answer
})
continue
}
let chosen_option_number = table.querySelector('tr:last-child > td:last-child').textContent
let chosen_option
if (!chosen_option_number.includes('--')) {
chosen_option = table.querySelector(`tr:nth-child(${2 + parseInt(chosen_option_number)}) > td:last-child`).textContent
} else {
chosen_option = null
}
let status = table.querySelector('tr:nth-last-child(2) > td:nth-child(2)').textContent
answers.push({
question_id: question_id,
question_type: question_type,
chosen_option: chosen_option,
status: status
})
}
return answers
}
get_answered()
// END Get Answers
// START Get Corrrect Answers
var get_correct_answers = () => {
var table = document.querySelector('#ctl00_LoginContent_grAnswerKey.table.table-bordered.table-condensed tbody')
const content = table = table.querySelectorAll('tr:not(tr:nth-child(1))')
correct_answers = {}
for (let row of content) {
let question_id = row.querySelector('span[id$=QuestionNo]').textContent
let answer = row.querySelector('span[id$=Answer]').textContent
correct_answers[question_id] = answer
}
return correct_answers
}
var correct_answers = get_correct_answers()
// END Get Correct Answers
// START Calculate Marks
var get_marks = () => {
index = 0
marks = []
for (let answered of answers) {
if (answered.status !== 'Answered' && answered.status !== 'Marked For Review') {
marks.push([0, answered.question_id])
continue
}
if (answered.question_type.includes('MCQ')) {
if (correct_answers[answered.question_id] === answered.chosen_option) {
marks.push([4, answered.question_id])
} else {
marks.push([-1, answered.question_id])
}
} else {
if (correct_answers[answered.question_id] === answered.integer_answer) {
marks.push([4, answered.question_id])
} else {
marks.push([0, answered.question_id])
}
}
marks[index].push(correct_answers[answered.question_id])
index++
}
console.log(marks)
console.log('You got: ', marks.reduce((a, b) => a + b[0], 0), ' Marks')
return marks
}
var marks = get_marks()
// END Calculate Marks
// START Add marks to the questions
var add_marks = () => {
let i = 0
for (let table of document.querySelectorAll('table.menu-tbl > tbody')) {
let id_row = table.insertRow()
let correct_row = table.insertRow()
let new_row = table.insertRow()
new_row.innerHTML = `<td align="right">Marks Obtained :</td><td class="bold">${marks[i][0]}</td>`
correct_row.innerHTML = `<td align="right">Correct Answer :</td><td class="bold">${marks[i][2]}</td>`
id_row.innerHTML = `<td align="right">Checked against ID :</td><td class="bold">${marks[i][1]}</td>`
try {
option = ''
let x = []
for (let e = 0; e < [0,1,2,3].length; e++) {
const element = [0,1,2,3][e];
if (table.querySelector(`tr:nth-child(${3 + e}) > td:last-child`).textContent === marks[i][2]) {
x.push(e + 1)
break
}
}
correct_row.innerHTML = `<td align="right">Correct Answer :</td><td class="bold">option-${x[0]} ${marks[i][2]}</td>`
} catch (e) { }
i++
}
}
add_marks()
//
@KorigamiK
Copy link
Author

Tell me if it works correctly or if any further clarifications are needed.

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