Upload 6 files
Browse files- .hintrc +5 -0
- background.js +5 -0
- content.js +67 -0
- manifest.json +22 -0
- popup.html +10 -0
- popup.js +37 -0
.hintrc
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"extends": [
|
| 3 |
+
"development"
|
| 4 |
+
]
|
| 5 |
+
}
|
background.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
| 2 |
+
if (request.action === 'getAnswer') {
|
| 3 |
+
//This will be filled later.
|
| 4 |
+
}
|
| 5 |
+
});
|
content.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// content.js
|
| 2 |
+
|
| 3 |
+
async function autoFillForms() {
|
| 4 |
+
console.log("Auto-fill started.");
|
| 5 |
+
let questionElements = document.querySelectorAll('.office-form-question-title');
|
| 6 |
+
if (questionElements.length === 0) {
|
| 7 |
+
questionElements = document.querySelectorAll('.office-form-question-title-format-choice');
|
| 8 |
+
}
|
| 9 |
+
if (questionElements.length === 0) {
|
| 10 |
+
questionElements = document.querySelectorAll('[aria-labelledby*="question-title"]');
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
console.log("Question Elements:", questionElements);
|
| 14 |
+
const questions = Array.from(questionElements).map(el => el.textContent.trim());
|
| 15 |
+
console.log("Questions:", questions);
|
| 16 |
+
|
| 17 |
+
for (let i = 0; i < questions.length; i++) {
|
| 18 |
+
const question = questions[i];
|
| 19 |
+
try {
|
| 20 |
+
const answer = await getGoogleAnswer(question); // Use Google API here
|
| 21 |
+
if (answer) {
|
| 22 |
+
const inputFields = document.querySelectorAll('input[type="text"], textarea');
|
| 23 |
+
console.log("Input Fields:", inputFields);
|
| 24 |
+
if (inputFields[i]) {
|
| 25 |
+
console.log("Setting input field:", i, "to:", answer);
|
| 26 |
+
inputFields[i].value = answer;
|
| 27 |
+
} else {
|
| 28 |
+
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
| 29 |
+
console.log("Radio Buttons:", radioButtons);
|
| 30 |
+
radioButtons.forEach(radio => {
|
| 31 |
+
console.log("Radio Label:", radio.parentElement.textContent);
|
| 32 |
+
if (radio.parentElement.textContent.includes(answer)) {
|
| 33 |
+
console.log("Checking Radio Button:", radio);
|
| 34 |
+
radio.checked = true;
|
| 35 |
+
}
|
| 36 |
+
});
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
} catch (error) {
|
| 40 |
+
console.error("Error fetching answer:", error);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
async function getGoogleAnswer(question) {
|
| 46 |
+
console.log("Fetching Google answer for:", question);
|
| 47 |
+
const apiKey = "YOUR_GOOGLE_CUSTOM_SEARCH_API_KEY"; // Replace with your API key
|
| 48 |
+
const searchEngineId = "YOUR_GOOGLE_SEARCH_ENGINE_ID"; // Replace with your search engine ID
|
| 49 |
+
const apiUrl = `https://www.googleapis.com/customsearch/v1?key=${apiKey}&cx=${searchEngineId}&q=${encodeURIComponent(question)}`;
|
| 50 |
+
|
| 51 |
+
try {
|
| 52 |
+
const response = await fetch(apiUrl);
|
| 53 |
+
const data = await response.json();
|
| 54 |
+
console.log("Google API Response:", data);
|
| 55 |
+
|
| 56 |
+
if (data.items && data.items.length > 0) {
|
| 57 |
+
return data.items[0].snippet || data.items[0].title; // Extract snippet or title
|
| 58 |
+
} else {
|
| 59 |
+
return "Answer not found on Google.";
|
| 60 |
+
}
|
| 61 |
+
} catch (error) {
|
| 62 |
+
console.error("Google API error:", error);
|
| 63 |
+
return "Error fetching from Google.";
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
window.addEventListener('load', autoFillForms);
|
manifest.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"manifest_version": 3,
|
| 3 |
+
"name": "Forms Auto-Answer",
|
| 4 |
+
"version": "1.0",
|
| 5 |
+
"description": "Automatically answers Microsoft Forms (basic demo).",
|
| 6 |
+
"permissions": [
|
| 7 |
+
"activeTab",
|
| 8 |
+
"scripting"
|
| 9 |
+
],
|
| 10 |
+
"action": {
|
| 11 |
+
"default_popup": "popup.html"
|
| 12 |
+
},
|
| 13 |
+
"background": {
|
| 14 |
+
"service_worker": "background.js"
|
| 15 |
+
},
|
| 16 |
+
"content_scripts": [
|
| 17 |
+
{
|
| 18 |
+
"matches": ["https://forms.office.com/*"],
|
| 19 |
+
"js": ["content.js"]
|
| 20 |
+
}
|
| 21 |
+
]
|
| 22 |
+
}
|
popup.html
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Forms Auto-Answer</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<h1>Forms Auto-Answer</h1>
|
| 8 |
+
<p>Extension loaded. Answers will attempt to fill automatically on form load.</p>
|
| 9 |
+
</body>
|
| 10 |
+
</html>
|
popup.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.getElementById('findAnswers').addEventListener('click', async () => {
|
| 2 |
+
const statusDiv = document.getElementById('status');
|
| 3 |
+
statusDiv.textContent = "Analyzing the page...";
|
| 4 |
+
|
| 5 |
+
try {
|
| 6 |
+
// Get the active tab
|
| 7 |
+
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
|
| 8 |
+
|
| 9 |
+
// Check if we're on a Microsoft Forms page
|
| 10 |
+
if (!tab.url.includes("forms.office.com")) {
|
| 11 |
+
statusDiv.textContent = "Error: Not a Microsoft Forms page. Please use this extension on a Microsoft Forms page.";
|
| 12 |
+
return;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
// Send message to content script
|
| 16 |
+
chrome.tabs.sendMessage(tab.id, {action: "findAnswers"}, (response) => {
|
| 17 |
+
if (chrome.runtime.lastError) {
|
| 18 |
+
console.error(chrome.runtime.lastError);
|
| 19 |
+
statusDiv.textContent = "Error: Could not connect to the page. Try refreshing the page and trying again.";
|
| 20 |
+
return;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if (response && response.success) {
|
| 24 |
+
if (response.questions.length > 0) {
|
| 25 |
+
statusDiv.textContent = `Found ${response.questions.length} questions. Searching for answers...`;
|
| 26 |
+
} else {
|
| 27 |
+
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.";
|
| 28 |
+
}
|
| 29 |
+
} else {
|
| 30 |
+
statusDiv.textContent = "Failed to find questions on this page.";
|
| 31 |
+
}
|
| 32 |
+
});
|
| 33 |
+
} catch (error) {
|
| 34 |
+
console.error(error);
|
| 35 |
+
statusDiv.textContent = "Error: " + error.message;
|
| 36 |
+
}
|
| 37 |
+
});
|