-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscript_reader.html
225 lines (199 loc) · 8.03 KB
/
transcript_reader.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
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
<!DOCTYPE html>
<html>
<head>
<title>Transcript Cleaner</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<script src="https://unpkg.com/compromise@13.10.2"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
#reader {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: #000;
padding: 60px 50px 50px 50px;
box-sizing: border-box;
overflow-y: auto;
font-family: 'Cambria', serif;
color: #aaa;
line-height: 1.6;
font-size: 20px;
text-align: justify;
text-justify: inter-word;
}
#reader-content {
max-width: 800px;
margin: auto;
}
#close-reader {
position: absolute;
right: 20px;
top: 20px;
color: #aaa;
cursor: pointer;
font-size: 18px;
}
p {
margin-bottom: 1em;
}
#settings {
position: absolute;
right: 20px;
top: 50px;
color: #aaa;
cursor: pointer;
display: none;
font-size: 14px;
}
#reader:hover #settings {
display: block;
}
</style>
</head>
<body>
<div class="container">
<h1>YouTube Transcript Cleaner</h1>
<hr/>
<div class="row">
<div class="col-md-6">
<h3>Original Transcript</h3>
<textarea id="original" class="form-control" rows="10"></textarea>
<br/>
<button id="clean" class="btn btn-primary">Clean Transcript</button>
<input type="file" id="fileUpload" accept=".txt" style="display:none;">
<button id="uploadFile" class="btn btn-secondary">Upload File</button>
<button id="downloadFile" class="btn btn-secondary">Download Cleaned Transcript</button>
</div>
<div class="col-md-6">
<h3>Cleaned Transcript</h3>
<textarea id="cleaned" class="form-control" rows="10"></textarea>
<br/>
<button id="read" class="btn btn-success">Display Cleaned Transcript in Reader Mode</button>
</div>
</div>
<br/>
<div id="loading" style="display: none;">
<h3>Processing... Please wait...</h3>
</div>
</div>
<div id="reader">
<div id="close-reader" onclick="closeReaderMode()">❌ Close</div>
<div id="settings">
🖥️ Text Size:
<button onclick="increaseFontSize()">➕</button>
<button onclick="decreaseFontSize()">➖</button>
Width:
<button onclick="increaseWidth()">➕</button>
<button onclick="decreaseWidth()">➖</button>
🖋️ Font:
<select id="font-selector" onchange="changeFont()">
<option>Cambria</option>
<option>Georgia</option>
<option>Times New Roman</option>
<option>Palatino</option>
<option>Garamond</option>
</select>
🖨️<button onclick="window.print()">Print</button>
</div>
<div id="reader-content"></div>
</div>
<script>
function cleanTranscript() {
var inputText = document.getElementById('original').value;
var splitText = inputText.split('\n');
var cleanedText = '';
var currentLine = '';
splitText.forEach(function(line) {
if (line.startsWith('- ') || currentLine.endsWith(', ')) {
currentLine += line.replace('- ', '') + ' ';
} else {
cleanedText += currentLine;
currentLine = line + ' ';
}
});
cleanedText += currentLine;
// Split the cleaned text into sentences using compromise
var sentences = nlp(cleanedText).sentences().out('array');
var paragraphs = '';
var paragraph = '';
sentences.forEach(function(sentence, index) {
paragraph += sentence.trim() + ' ';
if ((index + 1) % 5 == 0) {
paragraphs += '<p>' + paragraph + '</p>';
paragraph = '';
}
});
// Add the last paragraph if it's not empty
if (paragraph != '') {
paragraphs += '<p>' + paragraph + '</p>';
}
document.getElementById('cleaned').value = paragraphs;
}
function displayReaderMode() {
var text = document.getElementById('cleaned').value;
document.getElementById('reader').style.display = 'block';
document.getElementById('reader-content').innerHTML = text;
}
function closeReaderMode() {
document.getElementById('reader').style.display = 'none';
}
function increaseFontSize() {
var currentFontSize = parseFloat(window.getComputedStyle(document.getElementById('reader')).fontSize);
document.getElementById('reader').style.fontSize = (currentFontSize + 2) + 'px';
}
function decreaseFontSize() {
var currentFontSize = parseFloat(window.getComputedStyle(document.getElementById('reader')).fontSize);
document.getElementById('reader').style.fontSize = (currentFontSize - 2) + 'px';
}
function increaseWidth() {
var currentWidth = parseFloat(window.getComputedStyle(document.getElementById('reader-content')).maxWidth);
document.getElementById('reader-content').style.maxWidth = (currentWidth + 50) + 'px';
}
function decreaseWidth() {
var currentWidth = parseFloat(window.getComputedStyle(document.getElementById('reader-content')).maxWidth);
document.getElementById('reader-content').style.maxWidth = (currentWidth - 50) + 'px';
}
function changeFont() {
var newFont = document.getElementById('font-selector').value;
document.getElementById('reader').style.fontFamily = newFont;
}
$('#clean').on('click', function() {
cleanTranscript();
});
$('#read').on('click', function() {
displayReaderMode();
});
$('#uploadFile').on('click', function() {
$('#fileUpload').trigger('click');
});
$('#fileUpload').on('change', function(evt) {
var file = evt.target.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
document.getElementById('original').value = contents;
cleanTranscript();
};
reader.readAsText(file);
}
});
$('#downloadFile').on('click', function() {
var cleanedText = document.getElementById('cleaned').value;
// Replace paragraph tags with newline characters to retain formatting
var textToDownload = cleanedText.replace(/<p>/g, '').replace(/<\/p>/g, '\n\n');
if (textToDownload) {
var blob = new Blob([textToDownload], {type: 'text/plain'});
var url = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = url;
link.download = 'cleaned_transcript.txt';
link.click();
}
});
</script>
</body>
</html>