File size: 15,520 Bytes
a0be895
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced Text Processor</title>
    <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">
    <style>
        .dropzone {
            border: 2px dashed #ccc;
            transition: all 0.3s;
        }
        .dropzone.active {
            border-color: #4f46e5;
            background-color: #f0f7ff;
        }
        .chunk-box {
            position: relative;
        }
        .chunk-box:hover .copy-btn {
            opacity: 1;
        }
        .copy-btn {
            opacity: 0;
            transition: opacity 0.2s;
        }
        .progress-bar {
            transition: width 0.3s ease;
        }
        .glow {
            animation: glow 1.5s ease-in-out infinite alternate;
        }
        @keyframes glow {
            from {
                box-shadow: 0 0 5px rgba(79, 70, 229, 0.5);
            }
            to {
                box-shadow: 0 0 15px rgba(79, 70, 229, 0.8);
            }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8 max-w-4xl">
        <div class="text-center mb-8">
            <h1 class="text-3xl font-bold text-indigo-700 mb-2">Advanced Text Processor</h1>
            <p class="text-gray-600">Upload a TXT file to clean text (removes punctuation and numbers)</p>
        </div>

        <div class="bg-white rounded-xl shadow-md p-6 mb-8 glow">
            <div id="dropzone" class="dropzone rounded-lg p-12 text-center cursor-pointer">
                <div class="flex flex-col items-center justify-center">
                    <i class="fas fa-file-alt text-4xl text-indigo-500 mb-4"></i>
                    <h3 class="text-lg font-medium text-gray-700 mb-2">Drag & drop your TXT file here</h3>
                    <p class="text-gray-500 mb-4">or</p>
                    <label for="fileInput" class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700 transition cursor-pointer">
                        <i class="fas fa-upload mr-2"></i> Select File
                    </label>
                    <input id="fileInput" type="file" accept=".txt" class="hidden">
                </div>
            </div>

            <div id="progressContainer" class="mt-4 hidden">
                <div class="flex justify-between mb-1">
                    <span class="text-sm font-medium text-indigo-700">Processing...</span>
                    <span id="progressPercent" class="text-sm font-medium text-indigo-700">0%</span>
                </div>
                <div class="w-full bg-gray-200 rounded-full h-2.5">
                    <div id="progressBar" class="progress-bar bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
                </div>
            </div>
        </div>

        <div id="resultsSection" class="hidden">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-xl font-semibold text-gray-800">Processed Results</h2>
                <div class="flex space-x-2">
                    <button id="copyAllBtn" class="bg-indigo-100 text-indigo-700 px-3 py-1 rounded-md text-sm hover:bg-indigo-200 transition flex items-center">
                        <i class="fas fa-copy mr-1"></i> Copy All
                    </button>
                    <button id="downloadBtn" class="bg-green-100 text-green-700 px-3 py-1 rounded-md text-sm hover:bg-green-200 transition flex items-center">
                        <i class="fas fa-download mr-1"></i> Download
                    </button>
                </div>
            </div>

            <div id="fileInfo" class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6 rounded">
                <div class="flex justify-between">
                    <div>
                        <h3 class="font-medium text-blue-800" id="fileName"></h3>
                        <p class="text-sm text-blue-600" id="fileSize"></p>
                    </div>
                    <div class="text-right">
                        <p class="text-sm text-blue-600" id="chunkCount"></p>
                        <p class="text-sm text-blue-600" id="processingTime"></p>
                    </div>
                </div>
            </div>

            <div id="chunksContainer" class="space-y-4"></div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const dropzone = document.getElementById('dropzone');
            const fileInput = document.getElementById('fileInput');
            const resultsSection = document.getElementById('resultsSection');
            const chunksContainer = document.getElementById('chunksContainer');
            const progressContainer = document.getElementById('progressContainer');
            const progressBar = document.getElementById('progressBar');
            const progressPercent = document.getElementById('progressPercent');
            const copyAllBtn = document.getElementById('copyAllBtn');
            const downloadBtn = document.getElementById('downloadBtn');
            const fileName = document.getElementById('fileName');
            const fileSize = document.getElementById('fileSize');
            const chunkCount = document.getElementById('chunkCount');
            const processingTime = document.getElementById('processingTime');

            // Handle drag and drop events
            ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
                dropzone.addEventListener(eventName, preventDefaults, false);
            });

            function preventDefaults(e) {
                e.preventDefault();
                e.stopPropagation();
            }

            ['dragenter', 'dragover'].forEach(eventName => {
                dropzone.addEventListener(eventName, highlight, false);
            });

            ['dragleave', 'drop'].forEach(eventName => {
                dropzone.addEventListener(eventName, unhighlight, false);
            });

            function highlight() {
                dropzone.classList.add('active');
            }

            function unhighlight() {
                dropzone.classList.remove('active');
            }

            // Handle dropped files
            dropzone.addEventListener('drop', handleDrop, false);
            fileInput.addEventListener('change', handleFiles);

            function handleDrop(e) {
                const dt = e.dataTransfer;
                const files = dt.files;
                handleFiles({ target: { files } });
            }

            function handleFiles(e) {
                const file = e.target.files[0];
                if (!file) return;
                
                if (!file.name.endsWith('.txt')) {
                    alert('Please upload a .txt file');
                    return;
                }

                processFile(file);
            }

            function processFile(file) {
                const startTime = performance.now();
                progressContainer.classList.remove('hidden');
                resultsSection.classList.add('hidden');
                chunksContainer.innerHTML = '';
                
                const reader = new FileReader();
                
                reader.onload = function(e) {
                    let content = e.target.result;
                    
                    // Advanced text cleaning
                    // 1. Remove all punctuation (including full-width punctuation)
                    // Full-width punctuation ranges: 
                    // - Full-width comma, period: \uFF0C-\uFF0E
                    // - Full-width brackets: \uFF08-\uFF09
                    // - Full-width exclamation/question: \uFF01-\uFF1F
                    // - Full-width period: \u3002
                    content = content.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@[\]^_`{|}~\uFF0C-\uFF0E\uFF08-\uFF09\uFF01-\uFF1F\u3002]/g, '');
                    
                    // 2. Remove numeric sequences (like 1. 2. 3. etc.)
                    content = content.replace(/\b\d+\.?\s*/g, '');
                    
                    // 3. Remove standalone numbers
                    content = content.replace(/\b\d+\b/g, '');
                    
                    // 4. Normalize whitespace (replace multiple spaces/newlines with single space)
                    content = content.replace(/\s+/g, ' ');
                    
                    // 5. Trim leading/trailing spaces
                    content = content.trim();
                    
                    // Split into 128-byte chunks
                    const chunks = [];
                    for (let i = 0; i < content.length; i += 128) {
                        const chunk = content.substr(i, 128).trim();
                        if (chunk.length > 0) {  // Only add non-empty chunks
                            chunks.push(chunk);
                        }
                    }
                    
                    // Update progress bar as we process chunks
                    let processed = 0;
                    const totalChunks = chunks.length;
                    
                    // Display file info
                    fileName.textContent = file.name;
                    fileSize.textContent = `${(file.size / 1024).toFixed(2)} KB`;
                    chunkCount.textContent = `${totalChunks} chunks`;
                    
                    // Process chunks with slight delay to show progress
                    const processChunk = (index) => {
                        if (index >= totalChunks) {
                            const endTime = performance.now();
                            processingTime.textContent = `Processed in ${((endTime - startTime) / 1000).toFixed(2)}s`;
                            progressContainer.classList.add('hidden');
                            resultsSection.classList.remove('hidden');
                            
                            // Store the cleaned content for download
                            document.cleanedContent = chunks.join('\n\n');
                            return;
                        }
                        
                        const chunk = chunks[index];
                        createChunkElement(chunk, index + 1);
                        
                        processed++;
                        const percent = Math.round((processed / totalChunks) * 100);
                        progressBar.style.width = `${percent}%`;
                        progressPercent.textContent = `${percent}%`;
                        
                        setTimeout(() => processChunk(index + 1), 10);
                    };
                    
                    processChunk(0);
                };
                
                reader.readAsText(file);
            }
            
            function createChunkElement(chunk, index) {
                const chunkElement = document.createElement('div');
                chunkElement.className = 'chunk-box bg-white border border-gray-200 rounded-lg p-4 hover:shadow-sm transition';
                
                chunkElement.innerHTML = `
                    <div class="flex justify-between items-start mb-2">
                        <span class="text-xs font-medium bg-indigo-100 text-indigo-800 px-2 py-1 rounded">Chunk ${index}</span>
                        <span class="text-xs text-gray-500">${chunk.length} bytes</span>
                    </div>
                    <div class="relative">
                        <pre class="text-gray-800 whitespace-pre-wrap break-words font-mono text-sm">${chunk}</pre>
                        <button class="copy-btn absolute top-0 right-0 bg-gray-100 hover:bg-gray-200 p-1 rounded text-gray-600" data-chunk="${index}">
                            <i class="fas fa-copy text-xs"></i>
                        </button>
                    </div>
                `;
                
                chunksContainer.appendChild(chunkElement);
            }
            
            // Copy functionality
            chunksContainer.addEventListener('click', function(e) {
                if (e.target.closest('.copy-btn')) {
                    const btn = e.target.closest('.copy-btn');
                    const chunkIndex = btn.getAttribute('data-chunk');
                    const chunkText = btn.closest('.chunk-box').querySelector('pre').textContent;
                    
                    navigator.clipboard.writeText(chunkText).then(() => {
                        const originalIcon = btn.innerHTML;
                        btn.innerHTML = '<i class="fas fa-check text-xs text-green-500"></i>';
                        setTimeout(() => {
                            btn.innerHTML = originalIcon;
                        }, 2000);
                    });
                }
            });
            
            // Copy all chunks
            copyAllBtn.addEventListener('click', function() {
                const allChunks = Array.from(document.querySelectorAll('#chunksContainer pre'))
                    .map(pre => pre.textContent)
                    .join('\n\n');
                
                navigator.clipboard.writeText(allChunks).then(() => {
                    const originalText = copyAllBtn.innerHTML;
                    copyAllBtn.innerHTML = '<i class="fas fa-check mr-1"></i> Copied!';
                    setTimeout(() => {
                        copyAllBtn.innerHTML = originalText;
                    }, 2000);
                });
            });
            
            // Download cleaned content
            downloadBtn.addEventListener('click', function() {
                if (!document.cleanedContent) return;
                
                const blob = new Blob([document.cleanedContent], { type: 'text/plain' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'cleaned_' + fileName.textContent;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                URL.revokeObjectURL(url);
                
                // Show download confirmation
                const originalText = downloadBtn.innerHTML;
                downloadBtn.innerHTML = '<i class="fas fa-check mr-1"></i> Downloaded!';
                setTimeout(() => {
                    downloadBtn.innerHTML = originalText;
                }, 2000);
            });
        });
    </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=xacwutao/advanced-text-processor" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>