-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputFile.html
61 lines (56 loc) · 2.14 KB
/
inputFile.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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id="fileForm">
<input type="file" id="fileInput">
<button type="submit">Datei laden</button>
</form>
<form id="textForm">
<input type="text" id="textInput" value="https://docs.google.com/spreadsheets/d/e/2PACX-1vQCho2k88nLWrNSXj4Mgj_MwER5GQ9zbZ0OsO3X_QPa9s-3UkoeLLQHuNHoFMKqCFjWMMprKVHMZzOj/pub?gid=0&single=true&output=csv">
<button type="submit">URL laden</button>
</form>
<div id="result"></div>
</body>
<script>
const fileForm = document.getElementById('fileForm');
fileForm.addEventListener('submit', inputFileTest);
const textForm = document.getElementById('textForm');
textForm.addEventListener('submit', fileFromUrlTest);
function inputFileTest() {
event.preventDefault();
const input = document.getElementById('fileInput');
const file = input.files[0];
// red content of file
reader = new FileReader();
reader.onload = function(e) {
const result = e.target.result
writeFile(result)// e.target.result should contain the text
};
const text = reader.readAsText(file);
}
async function fileFromUrlTest() {
event.preventDefault();
const inputURL = document.getElementById('textInput').value;
// fetch csv from google sheet link
const response = await fetch(inputURL, {
headers: { "content-type": "text/csv;charset=UTF-8" },
});
const text = await response.text();
/*
const reader = new FileReader();
reader.onload = function(e) {
const text = e.target.response;
writeFile(text);
};
const text = reader.readAsText(response);
*/
writeFile(text)
}
function writeFile(data) {
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = data
}
</script>
</html>