-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_input.html
271 lines (223 loc) · 8.84 KB
/
csv_input.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
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
<!-- Copyright (c) 2021, Brian Junker-Latocha
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. -->
<!doctype html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Primary Meta Tags -->
<meta name="description" content="a framework for clustering research notes">
<meta name="title" content="Xzerpt Card Creator">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://xzerpt.com/csv_input.html">
<meta property="og:title" content="Xzerpt Card Creator">
<meta property="og:description" content="a framework for clustering research notes">
<meta property="og:image" content="https://xzerpt.com/exampleImages/xzerpt.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://xzerpt.com/csv_input.html">
<meta property="twitter:title" content="Xzerpt">
<meta property="twitter:description" content="a framework for clustering research notes">
<meta property="twitter:image" content="https://xzerpt.com/exampleImages/xzerpt.png">
<head>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<script id="tableBlock" type="text/html">
<table class="styled-table" width="100%" height="30" border="1">
<tr>
<th><font size="5">DDD</font></th>
<th><font size="5">Type: TTT</font></th>
<th><font size="5">Source: SSS</font></th>
<th><font size="5">Page: PPP</font></th>
</tr>
</table>
<table class="styled-table" width="100%" height="380" border="1">
<tr>
<th width="25%" height="30"><font size="5">Topic</font></th>
<th width="75%" height="30"><font size="5">Statement</font></th>
</tr>
<tr>
<td height="380"><font size="5">TPTP</font></td>
<td height="380"><font size="5">SUSU</font></td>
</tr>
</table>
</script>
<script>
function appendToStorage(name, data){
var old = localStorage.getItem(name);
if(old === null) old = "";
localStorage.setItem(name, old + data);
}
function clear_and_gen_tables(){
var csv_data = localStorage.getItem('all_csv');
console.log("this is csv_data");
console.log(csv_data);
var rows = csv_data.split('\\r\\n');
rows = rows[0].split('\r\n');
console.log("this is rows:");
console.log(rows);
var id_count = parseInt(document.getElementById("id_start").value) -1;
document.getElementById("targetElement").innerHTML = "";
for (row of rows){
if (row == ''){
continue;
}
id_count += 1;
console.log("this is a row")
console.log(row)
var fields = row.split('|');
var div = document.createElement('div');
div.setAttribute('class', 'avoid');
div.innerHTML = document.getElementById('tableBlock').innerHTML;
var br = document.createElement('br');
// You could optionally even do a little bit of string templating
div.innerHTML = div.innerHTML
.replace(/DDD/g, id_count)
.replace(/TTT/g, fields[0])
.replace(/SSS/g, fields[1])
.replace(/PPP/g, fields[2])
.replace(/TPTP/g, fields[3])
.replace(/SUSU/g, fields[4]);
document.getElementById('targetElement').appendChild(div);
document.getElementById('targetElement').appendChild(br);
}
localStorage.setItem('all_csv', '');
}
function dragOverHandler(ev) {
console.log('File(s) in drop zone');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
}
function removeDragData(ev) {
console.log('Removing drag data');
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to remove the drag data
ev.dataTransfer.items.clear();
} else {
// Use DataTransfer interface to remove the drag data
ev.dataTransfer.clearData();
document.getElementById("drop_zone").innerHTML = "Drag file(s) here to create Xzerpt cards from.";
}
}
function dropHandler(ev) {
// alert("Files Dropped!")
console.log('File(s) dropped');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.items.length; i++) {
// If dropped items aren't files, reject them
if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile();
var fileNameP = document.createElement("li");
fileNameP.innerHTML = ev.dataTransfer.files[i].name;
document.getElementById("drop_zone").appendChild(fileNameP);
console.log('... file[' + i + '].name = ' + file.name);
var fr = new FileReader();
fr.onload = function(e) {
// e.target.result should contain the text
appendToStorage('all_csv', e.target.result.toString());
};
fr.readAsText(file);
}
}
} else {
// Use DataTransfer interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
var fileNameP = document.createElement("li");
fileNameP.innerHTML = ev.dataTransfer.files[i].name;
document.getElementById("drop_zone").appendChild(fileNameP);
var fr = new FileReader();
fr.onload = function(e) {
// e.target.result should contain the text
appendToStorage('all_csv', e.target.result.toString());
};
fr.readAsText(file);
}
}
console.log("heres local csv storage:");
console.log(localStorage.getItem('all_csv'));
// Pass event to removeDragData for cleanup
removeDragData(ev)
}
</script>
<title>Xzerpt Card Creator</title>
<style>
*{
font-family: "Trebuchet MS";
}
.styled-table {
font-family: "Trebuchet MS";
border-collapse: collapse;
width: 100%;
}
.styled-table td, .styled-table th {
border: 2px solid black;
padding: 8px;
}
.styled-table th {
/* padding-top: 12px;
padding-bottom: 12px; */
/* text-align: left; */
background-color: white;
color: black;
}
.avoid {
page-break-inside: avoid !important;
margin: 4px 0 4px 0; /* to keep the page break from cutting too close to the text in the div */
}
input[type=button], input[type=submit], input[type=reset], button[type=button] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
#drop_zone {
/* border: 5px solid blue; */
width: 200px;
height: 200px;
background-color: #0e70e0;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
overflow:auto;
}
input[type=button], input[type=submit], input[type=reset] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body id="targetElement">
<h1>Xzerpt Card Creator</h1>
<div id="drop_zone" class="container" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
<ul id="drop_text">Drag file(s) here to create Xzerpt cards from.</ul>
</div>
<br/>
<label for="id_start">Number to start IDs from:</label><br/>
<input id="id_start" type="number" name="id_start" min="1" value="1">
<br/>
<button type="button" id="send_files" onclick="clear_and_gen_tables()">Create Cards</button>
<br/>
<p>By <a href="https://thejunkyard.cc">Brian Junker-Latocha</a>.</p>
<p>See Github for <a href="https://github.com/BrianInGermany/Xzerpt">code and instructions</a>.</p>
</body>
<script>
</script>
</html>