-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarklet.js
108 lines (94 loc) · 2.87 KB
/
bookmarklet.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function() {
'replaceme';
const piggybackData = window.piggybackData;
if (!piggybackData) return;
const formFields = [
'select#edit-requestor-category',
'select#edit-delivery-method',
'input#edit-given-name',
'input#edit-family-name',
'input#edit-your-e-mail-address',
'input#edit-your-telephone-number',
'textarea#edit-additional-comments',
'input#edit-address-fieldset-address',
'input#edit-address-fieldset-city',
'select#edit-address-fieldset-state-province-select',
'input#edit-address-fieldset-postal-code',
'select#edit-address-fieldset-country',
'select#edit-preferred-language-of-correspondence',
'select#edit-consent',
'input#edit-details'
];
function setSelectValue(el, fieldContents) {
const options = Array.from(el.options)
.map(d => d.text);
switch (fieldContents) {
case 'requestor-category':
el.value = options.indexOf(piggybackData.requestor);
break;
case 'delivery-method':
el.value = options.indexOf(piggybackData.delivery);
break;
case 'address-fieldset-state-province-select':
el.value = piggybackData.province;
break;
case 'address-fieldset-country':
el.value = piggybackData.country;
break;
case 'preferred-language-of-correspondence':
el.value = piggybackData.lang;
break;
case 'consent':
el.value = 'Yes';
break;
}
}
function setInputValue(el, fieldContents) {
switch (fieldContents) {
case 'given-name':
el.value = piggybackData.givenName;
break;
case 'family-name':
el.value = piggybackData.familyName;
break;
case 'your-e-mail-address':
el.value = piggybackData.email;
break;
case 'your-telephone-number':
el.value = piggybackData.tel;
break;
case 'address-fieldset-address':
el.value = piggybackData.address;
break;
case 'address-fieldset-city':
el.value = piggybackData.city;
break;
case 'address-fieldset-postal-code':
el.value = piggybackData.postal;
break;
default:
}
}
function setTextareaValue(el) {
el.value = piggybackData.additionalComments;
}
formFields.map(entry => {
const element = document.querySelector(entry),
fieldType = entry.replace(/#.+/, ''),
fieldContents = entry.replace(/^.+#edit-/, '');
switch (fieldType) {
case 'select':
setSelectValue(element, fieldContents);
break;
case 'input':
setInputValue(element, fieldContents);
break;
case 'textarea':
setTextareaValue(element);
break;
}
});
const submitBtn = document.querySelector('#edit-actions');
submitBtn.style.display = 'block';
if (submitBtn.scrollIntoView) submitBtn.scrollIntoView({ behavior: 'smooth' });
})();