-
Notifications
You must be signed in to change notification settings - Fork 0
/
proped.html
376 lines (329 loc) · 19.4 KB
/
proped.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!doctype html>
<html lang="en">
<head>
<title>PropEd</title>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/jpg" href="data:image"/>
<link href="data:image/x-icon;base64,AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuLi4WMjIykzIyMuMyMjL9MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8yMjL3MjIyxjExMVcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDAwJTIyMuUzMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zExMZUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEyMjLMMzMz/zIyMv4zMzOvMzMzeDIyMnUyMjJ1MjIydTIyMnUyMjJ1MjIydTIyMnUyMjJ1MjIyhDIyMtozMzP/MzMz/zExMVcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzMzPDMzM/8zMzP/MjIyfv///////////////////////////////////////////////////////////////zMzM74zMzP/MjIyxgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMTFtMzMz/zMzM///////////////////////////////////////////////////////////////////////MjIydTMzM/8yMjL3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIyMnUzMzP/MzMz//////////////////////////////////////////////////////////////////////8yMjJ1MzMz/zMzM/8AAAAAAAAAADIyMjMyMjKeMjIy0DMzM9czMzPXMzMz1zMzM9czMzPXMzMz1zMzM9czMzPXMjIy6DIyMv0yMjL+////////////////////////////////+Pj4pi4uLib//////////////////////////zIyMnUzMzP/MzMz/wAAAAAzMzNuMjIy/DMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzPN/////////////////////zAwMEUyMjLqMDAwSf//////////////////////////MjIydTMzM/8zMzP/MzMzQTIyMv0zMzP/MjIy9DIyMqwyMjKcMjIynDIyMpwyMjKcMjIynDIyMpwyMjKcMjIynDExMZ8yMjLQMzMz/zMzM/8yMjK2//////////8yMjJ/MjIy/DMzM/8wMDBJ//////////////////////////8yMjJ1MzMz/zMzM/8zMzO5MzMz/zIyMu0uLi4m//////////////////////////////////////////////////////////8yMjJ1MzMz/zMzM/4wMDBEMTExuDMzM/8zMzP/MzMz/zIyMmUtLS0nLS0tJy4uLib//////////zIyMnUzMzP/MzMz/zIyMvMzMzP/MjIyjf////////////////////////////////////////////////////////////////////8zMzP/MzMz/zIyMvszMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz+v//////////MjIydTMzM/8zMzP/MjIy/jMzM/8xMTF2/////////////////////////////////////////////////////////////////////zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP6//////////8yMjJ1MzMz/zMzM/8zMzP/MzMz/zMzM3j//////////////////////////zExMST/////////////////////////////////////MzMz/zMzM/8yMjKeMjIy1TMzM/8zMzP/MzMz/zExMYExMTFOMTExTjExMU3//////////zIyMnUzMzP/MzMz/zMzM/8zMzP/MjIyev//////////////////////////MjIyeTExMbj///////////////////////////////8zMzP/MzMz/zIyMnX/////MjIypjMzM/8zMzP/MDAwSf//////////////////////////MjIydTMzM/8zMzP/MzMz/zMzM/8zMzN9//////////////////////////8yMjJ5MzMz/zIyMuIyMjI4/////////////////////zMzM/8zMzP/MjIydf//////////MjIyajIyMvgwMDBJ//////////////////////////8yMjJ1MzMz/zMzM/8zMzP/MzMz/zIyMn///////////////////////////zIyMnkzMzP/MzMz/zIyMvkzMzNu////////////////MzMz/zMzM/8yMjJ1////////////////MDAwNTMzMzL//////////////////////////zIyMnUzMzP/MzMz/zMzM/8zMzP/MTExgf////8vLy8rMzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzOq//////////8zMzP/MzMz/zIyMnX/////////////////////////////////////////////////////MjIydTMzM/8zMzP/MzMz/zMzM/8yMjKD/////y8vLyszMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zIyMvQzMzNL/////zMzM/8zMzP/MjIydf////////////////////////////////////////////////////8zMzOCMzMz/zIyMvczMzP/MzMz/zExMYX//////////zIyMnUyMjJ1MjIydTIyMrczMzP/MzMz/zMzM/8zMzPXLy8vK///////////MzMz/zMzM/8yMjJ1////////////////////////////////MTExcTIyMokyMjKJMTExlDMzM/AzMzP/MTExpDMzM/8zMzP/MjIyiP//////////////////////////MjIyeTMzM/8zMzP/MjIyqP////////////////////8zMzP/MzMz/zIyMnX//////////////////////////zMzM1UzMzP/MzMz/zMzM/8zMzP/MzMz/zIyMs4kJCQOMzMz/zMzM/8xMTGK//////////////////////////8yMjJ5MjIy+DExMWz//////////////////////////zMzM/8zMzP/MjIydf//////////////////////////MTExYTMzM/8zMzP/MzMz/zMzM/8zMzPNKioqEgAAAAAzMzP/MzMz/zMzM4z//////////////////////////zExMVwvLy82////////////////////////////////MzMz/zMzM/8yMjJ1//////////////////////////8xMTFhMzMz/zMzM/8zMzP/MjIyyi0tLREAAAAAAAAAADMzM/8zMzP/MjIyjv////////////////////////////////////////////////////////////////////8zMzP/MzMz/zIyMnX//////////////////////////zExMYAzMzP/MzMz/zIyMssvLy8QAAAAAAAAAAAAAAAAMzMz/zMzM/8xMTGQ/////////////////////////////////////////////////////////////////////zMzM/8zMzP/MzMzyDIyMpwyMjKcMjIynDIyMpwyMjKrMjIy+TMzM/8zMzPNLS0tEQAAAAAAAAAAAAAAAAAAAAAzMzP/MzMz/zIyMpP///////////////////////////////////////////Dw8IAyMjJgMTExYjAwMGMyMjKiMzMz/zIyMv4yMjL8MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMzzSgoKBMAAAAAAAAAAAAAAAAAAAAAAAAAADMzM/8zMzP/MTExlf//////////////////////////////////////////MjIy0zMzM/8zMzP/MzMz/zMzM/8zMzP/MjIyxjIyMtUzMzPXMzMz1zMzM9czMzPXMjIy0zMzM5EqKioMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzMz/zMzM/8yMjKX//////////////////////////////////////////8zMzPrMzMz/zMzM/8zMzP/MjIy/jIyMn4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyMjL3MzMz/zExMZr//////////////////////////////////////////zMzM+szMzP/MzMz/zIyMv4yMjJ6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADIyMsUzMzP/MjIy4v//////////////////////////////////////////MjIy9jMzM/8yMjL+MzMzeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTExVzMzM/8zMzP/MzMz4TIyMoQyMjJ1MjIydTIyMnUyMjJ0MTExdjIyMrwzMzP/MzMz/zExMXwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTExlDMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zMzM/8zMzP/MzMz/zIyMv4yMjJ/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTExVzIyMsUyMjL3MzMz/zMzM/8zMzP/MzMz/zIyMv4yMjLlMDAwYwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//4AA//8AAH/+AAA//gAAP/4AAD/+AAAwAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAwAAAAcAAAAPAAAAHwAAAD8AAH//AAD//wAB//8AA///gAf//8AP//8=" rel="icon" type="image/x-icon" />
<style>
table#entries {
width: 100%;
}
table.hideSame#entries tr.same {
display: none;
}
table.hideNew#entries tr.new {
display: none;
}
table.hideDifferent#entries tr.different {
display: none;
}
table#entries {
margin-top: 3.3em;
table-layout: fixed;
}
tr {
transition-property: background-color;
transition-duration: .1s;
}
tr.skip {
opacity: .3;
}
tr.same td {
/* color: #4caf50; */
color: #aaa;
}
tr.different td {
color: #f44336;
}
tr.new td {
/* color: #2196f3; */
color: #4caf50;
}
tbody tr:hover th, tbody tr:hover td {
background-color: #fffce1;
}
tbody tr:hover td:hover {
background-color: #fff6a4 !important;
}
tbody th {
cursor: default;
}
th {
background-color: #eeeeee;
font-weight: normal;
border-radius: .4em;
padding: .4em 0;
word-wrap: break-word;
}
td.propval {
cursor: pointer;
word-wrap: break-word;
border-radius: .4em;
padding: .4em .2em;
}
td.propval:hover {
/* text-decoration: underline; */
}
.hidden {
display: none !important;
}
#downloadLink {
display: none;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
#toolbar {
position: fixed;
top: 0;
height: auto;
width: 100%;
background-color: white;
padding: .2em;
left: -5px;
box-shadow: 0 0 5px #000;
}
#toolbar button, #toolbar input[type="file"] {
padding: .4em;
border-radius: .4em;
border: 1px solid #cccccc;
cursor: pointer;
}
#toolbar button:hover, #toolbar input[type="file"]:hover {
background-color: #e0e0e0;
}
.finalValue {
color: #999999 !important;
}
.finalValue > input {
width: calc(100% - 6em);
padding: .4em;
border-radius: .4em;
border: 1px solid #cccccc;
}
.finalValue > input:focus {
box-shadow: inset 0 0 5px #ddd;
}
.finalValue label {
width: 5em;
display: inline-block;
cursor: pointer;
}
.finalValue label:hover {
color: #222222;
}
.finalValue label input {
cursor: pointer;
}
#filters label, #filters label input {
cursor: pointer;
}
</style>
</head>
<body>
<div id="toolbar">
<input type="file" id="first">
<input type="file" id="second">
<button id="action" disabled="disabled">Load files</button>
<button id="downloadButton" disabled="disabled">Download</button>
<a id="downloadLink" download="local.properties">test</a>
</div>
<table id="entries">
<thead>
<tr><th colspan="4" id="filters">
show:
<label><input type="checkbox" checked="checked" id="showEqual" data-filter="Same">equal</label>
<label><input type="checkbox" checked="checked" id="showDifferent" data-filter="Different">different</label>
<label><input type="checkbox" checked="checked" id="showNew" data-filter="New">new</label>
</th></tr>
<tr><th>key</th><th class="firstFileName">first</th><th class="secondFileName">second</th><th>final</th></tr>
</thead>
<tbody>
<tr><td colspan="4">Pick two .properties files to compare.</td></tr>
</tbody>
<tfoot>
<tr><th>key</th><th class="firstFileName">first</th><th class="secondFileName">second</th><th>final</th></tr>
</tfoot>
</table>
<script>
const first = document.getElementById('first');
const second = document.getElementById('second');
const actionButton = document.getElementById('action');
const table = document.getElementById('entries');
const downloadButton = document.getElementById('downloadButton');
const downloadLink = document.getElementById('downloadLink');
// handle filter clicks
document.querySelectorAll('#filters input[type="checkbox"]').forEach((item) => {
item.addEventListener('change', () => {
table.classList.toggle(`hide${item.dataset.filter}`, !item.checked);
})
});
// handle load files action
actionButton.addEventListener('click', loadFiles);
// handle download button
downloadButton.addEventListener('click', collectEntries);
// auto-load properties
[first, second].forEach((item) => {
item.addEventListener('change', (obj) => {
actionButton.disabled = (first.files.length == 0 || second.files.length == 0);
if (!actionButton.disabled) {
actionButton.click();
}
})
});
// create table row
function createRow(key, value1, value2) {
const tr = document.createElement('tr');
tr.id = key;
tr.classList.add(value1 == value2 ? "same" : ((value1 == "" || value2 == "") ? "new" : "different"));
const th = document.createElement('th');
th.textContent = key;
tr.appendChild(th);
[value1, value2].forEach(val => {
const td = document.createElement('td');
td.textContent = val;
td.classList.add('propval');
td.title = "Select this value";
td.addEventListener('click', () => {
document.querySelector(`input[name="${key}"]`).value = val;
});
tr.appendChild(td);
});
const td = document.createElement('td');
td.classList.add('finalValue');
const input = document.createElement('input');
input.name = key;
input.type = 'text';
td.title = `Property: ${key}`;
td.appendChild(input);
const label = document.createElement('label');
const checkbox = document.createElement('input');
const span = document.createElement('span');
span.textContent = 'include';
checkbox.type = 'checkbox';
checkbox.checked = true;
checkbox.addEventListener('change', () => {
tr.classList.toggle('skip', !checkbox.checked);
});
span.title = "Include in final file"
label.appendChild(checkbox);
label.appendChild(span);
td.appendChild(label);
tr.appendChild(td);
if (value1 == "" || value2 == "" || value1 == value2) {
input.value = value1 || value2;
}
return tr;
}
// load both files and create table
async function loadFiles() {
actionButton.disabled = true;
downloadButton.disabled = true;
const [props1, props2] = await Promise.all([
getProperties(first.files[0]),
getProperties(second.files[0])
]);
// set table headers
table.querySelectorAll('.firstFileName').forEach((th) => {
th.textContent = first.files[0].name;
});
table.querySelectorAll('.secondFileName').forEach((th) => {
th.textContent = second.files[0].name;
});
const tbody = table.querySelector('tbody');
// reset filters
['hideSame', 'hideNew', 'hideDifferent'].forEach((name) => {
table.classList.remove(name);
});
document.querySelectorAll('#filters input[type="checkbox"]').forEach((item) => {
item.checked = true;
});
// remove rows
while (tbody.firstChild) {
tbody.removeChild(tbody.firstChild);
}
const rows = [];
for (let key in props1) {
if (props2.hasOwnProperty(key)) {
rows.push(createRow(key, props1[key], props2[key]));
delete props2[key];
} else {
rows.push(createRow(key, props1[key], ""));
}
}
for (let key in props2) {
rows.push(createRow(key, "", props2[key]));
}
rows.sort((first, second) => {
return first.id.toUpperCase() === second.id.toUpperCase() ? 0 : (first.id > second.id ? 1 : -1);
});
rows.forEach(row => {
tbody.appendChild(row);
});
downloadButton.disabled = false;
actionButton.disabled = false;
}
function collectEntries() {
let totalEmpty = 0;
table.querySelectorAll('tr.different').forEach((row) => {
if (row.querySelector('.finalValue input[type="text"]').value == "" && row.querySelector('.finalValue input[type="checkbox"]').checked) {
totalEmpty++;
}
});
if (totalEmpty == 0 || confirm(`There are ${totalEmpty} conflicting entries selected for saving with no value. Continue?`)) {
let entries = table.querySelectorAll('.finalValue');
let blobData = "";
entries.forEach(entry => {
if (entry.querySelector('input[type="checkbox"]:checked')) {
let val = entry.querySelector('input[type="text"]');
blobData += val.name + "=" + val.value + "\n";
}
});
let blob = new Blob([blobData], {type: 'application/binary'});
let url = window.URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.click();
window.URL.revokeObjectURL(url);
}
return false;
}
function lineMatches(line) {
return line != "" && !line.match(/^#/) && line.match(/=/);
}
function loadFile(file) {
return new Promise((resolve) => {
console.debug(`Loading '${file.name}'...`);
let fileReader = new FileReader();
fileReader.onload = (e) => resolve(fileReader.result, file.name);
fileReader.readAsText(file);
});
}
function splitContents(raw, fileName) {
return new Promise((resolve) => {
console.debug(`Splitting raw data for '${fileName}'...`);
let lines = raw.split('\n');
let result = {};
lines.forEach(line => {
if (lineMatches(line)) {
let index = line.indexOf("=");
let key = line.substr(0, index).trim();
let value = line.substr(index + 1).trim();
if (result.hasOwnProperty(key)) {
console.warn(`Duplicate value found in '${fileName}' for '${key}': '${result[key]}' => '${value}'.`);
}
result[key] = value;
}
});
resolve(result);
});
}
async function getProperties(file) {
let res = await loadFile(file)
let props = await splitContents(res, file.name);
return props;
}
</script>
</body>
</html>