File size: 20,061 Bytes
faf8d87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8039ec2
 
 
 
faf8d87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8039ec2
faf8d87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8039ec2
faf8d87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8039ec2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf8d87
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bulk File Extension Changer</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .dropzone {
            border: 2px dashed #94a3b8;
            transition: all 0.3s ease;
        }
        .dropzone.active {
            border-color: #4f46e5;
            background-color: #eef2ff;
        }
        .file-item:hover .remove-btn {
            opacity: 1;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in {
            animation: fadeIn 0.3s ease forwards;
        }
        .progress-bar {
            transition: width 0.3s ease;
        }
        #zipLoading {
            display: none;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-12 max-w-4xl">
        <div class="text-center mb-12">
            <h1 class="text-4xl font-bold text-indigo-600 mb-3">Bulk File Extension Changer</h1>
            <p class="text-lg text-gray-600">Select multiple files and change their extensions in one click</p>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden">
            <!-- File Drop Zone -->
            <div id="dropzone" class="dropzone p-10 text-center cursor-pointer rounded-t-xl">
                <div class="mx-auto max-w-md">
                    <div class="flex justify-center mb-4">
                        <i class="fas fa-cloud-upload-alt text-5xl text-indigo-400"></i>
                    </div>
                    <h3 class="text-xl font-medium text-gray-700 mb-2">Drag & drop files here</h3>
                    <p class="text-gray-500 mb-4">or</p>
                    <label for="fileInput" class="inline-flex items-center px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg shadow-sm cursor-pointer transition">
                        <i class="fas fa-folder-open mr-3"></i>
                        Browse Files
                        <input id="fileInput" type="file" multiple class="hidden">
                    </label>
                    <p class="text-sm text-gray-400 mt-4">Supports all file types</p>
                </div>
            </div>

            <!-- Control Panel -->
            <div class="bg-gray-50 p-6 border-t border-b border-gray-200">
                <div class="flex flex-col sm:flex-row sm:items-center gap-4">
                    <div class="flex-1">
                        <label for="newExtension" class="block text-sm font-medium text-gray-700 mb-1">New Extension</label>
                        <div class="flex rounded-md shadow-sm">
                            <span class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 text-sm">.</span>
                            <input type="text" id="newExtension" class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-r-md sm:text-sm border-gray-300 border" placeholder="jpg, png, txt..." value="">
                        </div>
                    </div>
                    <div class="mt-4 sm:mt-0">
                        <button id="renameBtn" class="inline-flex items-center px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg shadow-sm cursor-pointer transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                            <i class="fas fa-exchange-alt mr-3"></i>
                            Change Extensions
                        </button>
                    </div>
                </div>
            </div>

            <!-- Selected Files List -->
            <div id="filesList" class="divide-y divide-gray-200 max-h-96 overflow-y-auto">
                <!-- Files will be listed here -->
                <div class="py-4 px-6 text-center text-gray-500" id="emptyState">
                    <i class="fas fa-files-empty text-3xl mb-3 text-gray-300"></i>
                    <p>No files selected</p>
                </div>
            </div>

            <!-- Download Buttons -->
            <div id="downloadSection" class="bg-emerald-50 p-6 text-center hidden">
                <h3 class="text-lg font-medium text-emerald-800 mb-3">Files processed successfully!</h3>
                <div class="flex flex-col sm:flex-row justify-center gap-4">
                    <button id="mergeFilesBtn" class="inline-flex items-center px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg shadow-sm cursor-pointer transition">
                        <i class="fas fa-file-alt mr-3"></i>
                        Merge to TXT
                    </button>
                    <button id="downloadAllBtn" class="inline-flex items-center px-6 py-3 bg-emerald-600 hover:bg-emerald-700 text-white font-medium rounded-lg shadow-sm cursor-pointer transition">
                        <i class="fas fa-download mr-3"></i>
                        Download All Files
                    </button>
                    <button id="downloadZipBtn" class="inline-flex items-center px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg shadow-sm cursor-pointer transition">
                        <i class="fas fa-file-archive mr-3"></i>
                        Download as ZIP
                        <div id="zipLoading" class="ml-3">
                            <div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
                        </div>
                    </button>
                </div>
                <div id="zipProgress" class="mt-4 hidden">
                    <div class="w-full bg-gray-200 rounded-full h-2.5">
                        <div class="bg-emerald-600 h-2.5 rounded-full progress-bar" style="width: 0%"></div>
                    </div>
                    <p class="text-sm text-gray-600 mt-1" id="zipStatus">Preparing ZIP archive...</p>
                </div>
            </div>
        </div>

        <div class="mt-6 text-center text-sm text-gray-500">
            <p>Your files are processed locally in the browser — no data is uploaded anywhere.</p>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const fileInput = document.getElementById('fileInput');
            const dropzone = document.getElementById('dropzone');
            const filesList = document.getElementById('filesList');
            const emptyState = document.getElementById('emptyState');
            const renameBtn = document.getElementById('renameBtn');
            const newExtension = document.getElementById('newExtension');
            const downloadSection = document.getElementById('downloadSection');
            const downloadAllBtn = document.getElementById('downloadAllBtn');
            const downloadZipBtn = document.getElementById('downloadZipBtn');
            const zipLoading = document.getElementById('zipLoading');
            const zipProgress = document.getElementById('zipProgress');
            const zipStatus = document.getElementById('zipStatus');
            const progressBar = zipProgress.querySelector('.progress-bar');
            const mergeFilesBtn = document.getElementById('mergeFilesBtn');

            let files = [];
            let processedFiles = [];

            // Drag and drop functionality
            dropzone.addEventListener('dragover', (e) => {
                e.preventDefault();
                dropzone.classList.add('active');
            });

            dropzone.addEventListener('dragleave', () => {
                dropzone.classList.remove('active');
            });

            dropzone.addEventListener('drop', (e) => {
                e.preventDefault();
                dropzone.classList.remove('active');
                handleFiles(e.dataTransfer.files);
            });

            fileInput.addEventListener('change', (e) => {
                handleFiles(e.target.files);
            });

            renameBtn.addEventListener('click', renameExtensions);
            downloadAllBtn.addEventListener('click', downloadFiles);
            downloadZipBtn.addEventListener('click', createZip);
            mergeFilesBtn.addEventListener('click', mergeToTxt);

            function handleFiles(newFiles) {
                if (newFiles.length === 0) return;

                // Convert FileList to array and add to existing files
                files = files.concat(Array.from(newFiles));
                
                // Update UI
                updateFilesList();
                renameBtn.disabled = files.length === 0 || !newExtension.value.trim();
                
                // Clear file input to allow selecting same files again
                fileInput.value = '';
            }

            function updateFilesList() {
                if (files.length === 0) {
                    emptyState.classList.remove('hidden');
                    filesList.innerHTML = '';
                    filesList.appendChild(emptyState);
                    return;
                }

                emptyState.classList.add('hidden');
                filesList.innerHTML = '';

                files.forEach((file, index) => {
                    const fileNameParts = file.name.split('.');
                    const ext = fileNameParts.length > 1 ? fileNameParts.pop() : '';
                    const nameWithoutExt = fileNameParts.join('.');

                    const fileItem = document.createElement('div');
                    fileItem.className = 'file-item flex items-center justify-between p-4 hover:bg-gray-50 transition fade-in';
                    
                    fileItem.innerHTML = `
                        <div class="flex items-center min-w-0">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-50 flex items-center justify-center text-indigo-600 mr-4">
                                <i class="fas fa-file-alt"></i>
                            </div>
                            <div class="min-w-0">
                                <p class="text-sm font-medium text-gray-900 truncate">${nameWithoutExt || file.name}</p>
                                <p class="text-sm text-gray-500">${ext || 'no extension'}</p>
                            </div>
                        </div>
                        <div class="flex items-center ml-4">
                            <span class="text-xs font-mono bg-gray-100 px-2 py-1 rounded text-gray-700 mr-3">${formatFileSize(file.size)}</span>
                            <button class="remove-btn opacity-0 group focus:opacity-100 hover:opacity-100 transition" data-index="${index}">
                                <i class="fas fa-times text-gray-400 group-hover:text-red-500"></i>
                            </button>
                        </div>
                    `;
                    
                    filesList.appendChild(fileItem);
                });

                // Add event listeners to remove buttons
                document.querySelectorAll('.remove-btn').forEach(btn => {
                    btn.addEventListener('click', (e) => {
                        e.stopPropagation();
                        const index = parseInt(btn.getAttribute('data-index'));
                        files.splice(index, 1);
                        updateFilesList();
                        renameBtn.disabled = files.length === 0 || !newExtension.value.trim();
                    });
                });
            }

            function renameExtensions() {
                const ext = newExtension.value.trim();
                if (!ext) return;
                
                processedFiles = files.map(file => {
                    const fileNameParts = file.name.split('.');
                    const nameWithoutExt = fileNameParts.length > 1 
                        ? fileNameParts.slice(0, -1).join('.') 
                        : fileNameParts.join('.');
                    
                    const newName = `${nameWithoutExt}.${ext}`;
                    
                    // Create a new File object with the new name
                    return new File([file], newName, {
                        type: file.type,
                        lastModified: file.lastModified
                    });
                });
                
                // Show download section
                downloadSection.classList.remove('hidden');
                
                // Scroll to download button
                downloadSection.scrollIntoView({ behavior: 'smooth' });
            }

            function downloadFiles() {
                processedFiles.forEach(file => {
                    const url = URL.createObjectURL(file);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = file.name;
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                    URL.revokeObjectURL(url);
                });
            }

            async function createZip() {
                if (processedFiles.length === 0) return;
                
                // Show loading state
                downloadZipBtn.disabled = true;
                zipLoading.style.display = 'block';
                zipProgress.classList.remove('hidden');
                
                const zip = new JSZip();
                let processedCount = 0;
                
                // Add files to ZIP with progress tracking
                for (const file of processedFiles) {
                    try {
                        await new Promise((resolve) => {
                            const reader = new FileReader();
                            reader.onload = function(e) {
                                zip.file(file.name, e.target.result);
                                processedCount++;
                                updateProgress(processedCount);
                                resolve();
                            };
                            reader.readAsArrayBuffer(file);
                        });
                    } catch (error) {
                        console.error('Error adding file to ZIP:', error);
                    }
                }
                
                // Generate the ZIP file
                try {
                    zipStatus.textContent = 'Compressing files...';
                    
                    const content = await zip.generateAsync({
                        type: 'blob',
                        compression: 'DEFLATE',
                        compressionOptions: { level: 6 }
                    }, (metadata) => {
                        const progress = Math.round(metadata.percent);
                        progressBar.style.width = `${progress}%`;
                        zipStatus.textContent = `Compressing files... ${progress}%`;
                    });
                    
                    // Download the ZIP
                    saveAs(content, 'renamed_files.zip');
                    
                    // Reset UI
                    zipStatus.textContent = 'ZIP archive created successfully!';
                    progressBar.style.width = '100%';
                    progressBar.classList.add('bg-emerald-700');
                } catch (error) {
                    console.error('Error generating ZIP:', error);
                    zipStatus.textContent = 'Error creating ZIP file';
                    progressBar.classList.add('bg-red-500');
                } finally {
                    downloadZipBtn.disabled = false;
                    zipLoading.style.display = 'none';
                }
            }
            
            function updateProgress(processedCount) {
                const progress = Math.round((processedCount / processedFiles.length) * 100);
                progressBar.style.width = `${progress}%`;
                zipStatus.textContent = `Adding files to ZIP... ${processedCount}/${processedFiles.length}`;
            }

            function formatFileSize(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];
            }

            // Enable/disable rename button based on extension input
            newExtension.addEventListener('input', () => {
                renameBtn.disabled = files.length === 0 || !newExtension.value.trim();
            });

            async function mergeToTxt() {
                if (processedFiles.length === 0) return;
                
                try {
                    // Read all files as text
                    const fileContents = await Promise.all(
                        processedFiles.map(file => {
                            return new Promise((resolve) => {
                                const reader = new FileReader();
                                reader.onload = function(e) {
                                    resolve({
                                        name: file.name,
                                        content: e.target.result
                                    });
                                };
                                reader.readAsText(file);
                            });
                        })
                    );
                    
                    // Combine all contents with separators
                    let mergedContent = '';
                    fileContents.forEach((file, index) => {
                        mergedContent += `=== ${file.name} ===\n\n${file.content}\n\n`;
                        if (index < fileContents.length - 1) {
                            mergedContent += '\n\n';
                        }
                    });
                    
                    // Create and download the merged file
                    const blob = new Blob([mergedContent], { type: 'text/plain' });
                    const url = URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = 'merged_files.txt';
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                    URL.revokeObjectURL(url);
                    
                } catch (error) {
                    console.error('Error merging files:', error);
                    alert('Error merging files. Please try again.');
                }
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Ultronprime/extension-changer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>