-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-to-json.html
More file actions
300 lines (261 loc) · 8.78 KB
/
Copy pathcsv-to-json.html
File metadata and controls
300 lines (261 loc) · 8.78 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CSV to JSON | tools.eliana.lol</title>
<link rel="stylesheet" href="global.css" />
<link rel="icon" type="image/x-icon" href="favicon.svg" />
<style>
.container {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.input-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.input-label {
font-size: 0.85rem;
font-weight: bold;
text-transform: uppercase;
color: var(--puny);
letter-spacing: 0.05em;
}
.button-group {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
button {
flex: 0 1 auto;
min-width: 120px;
padding: 10px;
cursor: pointer;
font-family: monospace;
border: 1px solid var(--text);
background: var(--bg);
color: var(--text);
border-radius: 4px;
transition: all 150ms;
}
button:hover {
background-color: var(--hover);
border-color: var(--accent);
}
button.primary {
border-color: var(--accent);
font-weight: bold;
color: var(--accent);
}
button.danger {
border-style: dashed;
opacity: 0.7;
}
textarea,
input[type="text"] {
width: 100%;
font-family: monospace;
padding: 10px;
border: 1px solid var(--puny);
background: var(--bg);
color: var(--text);
box-sizing: border-box;
border-radius: 4px;
font-size: 0.95rem;
}
textarea:focus,
input[type="text"]:focus {
outline: none;
border-color: var(--accent);
}
textarea {
min-height: 150px;
resize: vertical;
}
.status {
padding: 0.75rem 1rem;
border-radius: 4px;
margin: 0.5rem 0;
display: none;
font-size: 0.9rem;
}
.status.show {
display: block;
}
.status.success {
background-color: rgba(16, 185, 129, 0.1);
border-left: 3px solid var(--accent);
color: var(--accent);
}
.status.error {
background-color: rgba(239, 68, 68, 0.1);
border-left: 3px solid #ef4444;
color: #ef4444;
}
.info-box {
padding: 1rem;
background-color: var(--highlight);
border-left: 3px solid var(--accent);
font-size: 0.9rem;
line-height: 1.6;
}
@media (max-width: 600px) {
.button-group {
flex-direction: column;
}
button {
width: 100%;
}
}
</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 to JSON]</h1>
<p class="puny">[Convert CSV data to JSON format. Supports custom delimiters and array/object output.]</p>
<div class="container">
<!-- YOUR TOOL CONTENT GOES HERE -->
<div class="options">
<div class="option-item">
<label for="delimiter">Delimiter:</label>
<select id="delimiter" style="padding: 5px; border: 1px solid var(--puny); background: var(--bg); color: var(--text);">
<option value=",">Comma (,)</option>
<option value=";">Semicolon (;)</option>
<option value="\t">Tab</option>
<option value="|">Pipe (|)</option>
</select>
</div>
<div class="option-item">
<input type="checkbox" id="useHeaders" checked />
<label for="useHeaders">First row contains headers</label>
</div>
<div class="option-item">
<input type="checkbox" id="prettyFormat" checked />
<label for="prettyFormat">Pretty format output</label>
</div>
</div>
<div class="input-group">
<label class="input-label">CSV Input</label>
<textarea id="input" placeholder="Paste CSV data here..."></textarea>
</div>
<div class="button-group">
<button id="convert" class="primary">✨ Convert</button>
<button id="copy">Copy</button>
<button id="clear">Clear</button>
</div>
<div class="input-group">
<label class="input-label">JSON Output</label>
<textarea id="output" readonly placeholder="JSON will appear here..."></textarea>
</div>
<div class="status" id="status"></div>
<div class="info-box">
<strong>Tip:</strong> [Add helpful information about the tool here]
</div>
<div class="status" id="status"></div>
</div>
</main>
<footer style="margin-top: 4rem; text-align: center" class="puny">
© 2026 eliana.lol • <a href="credits.html">credits</a>
</footer>
<!-- Theme Toggle Script (Required for all tools) -->
<script>
const html = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved =
localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
html.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) {
toggle.onclick = () => {
const now = html.getAttribute('data-theme');
const next = now === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
toggle.innerText = next === 'dark' ? '[light]' : '[dark]';
};
}
</script>
<!-- Tool-specific script here -->
<script>
// YOUR TOOL LOGIC GOES HERE
const input = document.getElementById('input');
const output = document.getElementById('output');
const convertBtn = document.getElementById('convert');
const copyBtn = document.getElementById('copy');
const clearBtn = document.getElementById('clear');
const delimiter = document.getElementById('delimiter');
const useHeaders = document.getElementById('useHeaders');
const prettyFormat = document.getElementById('prettyFormat');
const status = document.getElementById('status');
convertBtn.onclick = () => {
try {
const csv = input.value.trim();
if (!csv) {
showStatus('Please enter CSV data!', 'error');
return;
}
const delim = delimiter.value === '\t' ? '\t' : delimiter.value;
const lines = csv.split('\n').filter(l => l.trim());
if (lines.length === 0) {
showStatus('No data to convert!', 'error');
return;
}
const headers = useHeaders.checked ? lines[0].split(delim).map(h => h.trim()) : null;
const dataLines = useHeaders.checked ? lines.slice(1) : lines;
let json;
if (useHeaders.checked && headers) {
json = dataLines.map(line => {
const values = line.split(delim).map(v => v.trim());
const obj = {};
headers.forEach((header, i) => {
obj[header] = values[i] || '';
});
return obj;
});
} else {
json = dataLines.map(line => line.split(delim).map(v => v.trim()));
}
const result = prettyFormat.checked ? JSON.stringify(json, null, 2) : JSON.stringify(json);
output.value = result;
showStatus(`Converted ${dataLines.length} rows`);
} catch (e) {
showStatus('Error: ' + e.message, 'error');
}
};
copyBtn.onclick = () => {
if (!output.value) {
showStatus('Nothing to copy!', 'error');
return;
}
navigator.clipboard.writeText(output.value).then(() => {
showStatus('Copied!');
});
};
clearBtn.onclick = () => {
input.value = '';
output.value = '';
showStatus('Cleared!');
};
function showStatus(message, type = 'success') {
status.textContent = message;
status.classList.add('show');
setTimeout(() => status.classList.remove('show'), 2000);
}
</script>
</body>
</html>