-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
40 lines (34 loc) · 1.32 KB
/
Copy pathcontent.js
File metadata and controls
40 lines (34 loc) · 1.32 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
36
37
38
39
40
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "fillForm") {
const clientData = request.clientData;
clearFormFields();
const mappings = {
"firstName": "#address_recipient_firstName",
"lastName": "#address_recipient_lastName",
"ship-address-1": "#address_recipient_street",
"ship-postal-code": "#address_recipient_postcode",
"ship-city": "#address_recipient_city",
"email": "#address_recipient_email",
"buyer-phone-number": "#address_recipient_mobilePhoneNumber",
};
Object.entries(mappings).forEach(([key, selector]) => {
const field = document.querySelector(selector);
if (field) {
console.log(`Filling field ${selector} with value:`, clientData[key]);
field.value = clientData[key] || "";
} else {
console.warn(`Field with selector ${selector} not found.`);
}
});
sendResponse({ status: "Form filled", clientData });
}
});
function clearFormFields() {
const formElements = document.querySelectorAll('input, select, textarea');
formElements.forEach((element) => {
element.value = '';
if (element.type === 'checkbox' || element.type === 'radio') {
element.checked = false;
}
});
}