-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
73 lines (63 loc) · 2.06 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload .srt file to get words statistics</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
#file-input {
display: none;
}
.btn {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
cursor: pointer;
border: none;
border-radius: 5px;
}
.btn:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h2>Upload .srt file to get words statistics</h2>
<div>
<input type="file" id="file-input" accept=".srt">
<label for="file-input" class="btn">Upload SRT File</label>
</div>
<div id="result" style="display: none;">
<h3>Processed File:</h3>
<a id="download-link" class="btn" download="processed_file.csv">Download Processed File</a>
</div>
<script>
document.getElementById('file-input').addEventListener('change', function(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const text = e.target.result;
const words = text.trim().replace(/([^a-zA-Z' ])+/g, ' ').split(/\s+/).map(s => s.charAt(0).toUpperCase() + s.slice(1));
const map = new Map();
words.forEach(word => {
if (word === '') return;
map.set(word, (map.get(word) || 0) + 1);
});
const sortedByFrequency = Array.from(map).sort(([,a], [,b]) => b - a);
const csv = sortedByFrequency.reduce((prev, curr) => {
return prev + `\n${curr[0]},${curr[1]}`;
}, 'Word,Frequency');
const downloadLink = document.getElementById('download-link');
downloadLink.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
document.getElementById('result').style.display = 'block';
};
reader.readAsText(file);
});
</script>
</body>
</html>