-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
54 lines (47 loc) · 1.57 KB
/
script.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
const body = document.querySelector("body");
let mbp = document.createElement("mbp:frameset");
let idx = document.createElement("idx:entry");
let h5 = document.createElement("h5");
let dt = document.createElement("dt");
let orth = document.createElement("idx:orth");
let dd = document.createElement("dd");
let hr = document.createElement("hr");
body.appendChild(mbp);
window.onload = () => {
// FILE PICKER
let picker = document.getElementById("csv");
// READ CSV FILE
picker.onchange = () => {
// GET SELECTED CSV FILE
let selected = picker.files[0];
// READ CSV INTO ARRAY
let reader = new FileReader();
reader.addEventListener("loadend", () => {
// SPLIT ROWS & COLUMNS
let data = reader.result.split("\r\n");
for (let i in data) {
data[i] = data[i].split(",");
}
data.forEach((element) => {
let idx = document.createElement("idx:entry");
let h5 = document.createElement("h5");
let dt = document.createElement("dt");
let orth = document.createElement("idx:orth");
let dd = document.createElement("dd");
let hr = document.createElement("hr");
mbp.appendChild(idx);
idx.setAttribute("name", "default");
idx.setAttribute("scriptable", "yes");
idx.setAttribute("spell", "yes");
idx.appendChild(h5);
h5.appendChild(dt);
dt.appendChild(orth);
orth.innerText = element[0];
idx.appendChild(dd);
dd.innerText = element[1];
idx.appendChild(hr);
});
});
reader.readAsText(selected);
};
};