-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
749 lines (677 loc) · 34.7 KB
/
index.html
File metadata and controls
749 lines (677 loc) · 34.7 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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeStacker - Project Code Bundler</title>
<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=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=code" />
<style>
:root {
--bg-color: #f9fafb; /* Tailwind gray-50 / Vercel-like page background */
--card-bg-color: #ffffff;
--border-color: #e5e7eb; /* Tailwind gray-200 */
--text-primary: #111827; /* Tailwind gray-900 */
--text-secondary: #6b7280; /* Tailwind gray-500 */
--text-placeholder: #9ca3af; /* Tailwind gray-400 */
--accent-bg: #000000; /* Black for primary buttons (Vercel style) */
--accent-text: #ffffff;
--accent-hover-bg: #1f2937; /* Darker gray */
--success-bg-light: #f0fdf4; /* Tailwind green-50 */
--success-text: #15803d; /* Tailwind green-700 */
--success-border: #bbf7d0; /* Tailwind green-300 */
--success-icon: #22c55e; /* Tailwind green-500 */
--error-bg-light: #fef2f2; /* Tailwind red-50 */
--error-text: #b91c1c; /* Tailwind red-700 */
--error-border: #fecaca; /* Tailwind red-300 */
--error-icon: #ef4444; /* Tailwind red-500 */
--info-bg-light: #eff6ff; /* Tailwind blue-50 */
--info-text: #1d4ed8; /* Tailwind blue-700 */
--info-border: #bfdbfe; /* Tailwind blue-300 */
--info-icon: #3b82f6; /* Tailwind blue-500 */
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--border-radius: 6px; /* Slightly sharper radius */
--transition-speed: 0.15s ease-in-out;
}
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-sans);
background-color: var(--bg-color);
color: var(--text-primary);
display: flex;
flex-direction: column; /* For container and footer */
justify-content: center;
align-items: center; /* Center container and footer */
min-height: 100vh;
padding: 5vh 20px; /* Vertical padding based on viewport height */
font-size: 14px; /* Common base for pro UIs */
line-height: 1.6;
}
.container {
background-color: var(--card-bg-color);
padding: 32px;
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 1px 2px 0 rgba(0,0,0,0.03), 0 1px 6px -1px rgba(0,0,0,0.02), 0 2px 4px 0 rgba(0,0,0,0.02); /* Very subtle shadow */
width: 100%;
max-width: 560px;
}
.header {
margin-bottom: 28px;
}
.header h1 {
font-size: 20px;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 6px;
display: flex;
align-items: center;
gap: 10px;
}
.header h1 .fa-solid, .header h1 .fa-regular {
color: var(--text-secondary); /* Using secondary for the icon color as per theme */
font-size: 18px;
}
/* Custom icon for CodeStacker */
.fa-layer-group {
color: #3b82f6; /* A nice blue */
}
.header p {
font-size: 14px;
color: var(--text-secondary);
line-height: 1.5;
}
/* Custom File Input Area */
.file-upload-wrapper {
position: relative;
margin-bottom: 24px;
}
.file-upload-area { /* This is the <label> */
position: relative;
border: 1px dashed var(--border-color);
border-radius: var(--border-radius);
padding: 24px;
text-align: center;
cursor: pointer;
background-color: var(--bg-color);
transition: border-color var(--transition-speed), background-color var(--transition-speed);
overflow: hidden;
min-height: 100px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.file-upload-area:hover, .file-upload-area.dragover {
border-color: var(--accent-bg); /* Black border on hover/dragover */
background-color: #f3f4f6; /* Slightly darker gray for hover */
}
.file-upload-area input[type="file"] {
position: absolute;
left: -9999px;
top: -9999px;
width: 1px;
height: 1px;
opacity: 0;
z-index: -1;
pointer-events: none;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
border: none !important;
outline: none !important;
box-shadow: none !important;
background: transparent !important;
}
.file-upload-content {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
color: var(--text-secondary);
position: relative;
z-index: 1;
}
.file-upload-icon .fa-solid {
font-size: 24px;
color: var(--text-placeholder);
margin-bottom: 4px;
}
.file-upload-text strong {
color: var(--accent-bg); /* Black for "Click to upload" */
font-weight: 500;
}
.file-upload-text span {
font-size: 13px;
color: var(--text-secondary);
}
.file-upload-hint {
font-size: 12px;
color: var(--text-placeholder);
}
.file-name-display {
font-size: 13px;
color: var(--text-primary);
margin-top: 12px;
min-height: 1.5em;
word-break: break-all;
background-color: var(--bg-color); /* Light background for filename */
padding: 6px 10px;
border-radius: 4px;
border: 1px solid var(--border-color);
display: none;
text-align: left;
width: 100%;
}
.file-name-display.visible {
display: block;
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%; /* Default to full width */
padding: 10px 16px;
border: 1px solid transparent;
border-radius: var(--border-radius);
cursor: pointer;
font-size: 14px;
font-weight: 500;
text-decoration: none;
transition: background-color var(--transition-speed), border-color var(--transition-speed), color var(--transition-speed), box-shadow var(--transition-speed);
white-space: nowrap;
}
.btn:focus-visible {
outline: 2px solid var(--accent-bg);
outline-offset: 2px;
}
.btn-primary {
background-color: var(--accent-bg);
color: var(--accent-text);
border-color: var(--accent-bg);
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-primary:hover:not(:disabled) {
background-color: var(--accent-hover-bg);
border-color: var(--accent-hover-bg);
}
.btn-primary:disabled {
background-color: #e5e7eb; /* Tailwind gray-200 for disabled */
border-color: #e5e7eb;
color: #9ca3af; /* Tailwind gray-400 for disabled text */
cursor: not-allowed;
box-shadow: none;
}
.btn .fa-solid, .btn .fa-regular {
font-size: 13px;
line-height: 1;
}
.btn .fa-spinner {
animation: spin 0.7s linear infinite;
}
.btn-success {
background-color: var(--success-bg-light);
color: var(--success-text);
border: 1px solid var(--success-border);
font-weight: 500;
}
.btn-success:hover:not(:disabled) {
background-color: #dcfce7; /* Tailwind green-100 for hover */
border-color: #86efac; /* Tailwind green-300 for hover */
}
.btn-success .fa-solid, .btn-success .fa-regular {
color: var(--success-icon);
}
/* Added style for secondary button (Copy button) */
.btn-secondary {
background-color: var(--card-bg-color);
color: var(--text-primary);
border: 1px solid var(--border-color);
font-weight: 500;
}
.btn-secondary:hover:not(:disabled) {
background-color: var(--bg-color);
border-color: #d1d5db; /* Tailwind gray-300 for hover */
}
.btn-secondary:focus-visible {
outline: 2px solid var(--border-color); /* Match primary or a neutral focus */
outline-offset: 2px;
}
.btn-secondary:disabled {
background-color: #f3f4f6; /* Tailwind gray-100 for disabled */
border-color: #e5e7eb;
color: #9ca3af; /* Tailwind gray-400 for disabled text */
cursor: not-allowed;
box-shadow: none;
}
#outputArea {
margin-top: 24px;
/* text-align: center; Removed to align message left */
}
.message {
display: flex;
align-items: flex-start; /* Align icon and text to the top */
gap: 10px;
padding: 12px 16px;
border-radius: var(--border-radius);
border: 1px solid;
margin-top: 20px;
font-size: 14px;
text-align: left;
line-height: 1.5;
}
.message .fa-solid, .message .fa-regular {
font-size: 18px;
margin-top: 2px; /* Slight adjustment for icon alignment */
flex-shrink: 0;
}
.message > div { /* Ensure text part takes remaining space */
flex-grow: 1;
}
.error-message {
background-color: var(--error-bg-light);
color: var(--error-text);
border-color: var(--error-border);
}
.error-message .fa-solid, .error-message .fa-regular {
color: var(--error-icon);
}
.error-message strong {
color: var(--error-text); /* Ensure strong text also uses error color */
font-weight: 600;
}
.info-message {
background-color: var(--info-bg-light);
color: var(--info-text);
border-color: var(--info-border);
}
.info-message .fa-solid, .info-message .fa-regular {
color: var(--info-icon);
}
.info-message strong {
color: var(--info-text);
font-weight: 600;
}
/* New style for button group */
.output-actions {
display: flex;
gap: 10px; /* Space between buttons */
margin-top: 20px; /* Space below message */
width: 100%; /* Take full width of outputArea */
}
.output-actions .btn {
flex: 1; /* Each button takes equal space */
width: auto; /* Override default 100% width */
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.footer {
text-align: center;
margin-top: 40px;
padding-bottom: 20px;
font-size: 12px;
color: var(--text-secondary);
}
.footer a {
color: var(--text-primary);
text-decoration: none;
font-weight: 500;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><span class="material-symbols-outlined">
code
</span>CodeStacker</h1>
<p>Upload a .zip archive of your project. CodeStacker will extract and consolidate all relevant file paths and their contents into a single text file, perfect for analysis, documentation, or sharing with LLMs. All processing is done securely in your browser.</p>
</div>
<form id="uploadForm"> <!-- Removed enctype, not needed for client-side -->
<div class="file-upload-wrapper">
<label for="zipfile" class="file-upload-area">
<input type="file" id="zipfile" name="zipfile" accept=".zip" required>
<div class="file-upload-content">
<div class="file-upload-icon">
<i class="fa-solid fa-arrow-up-from-bracket"></i>
</div>
<div class="file-upload-text">
<strong>Click to upload</strong><span> or drag and drop</span>
</div>
<div class="file-upload-hint">.ZIP archive only</div>
</div>
</label>
<div class="file-name-display" id="fileNameDisplay"></div>
</div>
<button type="submit" id="submitButton" class="btn btn-primary">
<i class="fa-solid fa-gears"></i> Process & Create Stack
</button>
</form>
<div id="outputArea">
<!-- Download link, Copy button, or error/info message will appear here -->
</div>
</div>
<div class="footer">
Created by <a href="https://github.com/ntf-sadnan" target="_blank" rel="noopener noreferrer">Ntf Sadnan</a>
</div>
<!-- JSZip Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script>
const uploadForm = document.getElementById('uploadForm');
const fileInput = document.getElementById('zipfile');
const fileUploadArea = document.querySelector('.file-upload-area');
const submitButton = document.getElementById('submitButton');
const outputArea = document.getElementById('outputArea');
const fileNameDisplay = document.getElementById('fileNameDisplay');
const originalButtonIconHTML = '<i class="fa-solid fa-gears"></i>';
const originalButtonText = 'Process & Create Stack';
// List of common image file extensions to ignore (case-insensitive)
const IGNORED_IMAGE_EXTENSIONS = [
'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.tif', '.webp', '.svg', '.ico',
'.avif', '.apng', '.jfif', '.pjpeg', '.pjp'
];
// List of common binary/compiled/lock files to ignore
const IGNORED_BINARY_LIKE_EXTENSIONS = [
'.exe', '.dll', '.so', '.o', '.a', '.lib', '.jar', '.war', '.ear', '.class',
'.pyc', '.pyo', '.pyd', '.DS_Store', '.lock', '.pdf', '.doc', '.docx', '.xls', '.xlsx',
'.ppt', '.pptx', '.zip', '.tar', '.gz', '.rar', '.7z', '.iso', '.dmg', '.app',
'.mp3', '.mp4', '.avi', '.mov', '.flv', '.wmv', '.mkv', '.webm', '.ogg', '.wav',
'.eot', '.ttf', '.woff', '.woff2', // fonts
'.psd', '.ai', '.eps', // design files
];
const IGNORED_DIRECTORIES = [
'node_modules', '__pycache__', '.git', '.svn', '.hg', '.vscode', '.idea',
'vendor', 'dist', 'build', 'target', 'out', 'bin', 'obj', 'venv', 'env',
'Pods', 'cmake-build-debug', 'cmake-build-release' // Common build/dependency dirs
];
fileInput.addEventListener('change', function() {
if (this.files.length > 0) {
fileNameDisplay.textContent = `Selected: ${this.files[0].name}`;
fileNameDisplay.classList.add('visible');
outputArea.innerHTML = ''; // Clear previous messages on new file selection
} else {
fileNameDisplay.textContent = '';
fileNameDisplay.classList.remove('visible');
}
});
// Drag and drop handling
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
fileUploadArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false); // Prevent browser opening file
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
fileUploadArea.addEventListener(eventName, () => fileUploadArea.classList.add('dragover'), false);
});
['dragleave', 'drop'].forEach(eventName => {
fileUploadArea.addEventListener(eventName, () => fileUploadArea.classList.remove('dragover'), false);
});
fileUploadArea.addEventListener('drop', (e) => {
const dt = e.dataTransfer;
const files = dt.files;
if (files.length > 0 && files[0].name.toLowerCase().endsWith('.zip')) {
fileInput.files = files;
const event = new Event('change', { bubbles: true });
fileInput.dispatchEvent(event);
} else if (files.length > 0) {
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-circle-exclamation"></i>
<div><strong>Invalid File:</strong> Please drop a .ZIP archive. You dropped: ${files[0].name}</div>
</div>`;
fileNameDisplay.textContent = '';
fileNameDisplay.classList.remove('visible');
fileInput.value = ''; // Clear the actual input
}
});
// Helper function to get file extension (robust)
function getFileExtension(filename) {
const name = filename || '';
const lastDot = name.lastIndexOf('.');
if (lastDot === -1 || lastDot === 0 || lastDot === name.length - 1) {
return ''; // No extension or hidden file like .bashrc
}
return name.substring(lastDot).toLowerCase(); // Include the dot, e.g., '.txt'
}
uploadForm.addEventListener('submit', async function(event) {
event.preventDefault();
if (!fileInput.files.length) {
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-circle-exclamation"></i>
<div><strong>Upload Error:</strong> Please select a .ZIP file.</div>
</div>`;
return;
}
const file = fileInput.files[0];
if (!file.name.toLowerCase().endsWith('.zip')) {
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-circle-exclamation"></i>
<div><strong>Invalid File Type:</strong> Only .ZIP files are allowed. You selected: ${file.name}</div>
</div>`;
return;
}
// Basic size check (e.g., 50MB) - browser might struggle with very large client-side unzipping
const maxSize = 169 * 1024 * 1024; // 169MB
if (file.size > maxSize) {
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-circle-exclamation"></i>
<div><strong>File Too Large:</strong> Max file size is ${maxSize / (1024*1024)}MB. Your file is ${(file.size / (1024*1024)).toFixed(2)}MB.</div>
</div>`;
return;
}
outputArea.innerHTML = ''; // Clear previous results
submitButton.disabled = true;
submitButton.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Processing...';
try {
const reader = new FileReader();
reader.onload = async function(e) {
let outputString = '';
try {
const zip = await JSZip.loadAsync(e.target.result);
// outputString = `Project: ${file.name}\n\n`; // MODIFIED: Removed Project name from outputString
const originalZipName = file.name.substring(0, file.name.lastIndexOf('.')) || file.name;
let processedFileCount = 0;
let skippedFilesLog = "Skipped files/directories:\n"; // This is for UI display, not for outputString
let hasSkippedFiles = false;
const fileProcessingPromises = [];
zip.forEach((relativePath, zipEntry) => {
const entryPath = zipEntry.name.replace(/\\/g, '/'); // Normalize path separators
const pathSegments = entryPath.split('/').filter(segment => segment.length > 0);
if (pathSegments.some(segment => IGNORED_DIRECTORIES.includes(segment.toLowerCase()))) {
skippedFilesLog += `- ${entryPath} (ignored directory rule)\n`;
hasSkippedFiles = true;
return;
}
const isDotFileOrInDotFolder = pathSegments.some(segment => segment.startsWith('.') && segment !== '.well-known');
const fileExtension = getFileExtension(entryPath);
const isImageFile = IGNORED_IMAGE_EXTENSIONS.includes(fileExtension);
const isBinaryLikeFile = IGNORED_BINARY_LIKE_EXTENSIONS.includes(fileExtension);
if (!zipEntry.dir && !isDotFileOrInDotFolder && !isImageFile && !isBinaryLikeFile) {
fileProcessingPromises.push(
zipEntry.async("string")
.then(content => {
if (content.includes('\u0000') || /[\x00-\x08\x0E-\x1F]/.test(content.substring(0,1024))) {
outputString += `\`\`\`${entryPath}\n`;
outputString += `[Content appears to be binary or non-UTF8, skipped]\n`;
outputString += "```\n\n";
skippedFilesLog += `- ${entryPath} (heuristic: likely binary/non-UTF8)\n`;
hasSkippedFiles = true;
} else {
outputString += `\`\`\`${entryPath}\n`;
outputString += content.trimEnd();
outputString += "\n```\n\n";
}
processedFileCount++;
})
.catch(readError => {
outputString += `\`\`\`${entryPath}\n`;
outputString += `[Error reading content for ${entryPath}: ${readError.message}. File might be binary or have an incompatible encoding.]\n`;
outputString += "```\n\n";
console.warn(`Could not decode ${entryPath}.`, readError.message);
processedFileCount++;
skippedFilesLog += `- ${entryPath} (error reading content: ${readError.message})\n`;
hasSkippedFiles = true;
})
);
} else {
if (zipEntry.dir) {
// Skipping directories is standard
} else if (isDotFileOrInDotFolder) {
skippedFilesLog += `- ${entryPath} (dotfile/in dotfolder)\n`; hasSkippedFiles = true;
} else if (isImageFile) {
skippedFilesLog += `- ${entryPath} (image file)\n`; hasSkippedFiles = true;
} else if (isBinaryLikeFile) {
skippedFilesLog += `- ${entryPath} (binary-like extension)\n`; hasSkippedFiles = true;
}
}
});
await Promise.all(fileProcessingPromises);
// MODIFIED: The skipped files log is prepared for UI but NOT added to outputString
if (hasSkippedFiles) {
skippedFilesLog = skippedFilesLog.trim(); // Clean up the log for UI display
// outputString += "\n--- Log of Skipped Files/Directories ---\n" + skippedFilesLog + "\n"; // MODIFIED: Removed log from outputString
}
if (processedFileCount === 0) {
const emptyMessage = "The .ZIP file was empty, contained only ignored file types (e.g., images, binaries, dotfiles), or no processable text files were found.";
outputArea.innerHTML = `<div class="message info-message">
<i class="fa-solid fa-circle-info"></i>
<div><strong>No Files Processed:</strong> ${emptyMessage}</div>
</div>`;
if (hasSkippedFiles) {
const details = document.createElement('details');
const summary = document.createElement('summary');
summary.textContent = 'View skipped files log';
summary.style.cursor = 'pointer';
summary.style.marginTop = '10px';
const pre = document.createElement('pre');
pre.textContent = skippedFilesLog; // Display the cleaned-up log
pre.style.textAlign = 'left';
pre.style.maxHeight = '200px';
pre.style.overflowY = 'auto';
pre.style.backgroundColor = 'var(--bg-color)';
pre.style.padding = '10px';
pre.style.border = '1px solid var(--border-color)';
pre.style.borderRadius = 'var(--border-radius)';
pre.style.whiteSpace = 'pre-wrap';
pre.style.wordBreak = 'break-word';
details.appendChild(summary);
details.appendChild(pre);
outputArea.querySelector('.message > div').appendChild(details);
}
} else {
const successMessage = document.createElement('div');
successMessage.classList.add('message', 'info-message');
successMessage.innerHTML = `
<i class="fa-solid fa-check-circle"></i>
<div><strong>Success!</strong> Your CodeStack is ready. ${processedFileCount} file(s) processed.</div>
`;
outputArea.appendChild(successMessage);
if (hasSkippedFiles) {
const details = document.createElement('details');
const summary = document.createElement('summary');
summary.textContent = 'View skipped files log';
summary.style.cursor = 'pointer';
summary.style.marginTop = '10px';
const pre = document.createElement('pre');
pre.textContent = skippedFilesLog; // Display the cleaned-up log
pre.style.textAlign = 'left';
pre.style.maxHeight = '200px';
pre.style.overflowY = 'auto';
pre.style.backgroundColor = 'var(--bg-color)';
pre.style.padding = '10px';
pre.style.border = '1px solid var(--border-color)';
pre.style.borderRadius = 'var(--border-radius)';
pre.style.whiteSpace = 'pre-wrap';
pre.style.wordBreak = 'break-word';
details.appendChild(summary);
details.appendChild(pre);
successMessage.querySelector('div').appendChild(details);
}
const outputActions = document.createElement('div');
outputActions.classList.add('output-actions');
const blob = new Blob([outputString.trimEnd()], { type: 'text/plain;charset=utf-8' });
const downloadUrl = URL.createObjectURL(blob);
const downloadLink = document.createElement('a');
downloadLink.href = downloadUrl;
const filename = `${originalZipName}_stack.txt`;
downloadLink.download = filename;
downloadLink.innerHTML = `<i class="fa-solid fa-download"></i> Download`;
downloadLink.classList.add('btn', 'btn-success');
outputActions.appendChild(downloadLink);
const copyButton = document.createElement('button');
copyButton.type = 'button';
copyButton.innerHTML = `<i class="fa-solid fa-copy"></i> Copy`;
copyButton.classList.add('btn', 'btn-secondary');
outputActions.appendChild(copyButton);
outputArea.appendChild(outputActions);
const originalCopyButtonHTML = copyButton.innerHTML;
copyButton.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(outputString.trimEnd());
copyButton.innerHTML = '<i class="fa-solid fa-check"></i> Copied!';
copyButton.disabled = true;
setTimeout(() => {
copyButton.innerHTML = originalCopyButtonHTML;
copyButton.disabled = false;
}, 2500);
} catch (err) {
console.error('Failed to copy text:', err);
copyButton.innerHTML = '<i class="fa-solid fa-xmark"></i> Copy Failed';
copyButton.disabled = true;
setTimeout(() => {
copyButton.innerHTML = originalCopyButtonHTML;
copyButton.disabled = false;
}, 3000);
}
});
}
} catch (zipError) {
console.error('Error processing ZIP file:', zipError);
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-circle-xmark"></i>
<div><strong>ZIP Processing Error:</strong> ${zipError.message}. The file might be corrupted or not a valid .ZIP archive.</div>
</div>`;
} finally {
submitButton.disabled = false;
submitButton.innerHTML = `${originalButtonIconHTML} ${originalButtonText}`;
}
};
reader.onerror = function(e) {
console.error("FileReader error:", e);
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-triangle-exclamation"></i>
<div><strong>File Reading Error:</strong> Could not read the selected file.</div>
</div>`;
submitButton.disabled = false;
submitButton.innerHTML = `${originalButtonIconHTML} ${originalButtonText}`;
};
reader.readAsArrayBuffer(file);
} catch (error) {
outputArea.innerHTML = `<div class="message error-message">
<i class="fa-solid fa-triangle-exclamation"></i>
<div><strong>Client-Side Error:</strong> ${error.message}</div>
</div>`;
console.error('Error setting up file processing:', error);
submitButton.disabled = false;
submitButton.innerHTML = `${originalButtonIconHTML} ${originalButtonText}`;
}
});
</script>
</body>
</html>