-
Notifications
You must be signed in to change notification settings - Fork 10
/
dump_reader.html
75 lines (64 loc) · 1.57 KB
/
dump_reader.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
<!DOCTYPE html>
<html>
<head>
<title>HTML5 File API</title>
<meta charset="UTF-8" />
<style>
body {
font-family: helvetica, sans-serif;
}
tbody {
font-family: courier new, monospaced;
}
tr:nth-child(even) {
background-color: #def
}
</style>
</head>
<body>
<input type="file" onchange="loadFile(this)"/>
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody id="results">
</tbody>
</table>
<script>
function loadFile(input) {
var file = input.files[0]
console.log(file)
var fileReader = new FileReader();
fileReader.onload = function(e) {
var output = ''
document.getElementById('results').innerHTML = output
var text = e.target.result
var lines = text.split('\n')
for(var i in lines) {
var line = lines[i]
if( !line || line[0] == '#' )
continue
var tokens = line.split('\t')
var key = JSON.parse( tokens[0] )
var val = JSON.parse( tokens[1] )
output += '<tr><td>' + key + '</td><td>' + val + '</td></tr>'
if( i > 100 )
break
}
document.getElementById('results').innerHTML = output
//document.getElementById('output').innerHTML = JSON.stringify(items,null,2)
};
fileReader.onerror = function(e) {
console.log(e.target.error.name);
};
fileReader.onprogress = function(e) {
console.log(e.loaded, e.total);
};
fileReader.readAsText(file);
}
</script>
</body>
</html>