Size
6.4 KB
Version
1.1.4
Created
Feb 19, 2026
Updated
18 days ago
1// ==UserScript==
2// @name Miacademy Answer Cheat
3// @description Automatically marks all answers as correct
4// @version 1.1.4
5// @match https://*.miacademy.co/*
6// @icon https://miacademy.co/generated/static-images/miacademy/shared/favicon.ico
7// @grant GM.xmlhttpRequest
8// ==/UserScript==
9(function() {
10 'use strict';
11
12 console.log('Miacademy Answer Helper Extension loaded');
13
14 // Utility function to wait for element
15 function waitForElement(selector, timeout = 10000) {
16 return new Promise((resolve, reject) => {
17 if (document.querySelector(selector)) {
18 return resolve(document.querySelector(selector));
19 }
20
21 const observer = new MutationObserver(() => {
22 if (document.querySelector(selector)) {
23 observer.disconnect();
24 resolve(document.querySelector(selector));
25 }
26 });
27
28 observer.observe(document.body, {
29 childList: true,
30 subtree: true
31 });
32
33 setTimeout(() => {
34 observer.disconnect();
35 reject(new Error(`Element ${selector} not found within ${timeout}ms`));
36 }, timeout);
37 });
38 }
39
40 // Debounce function to prevent multiple rapid calls
41 function debounce(func, wait) {
42 let timeout;
43 return function executedFunction(...args) {
44 const later = () => {
45 clearTimeout(timeout);
46 func(...args);
47 };
48 clearTimeout(timeout);
49 timeout = setTimeout(later, wait);
50 };
51 }
52
53 // Main function to highlight correct answer
54 async function highlightCorrectAnswer() {
55 try {
56 console.log('Finding correct answer...');
57
58 // Wait for question section to be present
59 const questionSection = await waitForElement('.mia-QuestionSection');
60 if (!questionSection) {
61 console.log('No question section found');
62 return;
63 }
64
65 // Get the question text
66 const questionElement = questionSection.querySelector('.mia-promptText, .mia-Prompt');
67 if (!questionElement) {
68 console.log('No question text found');
69 return;
70 }
71 const questionText = questionElement.textContent.trim();
72 console.log('Question:', questionText);
73
74 // Get all answer choices
75 const answerElements = document.querySelectorAll('.mia-SelectableAnswer');
76 if (answerElements.length === 0) {
77 console.log('No answer choices found');
78 return;
79 }
80
81 const answerChoices = Array.from(answerElements).map((el, index) => {
82 const textElement = el.querySelector('.mia-TextBlock');
83 return {
84 index: index,
85 text: textElement ? textElement.textContent.trim() : '',
86 element: el
87 };
88 });
89
90 console.log('Answer choices:', answerChoices.map(a => a.text));
91
92 // Use AI to determine the correct answer
93 const prompt = `Question: ${questionText}
94
95Answer choices:
96${answerChoices.map((choice, i) => `${i + 1}. ${choice.text}`).join('\n')}
97
98Which answer is correct? Respond with only the number (1, 2, 3, or 4) of the correct answer.`;
99
100 console.log('Asking AI for the correct answer...');
101
102 const aiResponse = await RM.aiCall(prompt, {
103 type: "json_schema",
104 json_schema: {
105 name: "answer_selection",
106 schema: {
107 type: "object",
108 properties: {
109 correctAnswerNumber: {
110 type: "number",
111 minimum: 1,
112 maximum: 10,
113 description: "The number of the correct answer choice"
114 },
115 reasoning: {
116 type: "string",
117 description: "Brief explanation of why this is correct"
118 }
119 },
120 required: ["correctAnswerNumber"]
121 }
122 }
123 });
124
125 console.log('AI Response:', aiResponse);
126
127 const correctIndex = aiResponse.correctAnswerNumber - 1;
128 if (correctIndex >= 0 && correctIndex < answerChoices.length) {
129 const correctAnswer = answerChoices[correctIndex];
130 console.log('✅ CORRECT ANSWER:', correctAnswer.text);
131 console.log('Reasoning:', aiResponse.reasoning);
132
133 // Remove any existing highlights
134 document.querySelectorAll('.mia-SelectableAnswer').forEach(el => {
135 el.style.border = '';
136 el.style.backgroundColor = '';
137 el.style.boxShadow = '';
138 });
139
140 // Highlight the correct answer with a green border
141 correctAnswer.element.style.border = '4px solid #00ff00';
142 correctAnswer.element.style.backgroundColor = 'rgba(0, 255, 0, 0.1)';
143 correctAnswer.element.style.boxShadow = '0 0 20px rgba(0, 255, 0, 0.5)';
144
145 console.log('✅ Correct answer highlighted in green!');
146 } else {
147 console.error('Invalid answer index from AI:', correctIndex);
148 }
149
150 } catch (error) {
151 console.error('Error finding correct answer:', error);
152 }
153 }
154
155 // Monitor for new questions
156 const debouncedHighlight = debounce(highlightCorrectAnswer, 2000);
157
158 const observer = new MutationObserver(debouncedHighlight);
159
160 // Start observing when DOM is ready
161 function init() {
162 console.log('Initializing answer helper...');
163
164 if (document.body) {
165 observer.observe(document.body, {
166 childList: true,
167 subtree: true
168 });
169
170 // Try to highlight any existing question
171 highlightCorrectAnswer();
172 }
173 }
174
175 // Initialize
176 if (document.readyState === 'loading') {
177 document.addEventListener('DOMContentLoaded', init);
178 } else {
179 init();
180 }
181
182 console.log('Miacademy Answer Helper Extension fully active!');
183})();
184