ai_forms / popup.js
kpgu's picture
Upload 6 files
b63d833 verified
Raw History Blame Contribute Delete
1.61 kB
document.getElementById('findAnswers').addEventListener('click', async () => {
const statusDiv = document.getElementById('status');
statusDiv.textContent = "Analyzing the page...";
try {
// Get the active tab
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
// Check if we're on a Microsoft Forms page
if (!tab.url.includes("forms.office.com")) {
statusDiv.textContent = "Error: Not a Microsoft Forms page. Please use this extension on a Microsoft Forms page.";
return;
}
// Send message to content script
chrome.tabs.sendMessage(tab.id, {action: "findAnswers"}, (response) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
statusDiv.textContent = "Error: Could not connect to the page. Try refreshing the page and trying again.";
return;
}
if (response && response.success) {
if (response.questions.length > 0) {
statusDiv.textContent = `Found ${response.questions.length} questions. Searching for answers...`;
} else {
statusDiv.textContent = "Could not find any questions on this page. This might not be a standard Microsoft Form, or the form structure is not recognized.";
}
} else {
statusDiv.textContent = "Failed to find questions on this page.";
}
});
} catch (error) {
console.error(error);
statusDiv.textContent = "Error: " + error.message;
}
});