-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
234 lines (206 loc) · 5.7 KB
/
form.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
window.onload = () => {
if ("scrollRestoration" in history) {
history.scrollRestoration = "manual";
}
document.querySelector("#message").innerHTML = "";
chrome.storage.local.get(
[
"preferred_fc",
"email",
"name",
"uid",
"vaccination",
"q1",
"q2",
"q3",
"q4",
"q5",
"q6",
"q7",
"q8",
"declaration",
],
(result) => {
if (result.preferred_fc === "c10001Tab") {
document.querySelector("#c10001Tab").click();
} else if (result.preferred_fc === "c10002Tab") {
document.querySelector("#c10002Tab").click();
} else if (result.preferred_fc === "c10003Tab") {
document.querySelector("#c10003Tab").click();
}
document.querySelector("#email").value = result.email;
document.querySelector("#name").value = result.name;
document.querySelector("#uid").value = result.uid;
if (result.vaccination !== null) {
if (result.vaccination) {
document.querySelector("#vaccination_t").checked = true;
} else {
document.querySelector("#vaccination_f").checked = true;
}
}
if (result.q1) {
document.querySelector("#q1_t").checked = true;
} else {
document.querySelector("#q1_f").checked = true;
}
if (result.q2) {
document.querySelector("#q2_t").checked = true;
} else {
document.querySelector("#q2_f").checked = true;
}
if (result.q3) {
document.querySelector("#q3_t").checked = true;
} else {
document.querySelector("#q3_f").checked = true;
}
if (result.q4) {
document.querySelector("#q4_t").checked = true;
} else {
document.querySelector("#q4_f").checked = true;
}
if (result.q5) {
document.querySelector("#q5_t").checked = true;
} else {
document.querySelector("#q5_f").checked = true;
}
if (result.q6) {
document.querySelector("#q6_t").checked = true;
} else {
document.querySelector("#q6_f").checked = true;
}
if (result.q7) {
document.querySelector("#q7_t").checked = true;
} else {
document.querySelector("#q7_f").checked = true;
}
if (result.q8) {
document.querySelector("#q8_t").checked = true;
} else {
document.querySelector("#q8_f").checked = true;
}
if (result.declaration) {
document.querySelector("#declaration").checked = true;
} else {
document.querySelector("#declaration").checked = false;
}
}
);
document.querySelector("#save").onclick = () => {
if (document.querySelector("#c10001Tab").checked) {
newPreferred_fc = "c10001Tab";
} else if (document.querySelector("#c10002Tab").checked) {
newPreferred_fc = "c10002Tab";
} else if (document.querySelector("#c10003Tab").checked) {
newPreferred_fc = "c10003Tab";
}
var newEmail = chrome.storage.local.get("email");
if (document.querySelector("#email").value) {
newEmail = document.querySelector("#email").value;
} else {
window.scrollTo(0, 0);
alert("Email?");
}
var newName = chrome.storage.local.get("name");
if (document.querySelector("#name").value) {
newName = document.querySelector("#name").value;
} else {
window.scrollTo(0, 0);
alert("Name?");
}
var newUid = chrome.storage.local.get("uid");
if (document.querySelector("#uid").value) {
newUid = document.querySelector("#uid").value;
} else {
window.scrollTo(0, 0);
alert("Student/Staff/CSE Sports Membership No.?");
}
var newVaccination = null;
if (
!document.querySelector("#vaccination_t").checked &&
!document.querySelector("#vaccination_f").checked
) {
window.scrollTo(0, 0);
alert("Have you completed the full COVID-19 vaccination course?");
} else if (document.querySelector("#vaccination_t")) {
newVaccination = true;
} else {
newVaccination = false;
}
var newQ1;
if (document.querySelector("#q1_t").checked) {
newQ1 = true;
} else {
newQ1 = false;
}
var newQ2;
if (document.querySelector("#q2_t").checked) {
newQ2 = true;
} else {
newQ2 = false;
}
var newQ3;
if (document.querySelector("#q3_t").checked) {
newQ3 = true;
} else {
newQ3 = false;
}
var newQ4;
if (document.querySelector("#q4_t").checked) {
newQ4 = true;
} else {
newQ4 = false;
}
var newQ5;
if (document.querySelector("#q5_t").checked) {
newQ5 = true;
} else {
newQ5 = false;
}
var newQ6;
if (document.querySelector("#q6_t").checked) {
newQ6 = true;
} else {
newQ6 = false;
}
var newQ7;
if (document.querySelector("#q7_t").checked) {
newQ7 = true;
} else {
newQ7 = false;
}
var newQ8;
if (document.querySelector("#q8_t").checked) {
newQ8 = true;
} else {
newQ8 = false;
}
var newDeclaration;
if (document.querySelector("#declaration").checked) {
newDeclaration = true;
} else {
newDeclaration = false;
}
chrome.storage.local.set({
preferred_fc: newPreferred_fc,
email: newEmail,
name: newName,
uid: newUid,
vaccination: newVaccination,
q1: newQ1,
q2: newQ2,
q3: newQ3,
q4: newQ4,
q5: newQ5,
q6: newQ6,
q7: newQ7,
q8: newQ8,
declaration: newDeclaration,
});
document.querySelector("#message").innerHTML = `
<div class="alert alert-primary" role="alert">
All changes (if any) updated.
</div>
`;
window.scrollTo(0, 0);
};
};