Skip to content

Commit b813af6

Browse files
authored
Update index.html
1 parent 95cb238 commit b813af6

1 file changed

Lines changed: 32 additions & 56 deletions

File tree

index.html

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -533,30 +533,27 @@ <h1><span class="material-symbols-outlined">
533533
try {
534534
const reader = new FileReader();
535535
reader.onload = async function(e) {
536-
let outputString = ''; // Declare outputString outside the try block
536+
let outputString = '';
537537
try {
538538
const zip = await JSZip.loadAsync(e.target.result);
539-
outputString = `Project: ${file.name}\n\n`; // Assign here
539+
// outputString = `Project: ${file.name}\n\n`; // MODIFIED: Removed Project name from outputString
540540
const originalZipName = file.name.substring(0, file.name.lastIndexOf('.')) || file.name;
541541
let processedFileCount = 0;
542-
let skippedFilesLog = "Skipped files/directories:\n";
542+
let skippedFilesLog = "Skipped files/directories:\n"; // This is for UI display, not for outputString
543543
let hasSkippedFiles = false;
544544

545545
const fileProcessingPromises = [];
546546

547547
zip.forEach((relativePath, zipEntry) => {
548548
const entryPath = zipEntry.name.replace(/\\/g, '/'); // Normalize path separators
549-
const pathSegments = entryPath.split('/').filter(segment => segment.length > 0); // Filter out empty segments from trailing slashes
549+
const pathSegments = entryPath.split('/').filter(segment => segment.length > 0);
550550

551-
// Skip if directory is in IGNORED_DIRECTORIES
552551
if (pathSegments.some(segment => IGNORED_DIRECTORIES.includes(segment.toLowerCase()))) {
553-
// console.log(`Skipping directory in ignored list: ${entryPath}`); // Keep console log for debugging
554552
skippedFilesLog += `- ${entryPath} (ignored directory rule)\n`;
555553
hasSkippedFiles = true;
556554
return;
557555
}
558556

559-
// Check if any segment (folder or file name) starts with a dot (excluding .well-known)
560557
const isDotFileOrInDotFolder = pathSegments.some(segment => segment.startsWith('.') && segment !== '.well-known');
561558
const fileExtension = getFileExtension(entryPath);
562559
const isImageFile = IGNORED_IMAGE_EXTENSIONS.includes(fileExtension);
@@ -567,18 +564,15 @@ <h1><span class="material-symbols-outlined">
567564
fileProcessingPromises.push(
568565
zipEntry.async("string")
569566
.then(content => {
570-
// Basic check for binary-like content (e.g., many null chars or non-printable ASCII)
571-
// This is a heuristic and might not be perfect.
572567
if (content.includes('\u0000') || /[\x00-\x08\x0E-\x1F]/.test(content.substring(0,1024))) {
573-
// console.warn(`Skipping likely binary file (heuristic): ${entryPath}`); // Keep console log
574568
outputString += `\`\`\`${entryPath}\n`;
575569
outputString += `[Content appears to be binary or non-UTF8, skipped]\n`;
576570
outputString += "```\n\n";
577571
skippedFilesLog += `- ${entryPath} (heuristic: likely binary/non-UTF8)\n`;
578572
hasSkippedFiles = true;
579573
} else {
580574
outputString += `\`\`\`${entryPath}\n`;
581-
outputString += content.trimEnd(); // Trim trailing whitespace from content
575+
outputString += content.trimEnd();
582576
outputString += "\n```\n\n";
583577
}
584578
processedFileCount++;
@@ -588,36 +582,30 @@ <h1><span class="material-symbols-outlined">
588582
outputString += `[Error reading content for ${entryPath}: ${readError.message}. File might be binary or have an incompatible encoding.]\n`;
589583
outputString += "```\n\n";
590584
console.warn(`Could not decode ${entryPath}.`, readError.message);
591-
processedFileCount++; // Still count it as processed to indicate an attempt
585+
processedFileCount++;
592586
skippedFilesLog += `- ${entryPath} (error reading content: ${readError.message})\n`;
593587
hasSkippedFiles = true;
594588
})
595589
);
596590
} else {
597591
if (zipEntry.dir) {
598-
// Skipping directories is standard/intentional, no need to log unless debugging
592+
// Skipping directories is standard
599593
} else if (isDotFileOrInDotFolder) {
600-
// console.log(`Skipping dotfile/folder: ${entryPath}`); // Keep console log
601594
skippedFilesLog += `- ${entryPath} (dotfile/in dotfolder)\n`; hasSkippedFiles = true;
602595
} else if (isImageFile) {
603-
// console.log(`Skipping image file: ${entryPath}`); // Keep console log
604596
skippedFilesLog += `- ${entryPath} (image file)\n`; hasSkippedFiles = true;
605597
} else if (isBinaryLikeFile) {
606-
// console.log(`Skipping binary-like file by extension: ${entryPath}`); // Keep console log
607598
skippedFilesLog += `- ${entryPath} (binary-like extension)\n`; hasSkippedFiles = true;
608599
}
609600
}
610601
});
611602

612-
// Wait for all file reading promises to resolve
613603
await Promise.all(fileProcessingPromises);
614604

615-
// Add the skipped files log at the end if there were any
605+
// MODIFIED: The skipped files log is prepared for UI but NOT added to outputString
616606
if (hasSkippedFiles) {
617-
skippedFilesLog = skippedFilesLog.trim(); // Clean up the log
618-
// console.log("\n--- Skipped Files/Directories Log ---"); // Keep console log
619-
// console.log(skippedFilesLog); // Keep console log
620-
outputString += "\n--- Log of Skipped Files/Directories ---\n" + skippedFilesLog + "\n";
607+
skippedFilesLog = skippedFilesLog.trim(); // Clean up the log for UI display
608+
// outputString += "\n--- Log of Skipped Files/Directories ---\n" + skippedFilesLog + "\n"; // MODIFIED: Removed log from outputString
621609
}
622610

623611

@@ -634,102 +622,90 @@ <h1><span class="material-symbols-outlined">
634622
summary.style.cursor = 'pointer';
635623
summary.style.marginTop = '10px';
636624
const pre = document.createElement('pre');
637-
pre.textContent = skippedFilesLog;
625+
pre.textContent = skippedFilesLog; // Display the cleaned-up log
638626
pre.style.textAlign = 'left';
639627
pre.style.maxHeight = '200px';
640628
pre.style.overflowY = 'auto';
641629
pre.style.backgroundColor = 'var(--bg-color)';
642630
pre.style.padding = '10px';
643631
pre.style.border = '1px solid var(--border-color)';
644632
pre.style.borderRadius = 'var(--border-radius)';
645-
pre.style.whiteSpace = 'pre-wrap'; /* Ensure text wraps */
646-
pre.style.wordBreak = 'break-word'; /* Break long words */
633+
pre.style.whiteSpace = 'pre-wrap';
634+
pre.style.wordBreak = 'break-word';
647635
details.appendChild(summary);
648636
details.appendChild(pre);
649-
outputArea.querySelector('.message > div').appendChild(details); // Append to the div inside the message
637+
outputArea.querySelector('.message > div').appendChild(details);
650638
}
651639
} else {
652-
// --- Success State: Add Download and Copy Buttons ---
653-
654-
// 1. Add Success Message
655640
const successMessage = document.createElement('div');
656-
successMessage.classList.add('message', 'info-message'); // Using info for less "in your face" success
641+
successMessage.classList.add('message', 'info-message');
657642
successMessage.innerHTML = `
658643
<i class="fa-solid fa-check-circle"></i>
659644
<div><strong>Success!</strong> Your CodeStack is ready. ${processedFileCount} file(s) processed.</div>
660645
`;
661646
outputArea.appendChild(successMessage);
662647

663-
// Add skipped files log details under the message if any
664648
if (hasSkippedFiles) {
665649
const details = document.createElement('details');
666650
const summary = document.createElement('summary');
667651
summary.textContent = 'View skipped files log';
668652
summary.style.cursor = 'pointer';
669653
summary.style.marginTop = '10px';
670654
const pre = document.createElement('pre');
671-
pre.textContent = skippedFilesLog;
655+
pre.textContent = skippedFilesLog; // Display the cleaned-up log
672656
pre.style.textAlign = 'left';
673657
pre.style.maxHeight = '200px';
674658
pre.style.overflowY = 'auto';
675659
pre.style.backgroundColor = 'var(--bg-color)';
676660
pre.style.padding = '10px';
677661
pre.style.border = '1px solid var(--border-color)';
678662
pre.style.borderRadius = 'var(--border-radius)';
679-
pre.style.whiteSpace = 'pre-wrap'; /* Ensure text wraps */
680-
pre.style.wordBreak = 'break-word'; /* Break long words */
663+
pre.style.whiteSpace = 'pre-wrap';
664+
pre.style.wordBreak = 'break-word';
681665
details.appendChild(summary);
682666
details.appendChild(pre);
683-
successMessage.querySelector('div').appendChild(details); // Append to the div inside the message
667+
successMessage.querySelector('div').appendChild(details);
684668
}
685669

686-
// 2. Create a container for buttons
687670
const outputActions = document.createElement('div');
688671
outputActions.classList.add('output-actions');
689672

690-
// 3. Create Download Link (as a button)
691673
const blob = new Blob([outputString.trimEnd()], { type: 'text/plain;charset=utf-8' });
692674
const downloadUrl = URL.createObjectURL(blob);
693675
const downloadLink = document.createElement('a');
694676
downloadLink.href = downloadUrl;
695677
const filename = `${originalZipName}_stack.txt`;
696678
downloadLink.download = filename;
697-
downloadLink.innerHTML = `<i class="fa-solid fa-download"></i> Download`; // Changed icon
679+
downloadLink.innerHTML = `<i class="fa-solid fa-download"></i> Download`;
698680
downloadLink.classList.add('btn', 'btn-success');
699681
outputActions.appendChild(downloadLink);
700682

701-
// 4. Create Copy Button
702683
const copyButton = document.createElement('button');
703-
copyButton.type = 'button'; // Important for button not to submit form
684+
copyButton.type = 'button';
704685
copyButton.innerHTML = `<i class="fa-solid fa-copy"></i> Copy`;
705-
copyButton.classList.add('btn', 'btn-secondary'); // Use the new secondary style
686+
copyButton.classList.add('btn', 'btn-secondary');
706687
outputActions.appendChild(copyButton);
707688

708-
// 5. Add Button Container to Output Area
709689
outputArea.appendChild(outputActions);
710690

711-
// 6. Add Copy Functionality
712691
const originalCopyButtonHTML = copyButton.innerHTML;
713692
copyButton.addEventListener('click', async () => {
714693
try {
715-
await navigator.clipboard.writeText(outputString.trimEnd()); // Copy the trimmed content
716-
// Provide feedback
717-
copyButton.innerHTML = '<i class="fa-solid fa-check"></i> Copied!'; // Change icon and text
718-
copyButton.disabled = true; // Disable during feedback
719-
// Revert after a few seconds
694+
await navigator.clipboard.writeText(outputString.trimEnd());
695+
copyButton.innerHTML = '<i class="fa-solid fa-check"></i> Copied!';
696+
copyButton.disabled = true;
720697
setTimeout(() => {
721698
copyButton.innerHTML = originalCopyButtonHTML;
722-
copyButton.disabled = false; // Re-enable
723-
}, 2500); // Show "Copied!" for 2.5 seconds
699+
copyButton.disabled = false;
700+
}, 2500);
724701
} catch (err) {
725702
console.error('Failed to copy text:', err);
726-
// Provide error feedback (optional, could just log error)
727-
copyButton.innerHTML = '<i class="fa-solid fa-xmark"></i> Copy Failed'; // Change icon and text
728-
copyButton.disabled = true; // Disable during feedback
703+
copyButton.innerHTML = '<i class="fa-solid fa-xmark"></i> Copy Failed';
704+
copyButton.disabled = true;
729705
setTimeout(() => {
730706
copyButton.innerHTML = originalCopyButtonHTML;
731-
copyButton.disabled = false; // Re-enable
732-
}, 3000); // Show "Failed" a bit longer
707+
copyButton.disabled = false;
708+
}, 3000);
733709
}
734710
});
735711
}
@@ -758,7 +734,7 @@ <h1><span class="material-symbols-outlined">
758734

759735
reader.readAsArrayBuffer(file);
760736

761-
} catch (error) { // Catch any synchronous error before FileReader starts
737+
} catch (error) {
762738
outputArea.innerHTML = `<div class="message error-message">
763739
<i class="fa-solid fa-triangle-exclamation"></i>
764740
<div><strong>Client-Side Error:</strong> ${error.message}</div>

0 commit comments

Comments
 (0)