-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
157 lines (136 loc) · 3.88 KB
/
index.html
File metadata and controls
157 lines (136 loc) · 3.88 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Text File Splitter</title>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
<style>
:root {
--primary: #4CAF50;
--bg: whitesmoke;
--white: #fff;
--text: #333;
--muted: #666;
--shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: "Inter", "Segoe UI", sans-serif;
background-color: var(--bg);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: var(--text);
}
.container {
background: var(--white);
padding: 2.5rem 3rem;
border-radius: 16px;
box-shadow: var(--shadow);
text-align: center;
max-width: 400px;
width: 100%;
animation: fadeIn 0.4s ease-in-out;
}
h2 {
margin-bottom: 1.5rem;
font-size: 1.6rem;
}
label {
display: block;
margin-top: 1.2rem;
margin-bottom: 0.3rem;
font-weight: 500;
text-align: left;
}
input[type="file"],
input[type="number"] {
width: 100%;
padding: 0.55rem;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 8px;
outline: none;
transition: border-color 0.2s ease-in-out;
}
input[type="file"]:hover,
input[type="number"]:hover {
border-color: var(--primary);
}
button {
margin-top: 1.5rem;
width: 100%;
padding: 0.7rem;
font-size: 1rem;
background-color: var(--primary);
border: none;
color: white;
border-radius: 10px;
cursor: pointer;
transition: background 0.2s ease-in-out;
}
button:hover {
background-color: #43a047;
}
#status {
margin-top: 1.2rem;
font-style: italic;
color: var(--muted);
font-size: 0.95rem;
min-height: 1.5em;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<div class="container">
<h2>📂 Text File Splitter</h2>
<label for="fileInput">Choose your .txt file:</label>
<input type="file" id="fileInput" accept=".txt" />
<label for="lineCount">Lines per file:</label>
<input type="number" id="lineCount" min="1" value="500" />
<button onclick="splitFile()">Upload & Split</button>
<p id="status"></p>
</div>
<script>
async function splitFile() {
const fileInput = document.getElementById('fileInput');
const lineInput = document.getElementById('lineCount');
const status = document.getElementById('status');
const file = fileInput.files[0];
const chunkSize = parseInt(lineInput.value);
if (!file) return alert('Please choose a file');
if (isNaN(chunkSize) || chunkSize <= 0) return alert('Please enter a valid number of lines');
status.textContent = 'Reading file...';
const reader = new FileReader();
reader.onload = async function(event) {
const content = event.target.result;
const lines = content.split(/\r?\n/);
const zip = new JSZip();
let fileCount = 0;
for (let i = 0; i < lines.length; i += chunkSize) {
const chunk = lines.slice(i, i + chunkSize).join('\n');
zip.file(`part_${String(fileCount).padStart(4, '0')}.txt`, chunk);
fileCount++;
}
status.textContent = `Zipping ${fileCount} parts...`;
const blob = await zip.generateAsync({ type: 'blob' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'split_files.zip';
link.click();
status.textContent = '✅ Done! Download started.';
};
reader.readAsText(file);
}
</script>
</body>
</html>