Repository navigation
Expand file tree
/
Copy pathtampermonkey_script.js
More file actions
111 lines (93 loc) · 4.35 KB
/
Copy pathtampermonkey_script.js
File metadata and controls
111 lines (93 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ==UserScript==
// @name Evalify to AEGIS-MIND Exporter (v1.3)
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Robust extraction including coding answers and variable marks
// @author AdityaVineeth
// @match http://v1.evalify.amritanet.edu/student/quiz/result/*
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
const BUTTON_ID = 'aegis-mind-export-btn';
const createButton = () => {
if (document.getElementById(BUTTON_ID)) return;
const btn = document.createElement('button');
btn.id = BUTTON_ID;
btn.innerHTML = 'Copy JSON for AEGIS-MIND';
btn.style = `
position: fixed; top: 100px; right: 20px; z-index: 10000;
padding: 12px 24px; background-color: #6366f1; color: white;
border: 2px solid white; border-radius: 8px; cursor: pointer;
font-weight: bold; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
transition: transform 0.2s;
`;
btn.onmouseover = () => btn.style.transform = 'scale(1.05)';
btn.onmouseout = () => btn.style.transform = 'scale(1)';
btn.onclick = exportData;
document.body.appendChild(btn);
};
const exportData = () => {
const questionBlocks = document.querySelectorAll('div.space-y-4.p-4.rounded-lg.border');
if (questionBlocks.length === 0) {
alert("No quiz questions detected.");
return;
}
const extractedData = [];
questionBlocks.forEach((block, index) => {
// 1. Capture question text
const questionContainer = block.querySelector('.prose');
const questionText = questionContainer ? questionContainer.innerText.trim() : "Text not found";
// 2. Dynamic Outcome Logic (Matches awarded marks vs total marks)
const marksMatch = block.innerText.match(/(\d+)\s*\/\s*(\d+)\s*marks/);
const outcome = (marksMatch && marksMatch[1] === marksMatch[2]) ? 1 : 0;
// 3. Extract Options & Correct Answer
const optionElements = block.querySelectorAll('.grid-cols-1 .p-4');
let options = [];
let correctAnswer = "";
if (optionElements.length > 0) {
// MCQ Handling
optionElements.forEach(opt => {
const letter = opt.querySelector('span')?.innerText.replace('.', '').trim() || "";
const text = opt.querySelector('.prose span')?.innerText.trim() || "";
options.push(`${letter}) ${text}`);
if (opt.className.includes('border-green-500') || opt.querySelector('.lucide-circle-check-big')) {
correctAnswer = letter;
}
});
} else {
// Coding / Open-ended Handling
const yourAnswerPre = block.querySelector('pre');
if (yourAnswerPre) {
correctAnswer = yourAnswerPre.innerText.trim();
} else {
const expectedBox = block.querySelector('div.bg-green-50');
correctAnswer = expectedBox ? expectedBox.innerText.trim() : "Manual Review Required";
}
}
extractedData.push({
"student_id": 1,
"test_id": window.location.pathname.split('/').pop(),
"topic_tag": null,
"question_id": index + 1,
"question_text": questionText,
"options": options,
"correct_answer": correctAnswer,
"outcome": outcome,
"time_spent_seconds": null,
"difficulty_level": null,
"test_sequence_number": index + 1,
"time_of_day": null,
"sleep_hours": null,
"stress_level": null
});
});
GM_setClipboard(JSON.stringify(extractedData, null, 2));
alert(`Exported ${extractedData.length} questions. Coding answers and variable marks are now included!`);
};
const observer = new MutationObserver(() => {
if (!document.getElementById(BUTTON_ID)) createButton();
});
observer.observe(document.body, { childList: true, subtree: true });
createButton();
})();