-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
87 lines (74 loc) · 2.55 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
<html lang="en">
<style>
body {
background: #202124;
color: #e1e1e1;
}
</style>
<body>
<label for="json1">Json 1</label>
<br>
<textarea id="json1" rows="4" cols="50"></textarea>
<br>
<label for="json2">Json 2</label>
<br>
<textarea id="json2" rows="4" cols="50"></textarea>
<br>
<br>
<button id="btnMerge">Merge</button>
<br>
<br>
<label for="finalJson">Merged Json</label>
<br>
<textarea id="finalJson" rows="4" cols="50" readonly></textarea>
<br>
<br>
<button id="btnCopy">Copy result</button>
</body>
<script>
document.getElementById("btnMerge").addEventListener("click", ev => {
const json1Str = document.getElementById('json1').value
const json2Str = document.getElementById('json2').value
try
{
const json1 = JSON.parse(json1Str)
const json2 = JSON.parse(json2Str)
if(!json1.hasOwnProperty("overrides"))
{
json1["overrides"] = []
}
if(!json2.hasOwnProperty("overrides"))
{
alert("Json 2 doesn't contain 'overrides' property.")
return;
}
json1["overrides"] = json1["overrides"].concat(json2["overrides"]);
function compare(a, b) {
try {
if (a.predicate.custom_model_data < b.predicate.custom_model_data) {
return -1
}
if (a.predicate.custom_model_data > b.predicate.custom_model_data) {
return 1
}
} catch (error) {
console.error(error)
}
return 0
}
json1["overrides"].sort(compare)
document.getElementById("finalJson").value = JSON.stringify(json1, null, 2)
}
catch (ex)
{
alert(ex.message)
console.error("Exception thrown", e.stack);
}
});
document.getElementById("btnCopy").addEventListener("click", ev => {
const finalJson = document.getElementById("finalJson");
navigator.clipboard.writeText(finalJson.value);
alert("Copied to clipboard");
});
</script>
</html>