-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-to-json.html
More file actions
101 lines (101 loc) · 2.91 KB
/
csv-to-json.html
File metadata and controls
101 lines (101 loc) · 2.91 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CSV to JSON Table | tools.eliana.lol</title>
<link rel="stylesheet" href="global.css" />
<link rel="icon" type="image/x-icon" href="favicon.svg" />
<style>
.table-container {
background: var(--hover);
border-radius: 8px;
overflow-x: auto;
margin-top: 20px;
border: 1px solid var(--puny);
}
table {
width: 100%;
border-collapse: collapse;
text-align: left;
}
th {
background: var(--accent);
color: var(--bg);
padding: 12px;
font-size: 0.75rem;
text-transform: uppercase;
}
td {
padding: 12px;
border-bottom: 1px solid var(--puny);
color: var(--text);
font-size: 0.85rem;
}
tr:hover {
background: var(--highlight);
}
</style>
</head>
<body>
<nav>
<div class="left">
<a href="index.html">home</a> | <a href="extra.html">extra</a> |
<a href="credits.html">credits</a> | <a href="changelog.html">logs</a>
</div>
<div class="right">
<button id="theme-toggle">[theme]</button> |
<a href="https://eliana.lol">site</a>
</div>
</nav>
<main>
<h1>CSV Visualizer</h1>
<p class="puny">Automatic table generation from JSON/CSV fragments.</p>
<div class="table-container">
<table>
<thead>
<tr id="table-header"></tr>
</thead>
<tbody id="table-body"></tbody>
</table>
</div>
</main>
<script id="raw-data" type="application/json">
[
{ "ID": "1", "Name": "Alice", "Role": "Admin" },
{ "ID": "2", "Name": "Bob", "Role": "Editor" }
]
</script>
<script>
const html = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved = localStorage.getItem('theme') || 'dark';
html.setAttribute('data-theme', saved);
try {
const data = JSON.parse(
document.getElementById('raw-data').textContent
);
if (data.length > 0) {
const headerRow = document.getElementById('table-header');
const tableBody = document.getElementById('table-body');
const columns = Object.keys(data[0]);
columns.forEach((col) => {
const th = document.createElement('th');
th.textContent = col;
headerRow.appendChild(th);
});
data.forEach((row) => {
const tr = document.createElement('tr');
columns.forEach((col) => {
const td = document.createElement('td');
td.textContent = row[col] || '';
tr.appendChild(td);
});
tableBody.appendChild(tr);
});
}
} catch (e) {
console.error(e);
}
</script>
</body>
</html>