-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractentries.html
98 lines (72 loc) · 3.12 KB
/
extractentries.html
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
<!DOCTYPE html>
<html>
<head>
<title>extract entries</title>
<script>
// https://stackoverflow.com/questions/28488777/get-all-input-field-names-from-an-html-form-with-code
// still need to:
// create text input field collect variable for URL. strip /viewform and make it /formResponse
// somehow extract location (another text input field?) get it from URL?
// apply to the form.
// apply all of this to index.html
</script>
</head>
<body>
<p id="demo"></p>
<script>
function extractEntries(form)
{
const extractedEntires = [];
const inputs = form.elements;
for (let i = 0; i < inputs.length; i++)
{
if(inputs[i].name.includes("entry."))
extractedEntires.push(inputs[i].name);
}
return extractedEntires;
}
function pluginCustomURL(extractedEntries)
{
document.getElementById("theForm").action = "";
document.getElementById("lastName").name = extractedEntries[0];
document.getElementById("firstName").name = extractedEntries[1];
document.getElementById("location").name = extractedEntries[2];
// you need to manually fill in the location field here
document.getElementById("location").value = "Test";
document.getElementById("formMonth").name = extractedEntries[3];
document.getElementById("formDay").name = extractedEntries[4];
document.getElementById("formYear").name = extractedEntries[0];
document.getElementById("passOrFail").name = extractedEntries[0];
document.getElementById("processedISOWeekNumber").name = extractedEntries[0];
document.getElementById("group").name = extractedEntries[0];
document.getElementById("teachersNames").name = extractedEntries[0];
// CEFR Level at Beginning
document.getElementById("levelAtBeginning").name = extractedEntries[0];
// CEFR Level at End
document.getElementById("levelAtEnd").name = extractedEntries[0];
document.getElementById("changedLevel").name = extractedEntries[0];
for (let i = 1; i < 6; i++) {document.getElementById("fluency-"+i).name = extractedEntries[0];}
for (let i = 1; i < 6; i++) {document.getElementById("pronunciation-"+i).name = extractedEntries[0];}
for (let i = 1; i < 6; i++) {document.getElementById("grammar-"+i).name = extractedEntries[0];}
for (let i = 1; i < 6; i++) {document.getElementById("vocabulary-"+i).name = extractedEntries[0];}
for (let i = 1; i < 6; i++) {document.getElementById("comprehension-"+i).name = extractedEntries[0];}
document.getElementById("formHomework").name = extractedEntries[0];
document.getElementById("formParticipation").name = extractedEntries[0];
// final score
document.getElementById("endLevel").name = extractedEntries[0];
document.getElementById("comment").name = extractedEntries[0];
}
console.log("fetching data...");
fetch('https://cors-anywhere.herokuapp.com/https://docs.google.com/forms/d/e/1FAIpQLSeBzokJL941yd1cK6EpZZAfNr_4UjUTi-irPZdsHYHK0ksAug/viewform')
.then(response => response.text())
.then(text => {
const parser = new DOMParser();
const htmlDocument = parser.parseFromString(text, "text/html");
var formElement = htmlDocument.forms[0];
var result = extractEntries(formElement);
console.log(result);
})
.catch(error => console.error(error))
</script>
</body>
</html>