-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
24 lines (22 loc) · 901 Bytes
/
modal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === "showModal") {
const { missingFields } = request;
const container = document.getElementById("fieldsContainer");
missingFields.forEach(({ label }) => {
const fieldDiv = document.createElement("div");
fieldDiv.innerHTML = `
<label>${label}</label>
<input type="text" data-label="${label}">
`;
container.appendChild(fieldDiv);
});
document.getElementById("submitBtn").addEventListener("click", () => {
const filledFields = Array.from(container.querySelectorAll("input")).map(input => ({
label: input.getAttribute("data-label"),
answer: input.value
}));
sendResponse(filledFields);
window.close();
});
}
});