// ==UserScript==
// @name ShalaDarpan Marks Auto Fill (Manual Subject & Exam)
// @namespace https://rajshaladarpan.rajasthan.gov.in/
// @version 1.1
// @description Auto-fill marks using manual subject & exam selector
// @match https://rajshaladarpan.rajasthan.gov.in/*/Home/School/StudentAccess_MarksEnter_School.aspx
// @grant none
// ==/UserScript==
(function () {
'use strict';
/************** FLOATING PANEL **************/
const panel = document.createElement('div');
panel.innerHTML = `
📘 Auto Fill Marks
`;
Object.assign(panel.style, {
position: 'fixed',
bottom: '20px',
right: '20px',
zIndex: '99999',
padding: '12px',
width: '220px',
background: '#ffffff',
border: '1px solid #ccc',
borderRadius: '6px',
boxShadow: '0 3px 10px rgba(0,0,0,0.3)',
fontSize: '13px'
});
document.body.appendChild(panel);
/************** HELPERS **************/
function getSchoolCode() {
const span = document.querySelector('#lblSchcd span');
return span ? span.innerText.trim() : null;
}
function getSelectValue(id) {
const el = document.getElementById(id);
return el ? el.options[el.selectedIndex]?.value.trim() : '';
}
function marksTableExists() {
return document.getElementById('ContentPlaceHolder1_grdStudent_6_10');
}
document.getElementById('tm_mode').addEventListener('change', function () {
const idx = document.getElementById('tm_total_index');
idx.style.display = this.value === 'total' ? 'block' : 'none';
});
/************** MAIN **************/
document.getElementById('tm_fill').addEventListener('click', async () => {
if (!marksTableExists()) {
alert('❌ Marks table not loaded.\nClick Show first.');
return;
}
const exam = document.getElementById('tm_exam').value || getSelectValue('ContentPlaceHolder1_ddlExamaccessment');
const subject = document.getElementById('tm_subject').value || getSelectValue('ContentPlaceHolder1_ddlsubject');
if (!exam || !subject) {
alert('❌ Please select Exam and Subject');
return;
}
const schoolCode = getSchoolCode();
if (!schoolCode) {
alert('❌ School code not found');
return;
}
const classVal = getSelectValue('ContentPlaceHolder1_ddlClass');
const sectionTxt = document.getElementById('ContentPlaceHolder1_ddlSection')
?.selectedOptions[0]?.text;
if (!classVal || !sectionTxt) {
alert('❌ Class / Section missing');
return;
}
const apiUrl =
`https://sd.rankguruji.com/api/load_marks.php` +
`?code=${schoolCode}` +
`&class=${classVal}` +
`§ion=${encodeURIComponent(sectionTxt)}` +
`&exam=${encodeURIComponent(exam)}` +
`&subject=${encodeURIComponent(subject)}`;
console.log('📡 API:', apiUrl);
try {
const res = await fetch(apiUrl);
const data = await res.json();
if (!data.students?.length) {
alert('❌ No data from API');
return;
}
const markMap = {};
data.students.forEach(s => {
markMap[String(s.srno)] = {
written: s.written,
oral: s.oral
};
});
const rows = document.querySelectorAll(
'#ContentPlaceHolder1_grdStudent_6_10 tr'
);
let filled = 0;
const mode = document.getElementById('tm_mode').value;
const totalIndex = parseInt(document.getElementById('tm_total_index').value);
rows.forEach(row => {
const srnoCell = row.querySelector('td:nth-child(2)');
if (!srnoCell) return;
const srno = srnoCell.innerText.trim();
const student = markMap[srno];
if (!student) return;
if (mode === 'individual') {
const oralInput = row.querySelector('td:nth-last-child(2) input');
const writtenInput = row.querySelector('td:last-child input');
if (writtenInput && student.written != null) {
writtenInput.value = student.written;
writtenInput.style.background = '#d4edda';
}
if (oralInput) {
if (student.oral != null) {
oralInput.value = student.oral;
oralInput.style.background = '#d4edda';
} else {
oralInput.value = '';
oralInput.style.background = '#fff3cd';
}
}
} else if (mode === 'total') {
if (!totalIndex || totalIndex < 1) return;
const total = (Number(student.written) || 0) + (Number(student.oral) || 0);
const totalInput = row.querySelector(`td:nth-child(${totalIndex}) input`);
if (totalInput) {
totalInput.value = total;
totalInput.style.background = '#cce5ff';
}
}
filled++;
});
alert(`✅ Written/Oral marks filled for ${filled} students`);
} catch (e) {
console.error(e);
alert('❌ API error');
}
});
})();