Now highlights answers with green border and subtle glow only, no background fill.

This commit is contained in:
justin committed 2026-01-08 13:12:47 -07:00
1 parent 9b0a63aa37
commit 7b7fdc7c2c
1 file changed
+59 -97
+59 -97
View File
@@ -12,17 +12,11 @@ function injectCustomStyles() {
style.id = 'quiz-helper-styles'; style.id = 'quiz-helper-styles';
style.textContent = ` style.textContent = `
.quiz-helper-correct { .quiz-helper-correct {
background-color: #90EE90 !important;
border: 3px solid #28a745 !important; border: 3px solid #28a745 !important;
box-shadow: 0 0 10px rgba(40, 167, 69, 0.6) !important; box-shadow: 0 0 8px rgba(40, 167, 69, 0.5) !important;
padding: 8px !important;
border-radius: 4px !important; border-radius: 4px !important;
transition: all 0.3s ease !important; transition: all 0.3s ease !important;
} }
.quiz-helper-correct * {
background-color: transparent !important;
}
`; `;
document.head.appendChild(style); document.head.appendChild(style);
styleInjected = true; styleInjected = true;
@@ -272,22 +266,17 @@ function findQuestions() {
return questions; return questions;
} }
// Enhanced answer choice finding // Enhanced answer choice finding - strictly finds only radio/checkbox options
function findAnswerChoices(questionElement) { function findAnswerChoices(questionElement) {
const answers = []; const answers = [];
const seenTexts = new Set(); const seenTexts = new Set();
let inputType = null; let inputType = null;
let container = questionElement.closest('[role="group"], fieldset, form, [class*="question"], [class*="answer"], [class*="option"], div'); // Find the container with radio/checkbox inputs
let container = questionElement;
if (!container || container === questionElement) { for (let i = 0; i < 6 && container; i++) {
container = questionElement.parentElement; const inputs = container.querySelectorAll('input[type="radio"], input[type="checkbox"]');
} if (inputs.length > 0) {
for (let i = 0; i < 4 && container; i++) {
const inputsInContainer = container.querySelectorAll('input[type="radio"], input[type="checkbox"]');
if (inputsInContainer.length > 0) {
console.log(` Found ${inputsInContainer.length} inputs at level ${i}`);
break; break;
} }
container = container.parentElement; container = container.parentElement;
@@ -295,93 +284,66 @@ function findAnswerChoices(questionElement) {
if (!container) container = document.body; if (!container) container = document.body;
let nextSibling = questionElement.nextElementSibling; // Get all radio/checkbox inputs - these are the ONLY valid answer choices
let siblingAttempts = 0; const inputs = container.querySelectorAll('input[type="radio"], input[type="checkbox"]');
const siblingContainers = [container]; console.log(` Found ${inputs.length} radio/checkbox inputs`);
while (nextSibling && siblingAttempts < 8) { inputs.forEach((input, idx) => {
siblingContainers.push(nextSibling); if (input.type === 'radio') inputType = 'radio';
nextSibling = nextSibling.nextElementSibling; else if (input.type === 'checkbox') inputType = 'checkbox';
siblingAttempts++;
}
const answerSelectors = [ let text = '';
'input[type="radio"]', let labelElement = null;
'input[type="checkbox"]',
'button[role="radio"]',
'button[role="checkbox"]',
'[role="option"]',
'[class*="answer"]',
'[class*="option"]',
'[class*="choice"]',
'[data-test*="answer"]',
'[data-test*="option"]',
'label',
'li'
];
const excludePatterns = [ // Strategy 1: Find label with matching 'for' attribute
/^question\s+\d+\s+of\s+\d+$/i, if (input.id) {
/^page\s+\d+/i, labelElement = document.querySelector(`label[for="${input.id}"]`);
/^(next|previous|submit|skip|back|continue|finish|review)$/i, if (labelElement) {
/^\d+\s*\/\s*\d+$/, text = labelElement.textContent.trim();
/^score:/i, }
/^time:/i, }
/^remaining:/i,
/^points?:/i
];
siblingContainers.forEach(searchContainer => { // Strategy 2: Find parent label
answerSelectors.forEach(selector => { if (!text) {
const elements = searchContainer.querySelectorAll(selector); labelElement = input.closest('label');
if (labelElement) {
text = labelElement.textContent.trim();
}
}
elements.forEach(el => { // Strategy 3: Find adjacent sibling text
let text = el.textContent.trim(); if (!text) {
const parent = input.parentElement;
if (parent) {
// Clone and remove the input to get just the text
const clone = parent.cloneNode(true);
const inputClone = clone.querySelector('input');
if (inputClone) inputClone.remove();
text = clone.textContent.trim();
}
}
if (el.tagName === 'INPUT') { // Strategy 4: Check next sibling
if (el.type === 'radio') { if (!text && input.nextSibling) {
inputType = 'radio'; text = input.nextSibling.textContent?.trim() || '';
} else if (el.type === 'checkbox') { }
inputType = 'checkbox';
}
const label = searchContainer.querySelector(`label[for="${el.id}"]`); // Skip if no text found or duplicate
if (label) { if (!text || text.length < 1) {
text = label.textContent.trim(); console.log(` Skipping input ${idx} - no text found`);
} else { return;
const parentLabel = el.closest('label'); }
if (parentLabel) {
text = parentLabel.textContent.trim();
} else {
const parent = el.parentElement;
if (parent) {
text = parent.textContent.trim();
}
}
}
}
if (!text || text.length < 2 || text.length > 800 || seenTexts.has(text)) { if (seenTexts.has(text)) {
return; console.log(` Skipping input ${idx} - duplicate text`);
} return;
}
if (excludePatterns.some(pattern => pattern.test(text))) { seenTexts.add(text);
return; answers.push({
} text: text,
element: input,
const wordCount = text.split(/\s+/).length; parentLabel: labelElement || input.parentElement
const numberCount = (text.match(/\d+/g) || []).length;
if (wordCount > 2 && numberCount > wordCount / 2) {
return;
}
seenTexts.add(text);
answers.push({
text: text,
element: el,
parentLabel: el.closest('label') || el
});
});
}); });
}); });
@@ -516,7 +478,7 @@ ANALYSIS STEPS:
Think carefully and provide your answer. Think carefully and provide your answer.
FORMAT: Respond with only "ANSWER: " followed by the letter(s) separated by commas (e.g., "ANSWER: B" or "ANSWER: A,C,D")`; FORMAT: Always respond with "ANSWER: " followed by the LETTER(s) of the correct option(s) (A, B, C, D, etc.), separated by commas if multiple. Never respond with numbers - always use letters to indicate which option is correct.`;
const response = await fetch('https://api.openai.com/v1/chat/completions', { const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST', method: 'POST',