-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
360 lines (329 loc) · 12.5 KB
/
index.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<title>DM nv dump viewer</title>
<style>
body {
font-family: Arial, sans-serif;
/*margin: 0 auto;*/
padding: 0px;
margin: 0px;
line-height: 1.6;
background-color: #000;
color: #fff;
}
#fileInput,
#searchInput {
width: 100%;
padding: 10px;
box-sizing: border-box;
border: none;
}
#searchInput {
background-color: #222;
}
.table-container {
max-height: calc(100vh - 45px);
overflow-y: auto;
position: relative;
border: 1px solid #222;
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
thead {
position: sticky;
top: -1px;
z-index: 1;
padding-top: 22px;
background: #222;
}
th,
td {
border: 1px solid #222;
padding: 3px 5px;
text-align: left;
overflow: scroll;
}
th {
font-weight: bold;
}
.payload-value {
display: inline-block;
padding: 2px 6px 0 6px;
margin: 2px;
border-radius: 3px;
font-family: monospace;
font-weight: bold;
}
.payload-value:hover {
background-color: #555;
}
.u8-value {
background-color: #4a371d;
}
.u16-value {
background-color: #30363d;
}
.u32-value {
background-color: #2e2a25;
}
.u64-value {
background-color: #2d252e;
}
#message {
text-align: center;
color: #666;
margin-top: 20px;
}
#loading {
background: #333;
padding: 20px;
display: none;
}
.stats {
margin: 10px 10px;
font-size: 0.9em;
color: #666;
}
.flex-container {
display: flex;
flex-wrap: nowrap;
}
.flex-container > div {
width: 100%;
}
[data-tooltip]:hover::after {
pointer-events: none;
display: block;
position: absolute;
content: attr(data-tooltip);
background: white;
color: black;
padding: 5px 10px 3px 10px;
border-radius: 3px;
}
</style>
</head>
<body>
<div class="flex-container">
<input
type="text"
id="searchInput"
placeholder="Search (min 2 characters)..."
disabled
/>
<div class="stats">
<span id="displayedEntries">0</span> /
<span id="totalEntries">0</span>
</div>
<input type="file" id="fileInput" accept=".json" />
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th style="width: 45px">Index</th>
<th style="width: 40%">Registry Name</th>
<th style="width: 56%">Payload</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
<div id="loading">Processing data...</div>
<script>
const CHUNK_SIZE = 50; // Number of rows to render at once
const BUFFER_SIZE = 100; // Number of rows to keep in memory above/below viewport
let jsonData = [];
let filteredData = [];
let visibleData = [];
let lastScrollTop = 0;
let isProcessing = false;
let currentChunk = 0;
const tableBody = document.getElementById("tableBody");
const tableContainer = document.querySelector(".table-container");
const loading = document.getElementById("loading");
const totalEntriesSpan = document.getElementById("totalEntries");
const displayedEntriesSpan =
document.getElementById("displayedEntries");
function hexToDec(hex) {
let bytes = hex.split(",").reverse().join("");
let decimal = parseInt(bytes, 16);
return decimal;
}
const typeByteSize = {
u8: 1,
s8: 1,
u16: 2,
s16: 2,
u32: 4,
s32: 4,
uint: 4,
u64: 8,
s64: 8,
char: 1,
bool: 4,
};
const tooltipClassMapping = {
1: "u8-value",
2: "u16-value",
4: "u32-value",
8: "u64-value",
};
function parsePayload(payload, typeName) {
const values = payload.split(",");
let html = "";
const byteSize = typeByteSize[typeName];
if (typeName === "char") {
const escapeMap = {
"<": "<",
">": ">",
'"': """,
"&": "&",
};
html += `<span>${values
.map((value) => {
let val = String.fromCharCode(parseInt(value, 16));
return escapeMap[val] || val;
})
.join("")}</span>`;
} else if (typeName === "bool") {
for (let i = 0; i < values.length; i += byteSize) {
const value = values.slice(i, i + byteSize).join(",");
html += `<span class="payload-value u64-value">${Boolean(Number(value[1]))}</span>`;
}
} else {
for (let i = 0; i < values.length; i += byteSize) {
const value = values.slice(i, i + byteSize).join(",");
const hexClass =
tooltipClassMapping[byteSize] || "default-value";
html += `<span data-tooltip="${i / byteSize}: ${hexToDec(value)}" class="payload-value ${hexClass}">${value}</span>`;
}
}
return html;
}
function updateStats() {
totalEntriesSpan.textContent = jsonData.length;
displayedEntriesSpan.textContent = visibleData.length;
}
function renderChunk(startIndex, endIndex) {
const fragment = document.createDocumentFragment();
for (
let i = startIndex;
i < endIndex && i < visibleData.length;
i++
) {
const item = visibleData[i];
const row = document.createElement("tr");
const indexCell = document.createElement("td");
indexCell.textContent = item.Index;
row.appendChild(indexCell);
const nameCell = document.createElement("td");
nameCell.textContent = item.RegistryName;
row.appendChild(nameCell);
const payloadCell = document.createElement("td");
payloadCell.innerHTML = parsePayload(
item.Payload,
item.TypeName,
);
row.appendChild(payloadCell);
fragment.appendChild(row);
}
tableBody.appendChild(fragment);
updateStats();
}
function processJsonChunk(reader, accumulator = "") {
loading.style.display = "block";
reader.read().then(({ done, value }) => {
if (done) {
try {
const jsonString = accumulator.trim();
jsonData = JSON.parse(
jsonString.startsWith("{")
? `[${jsonString}]`
: jsonString,
);
visibleData = jsonData;
document.getElementById("searchInput").disabled =
false;
renderChunk(0, CHUNK_SIZE);
loading.style.display = "none";
} catch (error) {
alert("Invalid JSON format");
loading.style.display = "none";
}
return;
}
accumulator += new TextDecoder().decode(value);
requestAnimationFrame(() =>
processJsonChunk(reader, accumulator),
);
});
}
function handleScroll() {
if (isProcessing) return;
const scrollTop = tableContainer.scrollTop;
const containerHeight = tableContainer.clientHeight;
const totalHeight = tableContainer.scrollHeight;
// Calculate if we're near bottom
if (scrollTop + containerHeight > totalHeight - 200) {
isProcessing = true;
const nextChunk = currentChunk + 1;
const startIndex = nextChunk * CHUNK_SIZE;
const endIndex = startIndex + CHUNK_SIZE;
if (startIndex < visibleData.length) {
renderChunk(startIndex, endIndex);
currentChunk = nextChunk;
}
isProcessing = false;
}
}
document
.getElementById("fileInput")
.addEventListener("change", function (e) {
const file = e.target.files[0];
if (file) {
tableBody.innerHTML = "";
currentChunk = 0;
const reader = file.stream().getReader();
processJsonChunk(reader);
}
});
let searchTimeout;
document
.getElementById("searchInput")
.addEventListener("input", function (e) {
clearTimeout(searchTimeout);
const searchTerm = e.target.value.toLowerCase();
searchTimeout = setTimeout(() => {
if (searchTerm.length >= 2) {
visibleData = jsonData.filter(
(item) =>
item.Index.toString().includes(
searchTerm,
) ||
item.RegistryName.toLowerCase().includes(
searchTerm,
) ||
item.Payload.toLowerCase().includes(
searchTerm,
),
);
} else {
visibleData = jsonData;
}
tableBody.innerHTML = "";
currentChunk = 0;
renderChunk(0, CHUNK_SIZE);
}, 0);
});
tableContainer.addEventListener("scroll", handleScroll);
</script>
</body>
</html>