Created
August 4, 2022 18:48
-
-
Save KorigamiK/caf73e8e703f5c3440d6c24ca9267991 to your computer and use it in GitHub Desktop.
JEE Mains Marks calculator
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
// ==UserScript== | |
// @name JEE Mains Answers capture | |
// @match https://test.cbexams.com/* | |
// @description This script detects parses your entered answers into a computer readable format | |
// ==/UserScript== | |
const returnData = [] // stores all the answers | |
const cb = document.createElement('input') | |
cb.id = 'cb' | |
cb.type = 'text' | |
cb.style.display = 'hidden' | |
document.body.appendChild(cb) | |
const copyToClip = () => { | |
var cb = document.getElementById("cb"); | |
cb.value = JSON.stringify(returnData); | |
cb.style.display = 'block'; | |
cb.select(); | |
document.execCommand('copy'); | |
cb.style.display = 'none'; | |
alert('Copied content to clipboard') | |
} | |
/** | |
* @param {string} content the content | |
*/ | |
function getSectionsData(content) { | |
const subjectRegex = /(?<=Name:).+(?=-)/; | |
const idRegex = /(?<=Question\sID:)\d{6}/; | |
const sectionRegex = /(?<=Section\s)./; | |
const id = content.match(idRegex).pop() | |
const subject = content.match(subjectRegex).pop(); | |
const section = content.match(sectionRegex).pop(); | |
return { id, subject, section }; | |
} | |
/** | |
* @param {Element} answerData the content | |
* @param {string} section | |
*/ | |
function getGivenAnswer(answerData, section) { | |
switch (section) { | |
case 'A': | |
return answerData.querySelector('font').textContent; | |
case 'B': | |
return answerData.querySelector('font').textContent; | |
} | |
} | |
const main = () => { | |
const questions = document.querySelectorAll('table[cellspacing="3"]'); | |
const copyButton = document.createElement("button"); | |
copyButton.innerText = 'Copy data to clipboard...' | |
copyButton.onclick = copyToClip; | |
document.body.prepend(copyButton); | |
for (const question of questions) { | |
let appendData = { id: null, subject: null, section: null, givenAnswer: null } | |
const questionData = question.querySelector('tbody > tr:first-child'); | |
const content = questionData.textContent | |
appendData = { ...appendData, ...getSectionsData(content) }; | |
const answerData = question.querySelector('tbody > tr:last-child'); | |
// console.log(answerData) | |
appendData.givenAnswer = getGivenAnswer(answerData, appendData.section); | |
returnData.push(appendData); | |
// break; | |
} | |
return returnData | |
} | |
console.log(main()) |
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
// ==UserScript== | |
// @name JEE Mains Marks after capturing the answers | |
// @match https://examinationservices.nic.in/*/KeyChallange/AnswerKey.aspx | |
// @description This script calculates the marks after you give the captured answers. | |
// ==/UserScript== | |
function parseAnswerKey() { | |
let 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; | |
} | |
/** | |
* @param {{id: string; subject: "Chemistry" | "Physics" | "Maths"; section: "A" | "B"; givenAnswer: string}[]} givenAnswers Description | |
*/ | |
function calculateMarks(givenAnswers) { | |
const correctAnswers = parseAnswerKey(); | |
let total = 0; | |
for (const givenAnswer of givenAnswers) { | |
if (!givenAnswer.givenAnswer.includes("Not Attempted")) { | |
if (correctAnswers[givenAnswer.id] === givenAnswer.givenAnswer) total += 4; | |
else total--; | |
} | |
} | |
alert(`The total marks are ${total}`) | |
} | |
const main = () => { | |
const mapForm = document.createElement("form"); | |
const mapInput = document.createElement("input"); | |
mapInput.type = "text"; | |
mapInput.name = "answers"; | |
mapInput.placeholder = 'Paste captured answers'; | |
const submitBtn = document.createElement("button"); | |
submitBtn.type = 'submit' | |
submitBtn.innerText = "Get marks" | |
mapForm.appendChild(mapInput); | |
mapForm.appendChild(submitBtn); | |
document.body.prepend(mapForm); | |
mapForm.onsubmit = e => { | |
e.preventDefault(); | |
try { | |
calculateMarks(JSON.parse(mapInput.value)); | |
} catch (e) { | |
alert(e) | |
} | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment