// ==UserScript==
// @name Quiz Assistant (Lightning AI)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Reads questions and queries Lightning AI (Gemini 3.1 Pro)
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// --- 1. CONFIGURATION ---
const LIGHTNING_API_KEY = "f42e9493-71bd-4d04-affd-55d4ee6ed60f";
// UPDATE THIS: Find the CSS selector for the question text.
const QUESTION_SELECTOR = ".loaded";
// --- 2. CREATE MODAL UI ---
const modal = document.createElement('div');
modal.id = 'lightning-assistant-modal';
Object.assign(modal.style, {
position: 'fixed',
top: '20px',
right: '20px',
width: '400px',
maxHeight: '80vh',
overflowY: 'auto',
backgroundColor: '#121212',
color: '#e0e0e0',
padding: '20px',
borderRadius: '12px',
boxShadow: '0 10px 30px rgba(0,0,0,0.5)',
zIndex: '999999',
display: 'none',
fontFamily: 'Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
fontSize: '14px',
lineHeight: '1.5',
border: '1px solid #333'
});
const title = document.createElement('div');
title.innerHTML = '⚡ Lightning Assistant';
title.style.marginBottom = '15px';
title.style.paddingBottom = '10px';
title.style.borderBottom = '1px solid #333';
modal.appendChild(title);
const contentDiv = document.createElement('div');
contentDiv.id = 'lightning-response-content';
contentDiv.innerText = 'Listening for questions...';
modal.appendChild(contentDiv);
document.body.appendChild(modal);
// --- 3. KEYBOARD SHORTCUTS ---
document.addEventListener('keydown', (e) => {
// Show: Ctrl + M
if (e.ctrlKey && e.key.toLowerCase() === 'm') {
e.preventDefault();
modal.style.display = 'block';
}
// Hide: Ctrl + H
if (e.ctrlKey && e.key.toLowerCase() === 'h') {
e.preventDefault();
modal.style.display = 'none';
}
});
// --- 4. LIGHTNING AI API LOGIC ---
async function queryLightning(questionText) {
contentDiv.innerHTML = 'Processing question...';
const url = "https://lightning.ai/api/v1/chat/completions";
const payload = {
model: "google/gemini-3.1-pro-preview",
messages: [
{
role: "user",
content: [
{
type: "text",
text: `Answer this quiz question concisely. Provide the correct option or a short explanation: ${questionText}`
}
]
}
]
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${LIGHTNING_API_KEY}`
},
body: JSON.stringify(payload)
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error?.message || `Status: ${response.status}`);
}
const data = await response.json();
// Standard OpenAI-style response path
const answer = data.choices[0].message.content;
contentDiv.innerHTML = `Answer:
${answer.replace(/\n/g, '
')}`;
} catch (error) {
contentDiv.innerHTML = `Error: ${error.message}`;
console.error("Lightning API Error:", error);
}
}
// --- 5. AUTOMATION LOGIC ---
let lastProcessedQuestion = "";
function checkForNewQuestion() {
const questionElement = document.querySelector(QUESTION_SELECTOR);
if (questionElement) {
const currentQuestionText = questionElement.innerText.trim();
if (currentQuestionText && currentQuestionText !== lastProcessedQuestion) {
lastProcessedQuestion = currentQuestionText;
queryLightning(currentQuestionText);
}
}
}
const observer = new MutationObserver(checkForNewQuestion);
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
// Initial check
setTimeout(checkForNewQuestion, 1000);
})();