This repository was archived by the owner on Feb 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
415 lines (367 loc) · 13.5 KB
/
app.js
File metadata and controls
415 lines (367 loc) · 13.5 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
const select_from = document.getElementById('select_from');
const select_to = document.getElementById('select_to');
const div_diff = document.getElementById('div_diff');
const stats = document.getElementById('stats');
const added_types = document.getElementById('added_types');
const added_functions = document.getElementById('added_functions');
const removed_types = document.getElementById('removed_types');
const removed_functions = document.getElementById('removed_functions');
const changed_types = document.getElementById('changed_types');
const changed_functions = document.getElementById('changed_functions');
const added_div = document.getElementById('added_div');
const removed_div = document.getElementById('removed_div');
const changed_div = document.getElementById('changed_div');
const added_types_div = document.getElementById('added_types_div');
const added_functions_div = document.getElementById('added_functions_div');
const removed_types_div = document.getElementById('removed_types_div');
const removed_functions_div = document.getElementById('removed_functions_div');
const changed_types_div = document.getElementById('changed_types_div');
const changed_functions_div = document.getElementById('changed_functions_div');
const collapsed_diff = [];
for (const layer of DIFF) {
const cdl = collapsed_diff.length;
if (cdl === 0
|| collapsed_diff[cdl - 1].layer === null
|| collapsed_diff[cdl - 1].layer !== layer.layer) {
collapsed_diff.push(layer); // first or different
} else {
collapsed_diff[cdl - 1] = layer; // replace same layer (keep latest)
}
}
let used_diff = collapsed_diff;
const get_url_query_param = param =>
(
(window.location.href.split("?")[1] || "")
.split("&")
.map(part => part.split("="))
.find(kv => kv[0] == param) || []
)[1] || null;
function change_used_diff(event) {
used_diff = event.target.checked ? collapsed_diff : DIFF;
fill_select_boxes();
load_diff();
}
function layer_name(layer) {
const name = layer.layer == null ? 'Unknown layer' : `Layer ${layer.layer}`;
const date = new Date(layer.date * 1000);
const year = date.getFullYear();
const month = `0${date.getMonth() + 1}`.slice(-2);
const day = `0${date.getDate()}`.slice(-2);
return `[${year}-${month}-${day}] ${name}`;
}
function toggle_expand(event) {
const div = event.target.parentElement.parentElement;
const tags = div.getElementsByTagName('details');
// open all if any is closed, close all only if all are open
let any_closed = false;
for (const details of tags) {
if (!details.open) {
any_closed = true;
break;
}
}
for (const details of tags) {
details.open = any_closed;
}
}
function fill_select_boxes(from_layer, to_layer) {
let from = null;
let to = null;
from_layer = parseInt(from_layer);
to_layer = parseInt(to_layer);
empty_node(select_from);
empty_node(select_to);
for (let i = 0; i < used_diff.length; ++i) {
const layer = used_diff[i];
if (i !== used_diff.length - 1) {
const option = document.createElement('option');
option.value = i;
option.innerText = layer_name(layer);
select_from.appendChild(option);
}
if (i !== 0) {
const option = document.createElement('option');
option.value = i;
option.innerText = layer_name(layer);
select_to.appendChild(option);
}
if (from === null && from_layer == layer.layer) {
from = i;
}
if (to === null && to_layer == layer.layer) {
to = i - 1;
}
}
select_from.selectedIndex = from || used_diff.length - 2;
select_to.selectedIndex = to || used_diff.length - 2;
}
function change_select_from() {
if (select_from.selectedIndex > select_to.selectedIndex) {
select_from.selectedIndex = select_to.selectedIndex;
}
}
function change_select_to() {
if (select_to.selectedIndex < select_from.selectedIndex) {
select_to.selectedIndex = select_from.selectedIndex;
}
}
function empty_node(node) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
function empty_diff_lists() {
empty_node(added_types);
empty_node(added_functions);
empty_node(removed_types);
empty_node(removed_functions);
empty_node(changed_types);
empty_node(changed_functions);
}
function append_li(ul, ...args) {
for (const arg of args) {
const li = document.createElement('li');
if (typeof arg === 'string') {
li.appendChild(document.createTextNode(arg))
} else if (arg instanceof Element) {
li.appendChild(arg);
} else {
const span = document.createElement('span');
span.className = arg.class;
span.appendChild(document.createTextNode(arg.value));
li.appendChild(span);
}
ul.appendChild(li);
}
}
function append_li_migrate(ul, from, to, name) {
const li = document.createElement('li');
if (name !== undefined) {
li.appendChild(document.createTextNode(`${name} `));
}
{
const span = document.createElement('span');
span.className = 'old';
span.appendChild(document.createTextNode(from));
li.appendChild(span);
}
li.appendChild(document.createTextNode(' → '));
{
const span = document.createElement('span');
span.className = 'new';
span.appendChild(document.createTextNode(to));
li.appendChild(span);
}
ul.appendChild(li);
}
function extend_list(list, items) {
sorted_items = [];
for (const [name, item] of Object.entries(items)) {
sorted_items.push(item);
}
sorted_items.sort((a, b) => a.name.localeCompare(b.name));
for (item of sorted_items) {
const summary = document.createElement('summary');
summary.appendChild(document.createTextNode(item.name));
const details = document.createElement('details');
details.appendChild(summary);
const ul = document.createElement('ul');
if (item.id !== null) {
append_li(ul, `#${('00000000' + item.id.toString(16)).slice(-8)}`);
}
for (arg of item.fields) {
append_li(ul, `${arg.name}:${arg.type}`);
}
{
append_li(`= ${item.type}`);
}
details.appendChild(ul);
const li = document.createElement('li');
li.appendChild(details);
list.appendChild(li);
}
}
function extend_change_list(list, items) {
sorted_items = [];
for (const [name, item] of Object.entries(items)) {
sorted_items.push(item);
}
sorted_items.sort((a, b) => a.after.name.localeCompare(b.after.name));
for (item of sorted_items) {
const summary = document.createElement('summary');
summary.appendChild(document.createTextNode(item.after.name));
const details = document.createElement('details');
details.appendChild(summary);
const ul = document.createElement('ul');
if (item.before.id !== item.after.id) { // neither null nor the same
if (item.before.id === null) {
append_li(ul, {
class: 'new',
value: `#${('00000000' + item.after.id.toString(16)).slice(-8)}`
});
} else if (typeof item.after.id === null) {
append_li(ul, {
class: 'old',
value: `#${('00000000' + item.before.id.toString(16)).slice(-8)}`
});
} else {
append_li_migrate(
ul,
`#${('00000000' + item.before.id.toString(16)).slice(-8)}`,
`#${('00000000' + item.after.id.toString(16)).slice(-8)}`
);
}
}
// fields are a list because their order matters, so that's why
// it's not a map already. we however work better with maps here.
old_args = {};
for (arg of item.before.fields) {
old_args[arg.name] = arg;
}
new_args = {};
for (arg of item.after.fields) {
new_args[arg.name] = arg;
}
// figure out changed items
for (arg of item.before.fields) {
const current = new_args[arg.name];
if (typeof current !== 'undefined' && arg.type !== current.type) {
append_li_migrate(ul, arg.type, current.type, arg.name);
}
}
// figure out removed items
for (arg of item.before.fields) {
if (!new_args.hasOwnProperty(arg.name)) {
append_li(ul, {class: 'old', value: `${arg.name}:${arg.type}`});
}
}
// figure out new items
for (arg of item.after.fields) {
if (!old_args.hasOwnProperty(arg.name)) {
append_li(ul, {class: 'new', value: `${arg.name}:${arg.type}`});
}
}
details.appendChild(ul);
const li = document.createElement('li');
li.appendChild(details);
list.appendChild(li);
}
}
function update_added(from, to, kind) {
for (item of from.added[kind]) {
if (item.name in to.removed[kind]) {
// if it was removed and then added again, it was changed (probably)
const before = to.removed[kind][item.name];
if (item.id !== before.id) {
to.changed[kind][item.name] = {
before: before,
after: item
};
}
} else {
// if it was only added, it was added
to.added[kind][item.name] = item;
}
// in any case, it was removed from removed
delete to.removed[kind][item.name];
}
}
function update_removed(from, to, kind) {
for (item of from.removed[kind]) {
// in any case, it is added to removed, and removed from both added and changed
to.removed[kind][item.name] = item;
delete to.added[kind][item.name];
delete to.changed[kind][item.name];
}
}
function update_changed(from, to, kind) {
for (item of from.changed[kind]) {
if (item.after.name in to.added[kind]) {
// if something was added and then changes, it was still newly added
} else {
to.changed[kind][item.after.name] = item;
}
}
}
function set_visible_ty_fn(main, ty, fn, where) {
const ty_count = Object.keys(where.types).length;
const fn_count = Object.keys(where.functions).length;
if (ty_count === 0 && fn_count === 0) {
main.style.display = 'none';
} else {
main.style.display = '';
ty.style.display = ty_count === 0 ? 'none' : '';
fn.style.display = fn_count === 0 ? 'none' : '';
}
}
function set_td_text(tr, index, object) {
tr.children[index].replaceChild(
document.createTextNode(Object.keys(object).length.toString()),
tr.children[index].lastChild
)
}
function fill_stats(diff) {
const tbody = stats.children[1];
const ty = tbody.children[0];
const fn = tbody.children[1];
set_td_text(ty, 1, diff.added.types);
set_td_text(fn, 1, diff.added.functions);
set_td_text(ty, 2, diff.removed.types);
set_td_text(fn, 2, diff.removed.functions);
set_td_text(ty, 3, diff.changed.types);
set_td_text(fn, 3, diff.changed.functions);
}
function load_diff() {
div_diff.style.display = 'none';
let from_idx = Number(select_from.value);
let to_idx = Number(select_to.value);
if (used_diff == collapsed_diff) {
// figure out indices in the original diff with all data
let needle = used_diff[from_idx];
for (let i = from_idx; i < DIFF.length; ++i) {
if (needle == DIFF[i]) {
from_idx = i;
break;
}
}
needle = used_diff[to_idx];
for (let i = to_idx; i < DIFF.length; ++i) {
if (needle == DIFF[i]) {
to_idx = i;
break;
}
}
}
const diff = {
added: {types: {}, functions: {}},
removed: {types: {}, functions: {}},
changed: {types: {}, functions: {}}
};
for (let i = from_idx + 1; i <= to_idx; ++i) {
const layer = DIFF[i];
update_added(layer, diff, 'types');
update_added(layer, diff, 'functions');
update_removed(layer, diff, 'types');
update_removed(layer, diff, 'functions');
update_changed(layer, diff, 'types');
update_changed(layer, diff, 'functions');
}
empty_diff_lists();
extend_list(added_types, diff.added.types);
extend_list(added_functions, diff.added.functions);
extend_list(removed_types, diff.removed.types);
extend_list(removed_functions, diff.removed.functions);
extend_change_list(changed_types, diff.changed.types);
extend_change_list(changed_functions, diff.changed.functions);
// default to showing everything, hide as needed
set_visible_ty_fn(added_div, added_types_div, added_functions_div, diff.added);
set_visible_ty_fn(removed_div, removed_types_div, removed_functions_div, diff.removed);
set_visible_ty_fn(changed_div, changed_types_div, changed_functions_div, diff.changed);
fill_stats(diff);
div_diff.style.display = '';
}
div_diff.style.display = 'none';
select_from.addEventListener('change', load_diff);
select_to.addEventListener('change', load_diff);
fill_select_boxes(get_url_query_param('from'), get_url_query_param('to'));
load_diff();