-
Notifications
You must be signed in to change notification settings - Fork 1
/
autofill.js
83 lines (80 loc) · 2.5 KB
/
autofill.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function get(keys) {
return new Promise(resolve => chrome.storage.local.get(keys, resolve));
}
function autofillForms(options) {
const {
fname,
lname,
email,
website,
linkedin,
'phone-num': phoneNum,
zipcode,
address,
country,
state,
city,
education,
'hear-about': hearAbout,
pronouns,
gender,
race,
} = options;
for (const form of document.forms) {
for (const input of form.elements) {
const labels = input.labels;
if (labels) {
for (const label of labels) {
const text = label.innerText;
if (text.match(/first name/i)) {
input.value = fname;
} else if (text.match(/last name/i)) {
input.value = lname;
} else if (text.match(/full name/i)) {
input.value = fname + ' ' + lname;
} else if (text.match(/email/i)) {
input.value = email;
} else if (text.match(/website/i)) {
input.value = website;
} else if (text.match(/linkedin/i)) {
input.value = linkedin;
} else if (text.match(/phone/i)) {
input.value = phoneNum;
} else if (text.match(/zipcode/i)) {
input.value = zipcode;
} else if (text.match(/address/i)) {
input.value = address;
} else if (text.match(/country/i)) {
input.value = country;
} else if (text.match(/state/i)) {
input.value = state;
} else if (text.match(/city/i)) {
input.value = city;
} else if (text.match(/university/i)) {
input.value = education;
} else if (text.match(/education/i)) {
input.value = education;
} else if (text.match(/this job/i)) {
input.value = hearAbout;
} else if (text.match(/pronouns/i)) {
input.value = pronouns;
} else if (gender === 'male' && text.match(/\b(male|man)/i)) {
input.checked = true;
} else if (gender === 'female' && text.match(/female|woman/i)) {
input.checked = true;
} else if (gender === 'non-binary' && text.match(/non(-| )?binary/i)) {
input.checked = true;
} else if (race === 'white' && text.match(/white/i)) {
input.checked = true;
}
}
}
}
}
}
chrome.runtime.onMessage.addListener(async request => {
if (request === 'autofill') {
const { options } = await get('options');
autofillForms(options);
}
});