Fix the generate button and it's functions, and terminate bugs if any
Browse files- index.html +88 -46
index.html
CHANGED
|
@@ -258,60 +258,102 @@
|
|
| 258 |
youtubeTab.classList.remove('active-tab', 'text-primary', 'dark:text-primary', 'border-primary');
|
| 259 |
document.getElementById('video-url').placeholder = 'https://www.tiktok.com/@username/video/...';
|
| 260 |
});
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
const
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
if (!url) {
|
| 267 |
alert('Please enter a valid YouTube or TikTok URL');
|
| 268 |
return;
|
| 269 |
}
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
.
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
});
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
})
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
document.getElementById('status-container').classList.add('hidden');
|
| 309 |
-
document.getElementById('empty-state').classList.remove('hidden');
|
| 310 |
-
alert('Error processing video. Please try again.');
|
| 311 |
-
});
|
| 312 |
-
});
|
| 313 |
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
document.getElementById('copy-btn').addEventListener('click', () => {
|
| 316 |
const transcriptText = document.getElementById('transcript-content').textContent;
|
| 317 |
navigator.clipboard.writeText(transcriptText).then(() => {
|
|
|
|
| 258 |
youtubeTab.classList.remove('active-tab', 'text-primary', 'dark:text-primary', 'border-primary');
|
| 259 |
document.getElementById('video-url').placeholder = 'https://www.tiktok.com/@username/video/...';
|
| 260 |
});
|
| 261 |
+
// Transcript generation
|
| 262 |
+
document.getElementById('generate-btn').addEventListener('click', async () => {
|
| 263 |
+
const url = document.getElementById('video-url').value.trim();
|
| 264 |
+
const urlPatterns = {
|
| 265 |
+
youtube: /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+/,
|
| 266 |
+
tiktok: /^(https?:\/\/)?(www\.)?tiktok\.com\/.+\/video\/.+/
|
| 267 |
+
};
|
| 268 |
|
| 269 |
if (!url) {
|
| 270 |
alert('Please enter a valid YouTube or TikTok URL');
|
| 271 |
return;
|
| 272 |
}
|
| 273 |
|
| 274 |
+
if (!urlPatterns.youtube.test(url) && !urlPatterns.tiktok.test(url)) {
|
| 275 |
+
alert('Please enter a valid YouTube or TikTok URL');
|
| 276 |
+
return;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
try {
|
| 280 |
+
// Show loading state
|
| 281 |
+
document.getElementById('empty-state').classList.add('hidden');
|
| 282 |
+
document.getElementById('status-container').classList.remove('hidden');
|
| 283 |
+
document.getElementById('results-container').classList.add('hidden');
|
| 284 |
+
document.getElementById('generate-btn').disabled = true;
|
| 285 |
+
|
| 286 |
+
// Mock API call - replace with actual API endpoint
|
| 287 |
+
const [videoInfo, transcriptData] = await Promise.all([
|
| 288 |
+
fetchVideoInfo(url),
|
| 289 |
+
fetchTranscript(url)
|
| 290 |
+
]);
|
| 291 |
+
|
| 292 |
+
// Update UI
|
| 293 |
+
document.getElementById('status-container').classList.add('hidden');
|
| 294 |
+
document.getElementById('results-container').classList.remove('hidden');
|
| 295 |
+
|
| 296 |
+
// Update video info
|
| 297 |
+
document.getElementById('video-title').textContent = videoInfo.title || 'Unknown';
|
| 298 |
+
document.getElementById('video-duration').textContent = videoInfo.duration || 'Unknown';
|
| 299 |
+
document.getElementById('processing-time').textContent = videoInfo.processingTime || 'Unknown';
|
| 300 |
+
|
| 301 |
+
// Update transcript
|
| 302 |
+
const fullTranscript = formatTranscript(transcriptData);
|
| 303 |
+
document.getElementById('transcript-content').innerHTML = fullTranscript;
|
| 304 |
+
document.getElementById('word-count').textContent = countWords(fullTranscript);
|
| 305 |
+
|
| 306 |
+
} catch (error) {
|
| 307 |
+
console.error('Error:', error);
|
| 308 |
+
document.getElementById('status-container').classList.add('hidden');
|
| 309 |
+
document.getElementById('results-container').classList.add('hidden');
|
| 310 |
+
document.getElementById('empty-state').classList.remove('hidden');
|
| 311 |
+
alert('Error processing video. Please try again.');
|
| 312 |
+
} finally {
|
| 313 |
+
document.getElementById('generate-btn').disabled = false;
|
| 314 |
+
}
|
| 315 |
+
});
|
| 316 |
+
|
| 317 |
+
// Helper functions
|
| 318 |
+
async function fetchVideoInfo(url) {
|
| 319 |
+
// Mock implementation - replace with actual API call
|
| 320 |
+
return new Promise(resolve => {
|
| 321 |
+
setTimeout(() => {
|
| 322 |
+
resolve({
|
| 323 |
+
title: 'Sample Video Title',
|
| 324 |
+
duration: '5:30',
|
| 325 |
+
processingTime: `${(Math.random() * 2 + 1).toFixed(2)} seconds`
|
| 326 |
+
});
|
| 327 |
+
}, 500);
|
| 328 |
+
});
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
async function fetchTranscript(url) {
|
| 332 |
+
// Mock implementation - replace with actual API call
|
| 333 |
+
return new Promise(resolve => {
|
| 334 |
+
setTimeout(() => {
|
| 335 |
+
const mockTranscript = [];
|
| 336 |
+
for (let i = 0; i < 10; i++) {
|
| 337 |
+
mockTranscript.push({
|
| 338 |
+
timestamp: `00:${i.toString().padStart(2, '0')}`,
|
| 339 |
+
text: `This is sample transcript line ${i + 1} for demonstration purposes.`
|
| 340 |
});
|
| 341 |
+
}
|
| 342 |
+
resolve(mockTranscript);
|
| 343 |
+
}, 1000);
|
| 344 |
+
});
|
| 345 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
+
function formatTranscript(data) {
|
| 348 |
+
return data.map(entry =>
|
| 349 |
+
`<p><strong>[${entry.timestamp}]</strong> ${entry.text}</p>`
|
| 350 |
+
).join('');
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
function countWords(text) {
|
| 354 |
+
return text.split(/\s+/).filter(word => word.length > 0).length;
|
| 355 |
+
}
|
| 356 |
+
// Copy functionality
|
| 357 |
document.getElementById('copy-btn').addEventListener('click', () => {
|
| 358 |
const transcriptText = document.getElementById('transcript-content').textContent;
|
| 359 |
navigator.clipboard.writeText(transcriptText).then(() => {
|