-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
35 lines (30 loc) · 1.13 KB
/
content.js
File metadata and controls
35 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// request the default answers from background.js
chrome.runtime.sendMessage({ action: "fillForm" }, (response) => {
const formData = response.data;
// function to find the best matching answer for a form label or placeholder
const findAnswer = (label) => {
return formData[label] || "";
};
// iterate over form inputs and text areas
const formElements = document.querySelectorAll('input[type="text"], textarea, input:not([type])');
formElements.forEach((element) => {
// attempt to get the prompt text by checking labels, placeholders, or associated texts
let prompt = "";
const id = element.id;
if (id) {
const labelElement = document.querySelector(`label[for="${id}"]`);
if (labelElement) {
prompt = labelElement.textContent.trim();
}
}
// if no label, check the placeholder or surrounding text
if (!prompt) {
prompt = element.placeholder.trim();
}
// g Create popup interface with search functionalityet the answer for the found prompt and fill the form
const answer = findAnswer(prompt);
if (answer) {
element.value = answer;
}
});
});