JEE Mains Marks after capturing the answers

This script calculates the marks after you give the captured answers.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @license      MIT
// @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.
// @version 0.0.1.20220804185237
// @namespace https://greasyfork.org/users/941655
// ==/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()