forked from rayondemiel/cleanalto.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
710 lines (616 loc) · 34.3 KB
/
index.html
File metadata and controls
710 lines (616 loc) · 34.3 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ALTO Archives Cleaner - XML-ALTO Optimization</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Source+Sans+3:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
'serif': ['"Playfair Display"', 'serif'],
'sans': ['"Source Sans 3"', 'sans-serif'],
},
colors: {
'parchment': '#f5f2e8',
'ink': '#2c343b',
'maroon': '#85344d',
'oxford': '#002147',
'cambridge': '#a3c1ad',
'gold': '#d4af37',
},
backgroundImage: {
'paper-texture': "url('data:image/svg+xml,%3Csvg width=\"100\" height=\"100\" viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\"%3E%3Cfilter id=\"noise\"%3E%3CfeTurbulence type=\"fractalNoise\" baseFrequency=\".7\" numOctaves=\"2\" stitchTiles=\"stitch\"/%3E%3CfeColorMatrix type=\"saturate\" values=\"0\"/%3E%3C/filter%3E%3Crect width=\"100%\" height=\"100%\" filter=\"url(%23noise)\" opacity=\"0.06\"/%3E%3C/svg%3E')",
}
}
}
}
</script>
<style>
/* Custom scrollbar */
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
background: #f5f2e8;
}
::-webkit-scrollbar-thumb {
background: #85344d;
border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
background: #70293f;
}
/* Checkbox styling */
input[type="checkbox"] {
appearance: none;
width: 1.25rem;
height: 1.25rem;
border: 2px solid #85344d;
border-radius: 0.25rem;
position: relative;
cursor: pointer;
transition: all 0.2s ease;
}
input[type="checkbox"]:checked {
background-color: #85344d;
}
input[type="checkbox"]:checked::after {
content: "✓";
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 0.75rem;
}
/* Animated progress bar */
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.pulse-animation {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
</style>
</head>
<body class="bg-parchment bg-paper-texture min-h-screen font-sans text-ink">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<header class="text-center mb-8">
<div class="mb-2 flex justify-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 text-maroon" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z" clip-rule="evenodd" />
</svg>
</div>
<h1 class="text-4xl font-serif font-bold text-oxford mb-2">ALTO Archives Cleaner</h1>
<p class="text-xl italic font-serif text-maroon">XML-ALTO Optimization</p>
<div class="w-24 h-1 bg-gold mx-auto my-4"></div>
<p class="text-gray-700 max-w-2xl mx-auto">Transform and optimize your XML-ALTO archive (ZIP) files with precision. This tool preserves archive integrity while reducing technical overhead.</p>
</header>
<div class="grid gap-8 lg:grid-cols-2">
<div class="bg-white rounded-lg shadow-lg overflow-hidden border-t-4 border-oxford transition-all duration-300 hover:shadow-xl">
<div class="p-6">
<h2 class="font-serif text-2xl text-oxford mb-4 flex items-center">
<i class="fas fa-file-upload mr-3 text-maroon"></i>
Document Upload
</h2>
<div id="dropZone" class="border-2 border-dashed border-gray-300 rounded-lg p-8 transition-all duration-300 cursor-pointer hover:border-maroon hover:bg-gray-50">
<div id="dropZoneDefault" class="flex flex-col items-center justify-center">
<div class="w-20 h-20 mb-4 bg-oxford/10 rounded-full flex items-center justify-center">
<i class="fas fa-cloud-upload-alt text-3xl text-oxford"></i>
</div>
<p class="text-gray-600 text-center mb-2">
Drag and drop a ZIP file here<br>or click to select
</p>
<p class="text-xs text-gray-500 italic">
(.zip archives containing ALTO XML files)
</p>
<input type="file" id="fileInput" accept=".zip" class="hidden">
</div>
<div id="dropZoneFile" class="hidden">
<div class="flex items-center justify-center">
<div class="w-12 h-12 bg-oxford/10 rounded-full flex items-center justify-center mr-4">
<i class="fas fa-file-archive text-xl text-oxford"></i>
</div>
<div class="flex-1">
<p id="selectedFileName" class="font-medium text-oxford break-all mb-1"></p>
<p class="text-xs text-gray-500">Ready for processing</p>
</div>
<button id="removeFileButton" class="ml-3 bg-maroon text-white rounded-full w-8 h-8 flex items-center justify-center hover:bg-maroon/80 transition-colors duration-200">
<i class="fas fa-times"></i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-lg overflow-hidden border-t-4 border-oxford transition-all duration-300 hover:shadow-xl">
<div class="p-6">
<h2 class="font-serif text-2xl text-oxford mb-4 flex items-center">
<i class="fas fa-sliders-h mr-3 text-maroon"></i>
Processing Options
</h2>
<div class="mb-4">
<div class="border-l-4 border-maroon pl-4 mb-6">
<h4 class="font-serif font-medium text-oxford mb-2">Structure Operations:</h4>
<div class="ml-2 mb-3">
<input type="checkbox" id="flattenStructure" name="processingMode" value="flattenStructure" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="flattenStructure" class="ml-2 text-gray-700 cursor-pointer">Move all XML files to root level</label>
</div>
<div class="ml-2 mb-2">
<input type="checkbox" id="compressXML" name="processingMode" value="compressXML" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="compressXML" class="ml-2 text-gray-700 cursor-pointer">Compress XML (remove whitespace and format)</label>
</div>
</div>
<div class="border-l-4 border-oxford pl-4 mb-4">
<h4 class="font-serif font-medium text-oxford mb-2">Content Operations:</h4>
<div class="ml-2 mb-3">
<input type="checkbox" id="cleanFilenames" name="processingMode" value="cleanFilenames" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="cleanFilenames" class="ml-2 text-gray-700 cursor-pointer">Clean filenames (remove directory paths)</label>
</div>
<div class="ml-2 mb-3">
<input type="checkbox" id="removeGlyphs" name="processingMode" value="removeGlyphs" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="removeGlyphs" class="ml-2 text-gray-700 cursor-pointer">Remove <Glyph> elements and children</label>
</div>
<div class="ml-2 mb-3">
<input type="checkbox" id="removeStyles" name="processingMode" value="removeStyles" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="removeStyles" class="ml-2 text-gray-700 cursor-pointer">Remove style-related attributes</label>
</div>
<div class="ml-2 mb-2">
<input type="checkbox" id="cleanWhitespace" name="processingMode" value="cleanWhitespace" class="w-5 h-5 text-maroon rounded focus:ring-maroon">
<label for="cleanWhitespace" class="ml-2 text-gray-700 cursor-pointer">Clean whitespace in text content</label>
</div>
</div>
<div id="modeError" class="text-red-500 text-sm bg-red-50 border border-red-200 rounded p-2 mt-3 hidden">
<i class="fas fa-exclamation-circle mr-1"></i> Please select at least one processing mode.
</div>
</div>
</div>
</div>
</div>
<div class="flex flex-wrap justify-center gap-4 my-8">
<button id="processButton" disabled class="px-6 py-3 bg-oxford text-white font-medium rounded-md shadow transition-all duration-300 hover:bg-oxford/90 focus:outline-none focus:ring-2 focus:ring-oxford/50 disabled:opacity-50 disabled:cursor-not-allowed transform hover:scale-105">
<span class="flex items-center">
<i class="fas fa-cogs mr-2"></i>
Process Archive
</span>
</button>
<button id="downloadButton" disabled class="px-6 py-3 bg-maroon text-white font-medium rounded-md shadow transition-all duration-300 hover:bg-maroon/90 focus:outline-none focus:ring-2 focus:ring-maroon/50 disabled:opacity-50 disabled:cursor-not-allowed transform hover:scale-105">
<span class="flex items-center">
<i class="fas fa-download mr-2"></i>
Download Processed Archive
</span>
</button>
</div>
<div id="progress" class="hidden bg-white rounded-lg shadow-lg p-6 mb-8 border-t-4 border-gold">
<h3 class="text-xl font-serif text-oxford mb-4 flex items-center">
<i class="fas fa-sync-alt fa-spin mr-3 text-maroon"></i>
Processing Archives...
</h3>
<div class="w-full bg-gray-200 rounded-full h-4 mb-3 overflow-hidden">
<div class="progress-fill h-full bg-gradient-to-r from-oxford to-maroon transition-all duration-300 ease-out w-0 pulse-animation"></div>
</div>
<div class="flex justify-between text-sm font-medium">
<span class="text-gray-500">Processing XML files</span>
<span id="status" class="text-oxford">0%</span>
</div>
</div>
<div id="fileStats" class="hidden bg-white rounded-lg shadow-lg p-6 mb-8 border-t-4 border-gold transition-all duration-500">
<h3 class="text-xl font-serif text-oxford mb-4 flex items-center">
<i class="fas fa-chart-pie mr-3 text-maroon"></i>
Processing Results
</h3>
<div class="mb-4 grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
<p class="text-xs text-gray-500 uppercase">Files Processed</p>
<p id="filesProcessed" class="text-2xl font-medium text-oxford">-</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
<p class="text-xs text-gray-500 uppercase">Total Size Reduction</p>
<p id="totalReduction" class="text-2xl font-medium text-maroon">-</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
<p class="text-xs text-gray-500 uppercase">Original Size</p>
<p id="originalSize" class="text-2xl font-medium text-oxford">-</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
<p class="text-xs text-gray-500 uppercase">Processed Size</p>
<p id="processedSize" class="text-2xl font-medium text-oxford">-</p>
</div>
</div>
<div class="overflow-x-auto">
<h4 class="text-lg font-serif text-oxford mb-3">File Details</h4>
<table class="min-w-full bg-white border-collapse rounded-lg overflow-hidden">
<thead class="bg-oxford text-white">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">File</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Original Size</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Processed Size</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Reduction</th>
</tr>
</thead>
<tbody id="statsTable" class="divide-y divide-gray-200">
<!-- Data will be populated here -->
</tbody>
</table>
</div>
</div>
<footer class="text-center text-gray-500 text-sm mt-12 pb-8">
<p class="mb-2">Designed for digital humanities and historical research projects</p>
<p><a class="text-blue-500" href="https://raw.githubusercontent.com/rayondemiel/cleanalto.github.io/refs/heads/main/LICENSE">Licence</a> - 2025</p>
</footer>
</div>
<script>
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const processButton = document.getElementById('processButton');
const downloadButton = document.getElementById('downloadButton');
const progressBar = document.querySelector('.progress-fill');
const progressStatus = document.getElementById('status');
const progressDiv = document.getElementById('progress');
const modeError = document.getElementById('modeError');
let selectedFile = null;
let processedZip = null;
// Add ripple effect to buttons
const buttons = document.querySelectorAll('button:not([disabled])');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
if (this.disabled) return;
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
ripple.style.position = 'absolute';
ripple.style.borderRadius = '50%';
ripple.style.width = '50px';
ripple.style.height = '50px';
ripple.style.transform = 'scale(0)';
ripple.style.backgroundColor = 'rgba(255, 255, 255, 0.3)';
ripple.style.left = `${e.clientX - rect.left - 25}px`;
ripple.style.top = `${e.clientY - rect.top - 25}px`;
ripple.style.animation = 'ripple 0.6s linear';
ripple.style.pointerEvents = 'none';
this.style.position = 'relative';
this.style.overflow = 'hidden';
this.appendChild(ripple);
setTimeout(() => ripple.remove(), 600);
});
});
// Handle checkbox changes
document.querySelectorAll('input[name="processingMode"]').forEach(checkbox => {
checkbox.addEventListener('change', validateForm);
});
// Handle remove file button
document.getElementById('removeFileButton').addEventListener('click', (e) => {
e.stopPropagation(); // Prevent triggering the dropZone click
selectedFile = null;
fileInput.value = '';
// Reset the UI
document.getElementById('dropZoneDefault').classList.remove('hidden');
document.getElementById('dropZoneDefault').classList.add('flex');
document.getElementById('dropZoneFile').classList.add('hidden');
document.getElementById('selectedFileName').textContent = '';
document.getElementById('fileStats').classList.add('hidden');
document.getElementById('progress').classList.add('hidden');
// Disable buttons
validateForm();
downloadButton.disabled = true;
});
function validateForm() {
const atLeastOneChecked = Array.from(document.querySelectorAll('input[name="processingMode"]'))
.some(checkbox => checkbox.checked);
processButton.disabled = !selectedFile || !atLeastOneChecked;
modeError.classList.toggle('hidden', atLeastOneChecked);
}
// Drag and drop handlers
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('bg-oxford/5', 'border-oxford');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('bg-oxford/5', 'border-oxford');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('bg-oxford/5', 'border-oxford');
const file = e.dataTransfer.files[0];
if (file && file.type === 'application/zip') {
handleFileSelection(file);
}
});
dropZone.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
handleFileSelection(file);
}
});
function handleFileSelection(file) {
selectedFile = file;
// Show file name in the drop zone
const dropZoneDefault = document.getElementById('dropZoneDefault');
const dropZoneFile = document.getElementById('dropZoneFile');
const selectedFileName = document.getElementById('selectedFileName');
if (file) {
selectedFileName.textContent = file.name;
dropZoneDefault.classList.remove('flex');
dropZoneDefault.classList.add('hidden');
dropZoneFile.classList.remove('hidden');
// Add a small animation to show success
dropZoneFile.classList.add('animate-pulse');
setTimeout(() => {
dropZoneFile.classList.remove('animate-pulse');
}, 1000);
}
validateForm();
downloadButton.disabled = true;
// Reset the file stats display when a new file is selected
document.getElementById('fileStats').classList.add('hidden');
document.getElementById('progress').classList.add('hidden');
}
function formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function compressXML(xmlString) {
// Remove comments
xmlString = xmlString.replace(/<!--[\s\S]*?-->/g, '');
// Remove white space between tags while preserving space in content
xmlString = xmlString.replace(/>\s+</g, '><');
// Remove leading and trailing whitespace from lines
xmlString = xmlString.replace(/^\s+|\s+$/gm, '');
// Remove empty lines
xmlString = xmlString.replace(/(\r\n|\n|\r)/gm, '');
return xmlString;
}
function processXMLContent(content, modes) {
let processedContent = content;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(processedContent, 'text/xml');
if (modes.includes('cleanFilenames')) {
const fileNameElements = xmlDoc.getElementsByTagName('fileName');
for (const elem of fileNameElements) {
const path = elem.textContent;
elem.textContent = path.split('/').pop();
}
}
if (modes.includes('removeGlyphs')) {
const glyphs = xmlDoc.getElementsByTagName('Glyph');
while (glyphs.length > 0) {
glyphs[0].parentNode.removeChild(glyphs[0]);
}
}
if (modes.includes('removeStyles')) {
const elements = xmlDoc.getElementsByTagName('*');
const styleAttributes = ['STYLE', 'COLOR', 'FONTSIZE', 'FONTSTYLE'];
for (const elem of elements) {
styleAttributes.forEach(attr => {
elem.removeAttribute(attr);
});
}
}
if (modes.includes('cleanWhitespace')) {
const textNodes = xmlDoc.getElementsByTagName('String');
for (const node of textNodes) {
if (node.hasAttribute('CONTENT')) {
const content = node.getAttribute('CONTENT');
node.setAttribute('CONTENT', content.trim().replace(/\s+/g, ' '));
}
}
}
const serializer = new XMLSerializer();
processedContent = serializer.serializeToString(xmlDoc);
if (modes.includes('compressXML')) {
processedContent = compressXML(processedContent);
}
return processedContent;
}
function getUniqueFilename(existingFiles, originalName) {
const baseName = originalName.split('/').pop();
if (!existingFiles.has(baseName)) {
existingFiles.add(baseName);
return baseName;
}
const [name, ext] = baseName.split('.');
let counter = 1;
let newName;
do {
newName = `${name}_${counter}.${ext}`;
counter++;
} while (existingFiles.has(newName));
existingFiles.add(newName);
return newName;
}
processButton.addEventListener('click', async () => {
if (!selectedFile) return;
const selectedModes = Array.from(document.querySelectorAll('input[name="processingMode"]:checked'))
.map(checkbox => checkbox.value);
if (selectedModes.length === 0) {
modeError.classList.remove('hidden');
return;
}
progressDiv.classList.remove('hidden');
const fileStats = document.getElementById('fileStats');
fileStats.classList.add('hidden');
const statsTable = document.getElementById('statsTable');
statsTable.innerHTML = '';
processButton.disabled = true;
try {
const originZip = new JSZip();
const loadedZip = await originZip.loadAsync(selectedFile);
const outputZip = new JSZip();
const xmlFiles = Object.keys(loadedZip.files)
.filter(name => name.toLowerCase().endsWith('.xml') && !loadedZip.files[name].dir);
let processed = 0;
const existingFiles = new Set();
let totalOriginalSize = 0;
let totalProcessedSize = 0;
for (const fileName of xmlFiles) {
const content = await loadedZip.file(fileName).async('text');
const originalSize = new Blob([content]).size;
totalOriginalSize += originalSize;
const processedContent = processXMLContent(content, selectedModes);
const processedSize = new Blob([processedContent]).size;
totalProcessedSize += processedSize;
// Calculate reduction percentage
const reduction = ((originalSize - processedSize) / originalSize * 100).toFixed(1);
// Add statistics row
const row = document.createElement('tr');
row.className = processed % 2 === 0 ? 'bg-white hover:bg-gray-50' : 'bg-gray-50 hover:bg-gray-100';
const fileCell = document.createElement('td');
fileCell.className = 'px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900';
fileCell.innerHTML = `<i class="far fa-file-code text-maroon mr-2"></i>${fileName.split('/').pop()}`;
const originalSizeCell = document.createElement('td');
originalSizeCell.className = 'px-6 py-4 whitespace-nowrap text-sm text-gray-500';
originalSizeCell.textContent = formatBytes(originalSize);
const processedSizeCell = document.createElement('td');
processedSizeCell.className = 'px-6 py-4 whitespace-nowrap text-sm text-gray-500';
processedSizeCell.textContent = formatBytes(processedSize);
const reductionCell = document.createElement('td');
let reductionClass;
if (parseFloat(reduction) > 20) {
reductionClass = 'text-green-600 font-medium';
} else if (parseFloat(reduction) > 10) {
reductionClass = 'text-blue-600 font-medium';
} else {
reductionClass = 'text-gray-600';
}
reductionCell.className = `px-6 py-4 whitespace-nowrap text-sm ${reductionClass}`;
reductionCell.innerHTML = `<span class="px-2 py-1 rounded ${parseFloat(reduction) > 10 ? 'bg-green-100' : 'bg-blue-50'}">${reduction}%</span>`;
row.appendChild(fileCell);
row.appendChild(originalSizeCell);
row.appendChild(processedSizeCell);
row.appendChild(reductionCell);
statsTable.appendChild(row);
// Determine output filename and add to the new zip
// When flattenStructure is selected, all XML files go to root level
if (selectedModes.includes('flattenStructure')) {
const basename = fileName.split('/').pop();
const outputName = getUniqueFilename(existingFiles, basename);
outputZip.file(outputName, processedContent);
} else {
// Keep original path
outputZip.file(fileName, processedContent);
}
processed++;
const progress = Math.round((processed / xmlFiles.length) * 100);
progressBar.style.width = `${progress}%`;
progressStatus.textContent = `${progress}%`;
}
// Copy non-XML files with their original paths (always preserve their structure)
const nonXmlFiles = Object.keys(loadedZip.files)
.filter(name => !name.toLowerCase().endsWith('.xml') && !loadedZip.files[name].dir);
for (const fileName of nonXmlFiles) {
const content = await loadedZip.file(fileName).async('blob');
outputZip.file(fileName, content);
}
processedZip = await outputZip.generateAsync({type: 'blob'});
downloadButton.disabled = false;
// Calculate overall stats
const totalReduction = ((totalOriginalSize - totalProcessedSize) / totalOriginalSize * 100).toFixed(1);
// Update summary stats
document.getElementById('filesProcessed').textContent = xmlFiles.length;
document.getElementById('totalReduction').textContent = `${totalReduction}%`;
document.getElementById('originalSize').textContent = formatBytes(totalOriginalSize);
document.getElementById('processedSize').textContent = formatBytes(totalProcessedSize);
// Show success animation
progressStatus.textContent = 'Processing complete!';
progressStatus.classList.add('text-green-600', 'font-medium');
progressBar.classList.remove('pulse-animation');
progressBar.classList.add('bg-green-500');
// Show the stats with a slight delay and animation
setTimeout(() => {
progressDiv.classList.add('opacity-0', 'transition-opacity', 'duration-500');
setTimeout(() => {
progressDiv.classList.add('hidden');
progressDiv.classList.remove('opacity-0');
fileStats.classList.remove('hidden');
fileStats.classList.add('animate-fade-in');
}, 500);
}, 1000);
} catch (error) {
console.error('Error processing ZIP:', error);
progressStatus.textContent = 'Error processing file. Please try again.';
progressStatus.classList.add('text-red-500', 'font-medium');
progressBar.classList.remove('pulse-animation');
progressBar.classList.add('bg-red-500');
}
});
downloadButton.addEventListener('click', () => {
if (processedZip) {
// Create visual feedback
downloadButton.innerHTML = '<span class="flex items-center"><i class="fas fa-circle-notch fa-spin mr-2"></i>Preparing download...</span>';
setTimeout(() => {
const url = URL.createObjectURL(processedZip);
const a = document.createElement('a');
a.href = url;
a.download = 'processed_' + selectedFile.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
// Reset button
setTimeout(() => {
downloadButton.innerHTML = '<span class="flex items-center"><i class="fas fa-download mr-2"></i>Download Processed Archive</span>';
}, 1000);
}, 800);
}
});
// Add some animations and interactions for better UX
document.querySelectorAll('.rounded-lg').forEach(card => {
card.addEventListener('mouseenter', function() {
if (!this.classList.contains('hover:shadow-xl')) {
this.classList.add('shadow-lg');
}
});
card.addEventListener('mouseleave', function() {
if (!this.classList.contains('hover:shadow-xl')) {
this.classList.remove('shadow-lg');
}
});
});
// Add keyboard accessibility
dropZone.setAttribute('tabindex', '0');
dropZone.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
fileInput.click();
}
});
// Add some CSS animations with keyframes
const style = document.createElement('style');
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
@keyframes fade-in {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-fade-in {
animation: fade-in 0.5s ease-out forwards;
}
`;
document.head.appendChild(style);
</script>
</body>
</html>