| <!DOCTYPE html> |
| <html lang="vi"> |
| <head> |
| <meta charset="UTF-8"> |
| <title>Nhân bản Text & Xuất File Thông Minh</title> |
| <style> |
| body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 30px; background-color: #f0f2f5; color: #333; } |
| .card { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); max-width: 600px; margin: auto; } |
| h2 { margin-top: 0; color: #007bff; } |
| .form-group { margin-bottom: 15px; } |
| label { display: block; margin-bottom: 5px; font-weight: bold; } |
| input[type="text"], input[type="number"] { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; box-sizing: border-box; } |
| button { width: 100%; padding: 12px; background: #007bff; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: 0.3s; } |
| button:hover { background: #0056b3; } |
| #preview { margin-top: 20px; white-space: pre-wrap; background: #fafafa; border: 1px dashed #bbb; padding: 10px; max-height: 150px; overflow-y: auto; font-size: 14px; } |
| </style> |
| </head> |
| <body> |
|
|
| <div class="card"> |
| <h2>Nhân bản & Xuất file</h2> |
| |
| <div class="form-group"> |
| <label>Nội dung văn bản:</label> |
| <input type="text" id="inputText" placeholder="Nhập nội dung tại đây..." value="Cộng hòa xã hội chủ nghĩa Việt Nam"> |
| </div> |
|
|
| <div class="form-group"> |
| <label>Số lượng dòng:</label> |
| <input type="number" id="repeatCount" value="100" min="1"> |
| </div> |
|
|
| <button onclick="processAndDownload()">Tạo và Tải File .txt</button> |
|
|
| <div id="preview">Xem trước nội dung...</div> |
| </div> |
|
|
| <script> |
| |
| function slugify(text, count) { |
| |
| let str = text.toLowerCase(); |
| str = str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); |
| str = str.replace(/[đĐ]/g, 'd'); |
| |
| |
| str = str.replace(/[^a-z0-9\s]/g, ''); |
| |
| |
| let words = str.split(/\s+/).filter(w => w.length > 0).slice(0, 5); |
| |
| |
| return words.join('') + count; |
| } |
| |
| function processAndDownload() { |
| const text = document.getElementById('inputText').value; |
| const count = document.getElementById('repeatCount').value; |
| |
| if (!text) { |
| alert("Vui lòng nhập nội dung!"); |
| return; |
| } |
| |
| |
| let finalContent = ""; |
| for (let i = 0; i < count; i++) { |
| finalContent += text + "\n"; |
| } |
| |
| |
| document.getElementById('preview').textContent = finalContent; |
| |
| |
| const fileName = slugify(text, count) + ".txt"; |
| |
| |
| const blob = new Blob([finalContent], { type: 'text/plain' }); |
| const link = document.createElement('a'); |
| link.href = URL.createObjectURL(blob); |
| link.download = fileName; |
| link.click(); |
| |
| URL.revokeObjectURL(link.href); |
| } |
| </script> |
|
|
| </body> |
| </html> |
|
|