-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScript.js
51 lines (44 loc) · 1.65 KB
/
contentScript.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// console.log("Content script loaded");
(() => {
document.querySelectorAll("input[type='submit']").forEach(ele =>
createFlashBtn(ele)
)
})();
function createFlashBtn(ele) {
submitBtnHeight = ele.offsetHeight;
const flashBtn = document.createElement('img');
flashBtn.src = chrome.runtime.getURL("assets/flashIcon.png");
// flashBtn.src = "https://cdn-icons-png.flaticon.com/512/6645/6645280.png";
flashBtn.className = ele.className + "FlashBtn";
flashBtn.title = "Supercharge Form";
flashBtn.style.height = `${submitBtnHeight}px`;
flashBtn.style.width = 'auto';
ele.parentElement.appendChild(flashBtn);
// console.log("Element Added...");
flashBtn.addEventListener("click", () => {
processInputTags(ele.closest("form"));
});
};
function processInputTags(formEle) {
const dictData = {
"first": "ABC",
"last": "XYZ",
"name": "ABC XYZ",
"mail": "abc@gmail.com",
"company": "IJK",
"phone": "1234567890",
"country": "YYY",
"address": "XXX",
"message": "___",
}
const keys = Object.keys(dictData)
// console.log("--- Click Event Triggired ---");
formEle.querySelectorAll("input[type='text'], input[type='email'], input[type='text']:not([type='hidden']), textarea").forEach(inp => {
const inputLabel = inp.placeholder.toLowerCase() || inp.name.toLowerCase() || inp.closest("div").textContent.toLowerCase().trim()
for (let key of keys) {
if (key == inputLabel || inputLabel.includes(key) || key.includes(inputLabel)) {
inp.value = dictData[key]
}
}
})
};