abdelhaqueidali commited on
Commit
d8e57c8
·
verified ·
1 Parent(s): f36a283

Replacing the transcript viewer of the SRT result with a text area with a copy button

Browse files
Files changed (1) hide show
  1. index.html +54 -75
index.html CHANGED
@@ -5,7 +5,6 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>CTM to SRT Converter</title>
7
  <style>
8
- /* ... (Same CSS as before, no changes) ... */
9
  body {
10
  font-family: sans-serif;
11
  margin: 20px;
@@ -32,39 +31,7 @@
32
  button:hover {
33
  background-color: #45a049;
34
  }
35
- #output {
36
- margin-top: 20px;
37
- border: 1px solid #ddd;
38
- padding: 10px;
39
- border-radius: 4px;
40
- }
41
- .segment {
42
- padding: 5px;
43
- margin-bottom: 5px;
44
- border: 1px solid #ddd;
45
- border-radius: 4px;
46
- cursor: pointer; /* Optional, since there's no audio */
47
- transition: background-color 0.2s ease;
48
- }
49
-
50
- .segment:hover {
51
- background-color:#f0f8ff;
52
- }
53
-
54
- .playing { /* Keep for potential future use/consistency */
55
- background-color: #e0f7fa;
56
- }
57
-
58
- .time {
59
- color: #888;
60
- margin-right: 10px;
61
- display: inline-block;
62
- min-width: 60px;
63
- }
64
 
65
- .text {
66
- display: inline-block;
67
- }
68
 
69
  #downloadBtn {
70
  margin-top: 10px;
@@ -77,6 +44,28 @@
77
  #ctmFileName{
78
  margin-bottom: 10px;
79
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  </style>
81
  </head>
82
  <body>
@@ -91,11 +80,14 @@
91
  <div id="ctmFileName"></div>
92
 
93
 
94
- <button id="convertBtn">Convert</button> <!-- Single Convert button -->
95
  <button id="downloadBtn" class="hidden">Download SRT</button>
96
 
97
- <h2>Transcript</h2>
98
- <div id="transcript"></div>
 
 
 
99
 
100
  <script>
101
  const ctmInput = document.getElementById('ctmInput');
@@ -103,7 +95,8 @@
103
  const ctmFileName = document.getElementById('ctmFileName');
104
  const convertBtn = document.getElementById('convertBtn');
105
  const downloadBtn = document.getElementById('downloadBtn');
106
- const transcriptDiv = document.getElementById('transcript');
 
107
  let segments = [];
108
  let fileData = null; // Store file data
109
 
@@ -129,28 +122,6 @@
129
  return segments;
130
  }
131
 
132
- function createTranscript(segmentsData) {
133
- transcriptDiv.innerHTML = '';
134
-
135
- segmentsData.forEach(segment => {
136
- const segmentDiv = document.createElement('div');
137
- segmentDiv.classList.add('segment');
138
-
139
- const timeSpan = document.createElement('span');
140
- timeSpan.classList.add('time');
141
- timeSpan.textContent = segment.startTime.toFixed(2) + 's ';
142
-
143
- const textSpan = document.createElement('span');
144
- textSpan.classList.add('text');
145
- textSpan.textContent = segment.text;
146
-
147
- segmentDiv.appendChild(timeSpan);
148
- segmentDiv.appendChild(textSpan);
149
-
150
- transcriptDiv.appendChild(segmentDiv);
151
- });
152
- }
153
-
154
  function generateSRT(segments) {
155
  let srtContent = '';
156
  segments.forEach((segment, index) => {
@@ -170,29 +141,27 @@
170
  return `${hh}:${mm}:${ss},${ms}`;
171
  }
172
 
173
- function processData() { // Unified processing function
174
  let ctmData = null;
175
 
176
  if (fileData) {
177
- ctmData = fileData; // Prioritize file data
178
- }
179
- else{
180
- ctmData = ctmInput.value;
181
  }
182
 
183
-
184
  if (ctmData) {
185
  segments = parseCTM(ctmData);
186
  if (segments.length > 0) {
187
- createTranscript(segments);
 
188
  downloadBtn.classList.remove('hidden');
189
  } else {
190
- transcriptDiv.innerHTML = '<p>No valid CTM data found.</p>';
191
  downloadBtn.classList.add('hidden');
192
  }
193
- }
194
- else{
195
- transcriptDiv.innerHTML = '<p>No CTM data provided.</p>'; //if no ctm provided
196
  downloadBtn.classList.add('hidden');
197
  }
198
  }
@@ -209,7 +178,7 @@
209
  };
210
  reader.onerror = () => {
211
  console.error("Error reading CTM file.");
212
- transcriptDiv.innerHTML = '<p>Error reading CTM file.</p>';
213
  downloadBtn.classList.add('hidden');
214
  fileData = null; // Reset on error
215
  };
@@ -221,18 +190,17 @@
221
  }
222
  });
223
 
224
- convertBtn.addEventListener('click', processData); // Call unified processing
225
-
226
 
227
  downloadBtn.addEventListener('click', () => {
228
- const srtData = generateSRT(segments);
229
  const blob = new Blob([srtData], { type: 'text/srt' });
230
  const url = URL.createObjectURL(blob);
231
  const a = document.createElement('a');
232
  a.href = url;
233
 
234
  let srtFilename = "transcript.srt";
235
- if (segments.length > 0) {
236
  srtFilename = segments[0].filename + ".srt";
237
  }
238
 
@@ -243,6 +211,17 @@
243
  URL.revokeObjectURL(url);
244
  });
245
 
 
 
 
 
 
 
 
 
 
 
 
246
  </script>
247
 
248
  </body>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>CTM to SRT Converter</title>
7
  <style>
 
8
  body {
9
  font-family: sans-serif;
10
  margin: 20px;
 
31
  button:hover {
32
  background-color: #45a049;
33
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
 
 
 
35
 
36
  #downloadBtn {
37
  margin-top: 10px;
 
44
  #ctmFileName{
45
  margin-bottom: 10px;
46
  }
47
+ #srtOutput {
48
+ margin-top: 10px;
49
+ min-height: 200px; /* Added for better visibility */
50
+ }
51
+ #copyBtn {
52
+ background-color: #2196F3; /* Different color for distinction */
53
+ margin-left: 10px; /* Space between buttons */
54
+ }
55
+ #copyBtn:hover{
56
+ background-color: #0d8bf2;
57
+ }
58
+
59
+ /* Styling for the container holding the textarea and copy button */
60
+ .output-container {
61
+ display: flex;
62
+ align-items: flex-start; /* Align items to the top */
63
+ gap: 10px; /* Space between textarea and button */
64
+ }
65
+ .output-container textarea {
66
+ flex-grow: 1; /* Allow textarea to take up remaining space */
67
+ }
68
+
69
  </style>
70
  </head>
71
  <body>
 
80
  <div id="ctmFileName"></div>
81
 
82
 
83
+ <button id="convertBtn">Convert</button>
84
  <button id="downloadBtn" class="hidden">Download SRT</button>
85
 
86
+ <h2>SRT Output</h2>
87
+ <div class="output-container">
88
+ <textarea id="srtOutput" readonly></textarea>
89
+ <button id="copyBtn">Copy</button>
90
+ </div>
91
 
92
  <script>
93
  const ctmInput = document.getElementById('ctmInput');
 
95
  const ctmFileName = document.getElementById('ctmFileName');
96
  const convertBtn = document.getElementById('convertBtn');
97
  const downloadBtn = document.getElementById('downloadBtn');
98
+ const srtOutput = document.getElementById('srtOutput'); // SRT output textarea
99
+ const copyBtn = document.getElementById('copyBtn'); // Copy button
100
  let segments = [];
101
  let fileData = null; // Store file data
102
 
 
122
  return segments;
123
  }
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  function generateSRT(segments) {
126
  let srtContent = '';
127
  segments.forEach((segment, index) => {
 
141
  return `${hh}:${mm}:${ss},${ms}`;
142
  }
143
 
144
+ function processData() {
145
  let ctmData = null;
146
 
147
  if (fileData) {
148
+ ctmData = fileData; // Prioritize file data
149
+ } else {
150
+ ctmData = ctmInput.value;
 
151
  }
152
 
 
153
  if (ctmData) {
154
  segments = parseCTM(ctmData);
155
  if (segments.length > 0) {
156
+ const srtData = generateSRT(segments); // Generate SRT content
157
+ srtOutput.value = srtData; // Display in textarea
158
  downloadBtn.classList.remove('hidden');
159
  } else {
160
+ srtOutput.value = 'No valid CTM data found.';
161
  downloadBtn.classList.add('hidden');
162
  }
163
+ } else {
164
+ srtOutput.value = 'No CTM data provided.';
 
165
  downloadBtn.classList.add('hidden');
166
  }
167
  }
 
178
  };
179
  reader.onerror = () => {
180
  console.error("Error reading CTM file.");
181
+ srtOutput.value = 'Error reading CTM file.';
182
  downloadBtn.classList.add('hidden');
183
  fileData = null; // Reset on error
184
  };
 
190
  }
191
  });
192
 
193
+ convertBtn.addEventListener('click', processData);
 
194
 
195
  downloadBtn.addEventListener('click', () => {
196
+ const srtData = srtOutput.value; // Get SRT data from textarea
197
  const blob = new Blob([srtData], { type: 'text/srt' });
198
  const url = URL.createObjectURL(blob);
199
  const a = document.createElement('a');
200
  a.href = url;
201
 
202
  let srtFilename = "transcript.srt";
203
+ if (segments.length > 0 && segments[0].filename) {
204
  srtFilename = segments[0].filename + ".srt";
205
  }
206
 
 
211
  URL.revokeObjectURL(url);
212
  });
213
 
214
+ // Copy button functionality
215
+ copyBtn.addEventListener('click', () => {
216
+ srtOutput.select(); // Select the text in the textarea
217
+ document.execCommand('copy'); // Execute the copy command
218
+ // Optional: Provide user feedback (e.g., change button text)
219
+ copyBtn.textContent = 'Copied!';
220
+ setTimeout(() => {
221
+ copyBtn.textContent = 'Copy';
222
+ }, 2000); // Reset after 2 seconds
223
+ });
224
+
225
  </script>
226
 
227
  </body>