-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_portal.js
40 lines (35 loc) · 1.26 KB
/
populate_portal.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
{ // block scope so we can use "const" and re-run snippet
"use strict";
const NAME = "Bobdole";
const EMAIL = "[email protected]";
/**
* Populate all input boxes that look name-related with a fake name, and similarly
* with a fake email address. Check checkboxes indicate the acceptance of terms.
*
* We consider an input box "name-related" if it has an attribute value
* containing the case-insensitive substring "name" (and likewise with "email").
*/
$("input").each(function(i, node) {
for (let attrName of node.getAttributeNames()) {
let attrVal = node.getAttribute(attrName);
if (node.type === "checkbox" && /accept/i.test(attrVal)) {
console.log("Checkbox match on attr=" + attrName + " value=" + attrVal);
node.checked = true;
console.log(node);
return;
}
if (/name/i.test(attrVal)) {
console.log("Name match on attr=" + attrName + " value=" + attrVal);
node.value = NAME;
console.log(node);
return;
}
if (/mail/i.test(attrVal)) {
console.log("Email match on attr=" + attrName + " value=" + attrVal);
node.value = EMAIL;
console.log(node);
return;
}
}
});
}