Prmot / index.html
Scratper's picture
Update index.html
05580b6 verified
<!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>
// Hàm chuẩn hóa tiếng Việt: Bỏ dấu, bỏ khoảng cách, lấy 5 chữ đầu
function slugify(text, count) {
// 1. Chuyển về chữ thường và bỏ dấu
let str = text.toLowerCase();
str = str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); // Bỏ dấu tiếng Việt
str = str.replace(/[đĐ]/g, 'd');
// 2. Chỉ giữ lại chữ cái và khoảng trắng
str = str.replace(/[^a-z0-9\s]/g, '');
// 3. Tách lấy 5 từ đầu tiên
let words = str.split(/\s+/).filter(w => w.length > 0).slice(0, 5);
// 4. Nối lại không cách + thêm số lượng
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;
}
// Tạo nội dung lặp lại
let finalContent = "";
for (let i = 0; i < count; i++) {
finalContent += text + "\n";
}
// Cập nhật preview
document.getElementById('preview').textContent = finalContent;
// Tạo tên file: 5 chữ đầu không dấu không cách + số lượng
const fileName = slugify(text, count) + ".txt";
// Tạo và tải file
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>