Spaces:
Running
Running
Update index.html
Browse files- index.html +57 -50
index.html
CHANGED
|
@@ -318,6 +318,7 @@
|
|
| 318 |
return;
|
| 319 |
}
|
| 320 |
|
|
|
|
| 321 |
const startIndex = (currentPage - 1) * videosPerPage;
|
| 322 |
const endIndex = Math.min(startIndex + videosPerPage, filteredVideos.length);
|
| 323 |
const currentVideos = filteredVideos.slice(startIndex, endIndex);
|
|
@@ -331,11 +332,11 @@
|
|
| 331 |
</div>
|
| 332 |
`).join('');
|
| 333 |
|
|
|
|
| 334 |
document.querySelectorAll('.video-item').forEach(item => {
|
| 335 |
item.addEventListener('click', function() {
|
| 336 |
const index = parseInt(this.getAttribute('data-index'));
|
| 337 |
if (!isNaN(index) && index >= 0 && index < filteredVideos.length) {
|
| 338 |
-
// Call the async function to play the video
|
| 339 |
playVideo(filteredVideos[index]);
|
| 340 |
}
|
| 341 |
});
|
|
@@ -345,39 +346,53 @@
|
|
| 345 |
// Function to render pagination
|
| 346 |
function renderPagination() {
|
| 347 |
const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
|
|
|
|
| 348 |
if (totalPages <= 1) {
|
| 349 |
pagination.innerHTML = '';
|
| 350 |
return;
|
| 351 |
}
|
| 352 |
|
|
|
|
| 353 |
let buttons = [];
|
| 354 |
if (totalPages <= 7) {
|
|
|
|
| 355 |
for (let i = 1; i <= totalPages; i++) {
|
| 356 |
buttons.push(i);
|
| 357 |
}
|
| 358 |
} else {
|
|
|
|
| 359 |
buttons.push(1);
|
|
|
|
|
|
|
| 360 |
if (currentPage > 3) {
|
| 361 |
buttons.push('...');
|
| 362 |
}
|
|
|
|
|
|
|
| 363 |
const startPage = Math.max(2, currentPage - 1);
|
| 364 |
const endPage = Math.min(totalPages - 1, currentPage + 1);
|
| 365 |
for (let i = startPage; i <= endPage; i++) {
|
| 366 |
buttons.push(i);
|
| 367 |
}
|
|
|
|
|
|
|
| 368 |
if (currentPage < totalPages - 2) {
|
| 369 |
buttons.push('...');
|
| 370 |
}
|
|
|
|
|
|
|
| 371 |
buttons.push(totalPages);
|
| 372 |
}
|
| 373 |
|
|
|
|
| 374 |
pagination.innerHTML = buttons.map(button => {
|
| 375 |
if (button === '...') {
|
| 376 |
return '<span class="page-btn">...</span>';
|
| 377 |
}
|
| 378 |
return `<button class="page-btn ${button === currentPage ? 'active' : ''}" data-page="${button}">${button}</button>`;
|
| 379 |
}).join('');
|
| 380 |
-
|
|
|
|
| 381 |
document.querySelectorAll('.page-btn[data-page]').forEach(button => {
|
| 382 |
button.addEventListener('click', function() {
|
| 383 |
currentPage = parseInt(this.getAttribute('data-page'));
|
|
@@ -388,57 +403,35 @@
|
|
| 388 |
});
|
| 389 |
}
|
| 390 |
|
| 391 |
-
//
|
| 392 |
-
|
| 393 |
currentVideo = video;
|
| 394 |
currentTitle.textContent = video.title;
|
| 395 |
|
|
|
|
| 396 |
let videoUrl = video.url;
|
| 397 |
-
let finalUrl = videoUrl;
|
| 398 |
|
| 399 |
-
// Check if
|
| 400 |
-
if (videoUrl.includes(
|
| 401 |
-
//
|
| 402 |
-
let token = localStorage.getItem('hf_token');
|
| 403 |
-
if (!token) {
|
| 404 |
-
token = prompt("Enter your HuggingFace token:");
|
| 405 |
-
if (!token) {
|
| 406 |
-
alert("Authentication token required to access HuggingFace video.");
|
| 407 |
-
return;
|
| 408 |
-
}
|
| 409 |
-
localStorage.setItem('hf_token', token);
|
| 410 |
-
}
|
| 411 |
-
try {
|
| 412 |
-
const response = await fetch(videoUrl, {
|
| 413 |
-
headers: {
|
| 414 |
-
'Authorization': `Bearer ${token}`
|
| 415 |
-
}
|
| 416 |
-
});
|
| 417 |
-
if (!response.ok) {
|
| 418 |
-
throw new Error(`Failed to load video: ${response.status} ${response.statusText}`);
|
| 419 |
-
}
|
| 420 |
-
const blob = await response.blob();
|
| 421 |
-
finalUrl = URL.createObjectURL(blob);
|
| 422 |
-
} catch (error) {
|
| 423 |
-
alert("Error loading HuggingFace video: " + error.message);
|
| 424 |
-
return;
|
| 425 |
-
}
|
| 426 |
}
|
| 427 |
|
| 428 |
-
videoPlayer.src =
|
| 429 |
videoPlayer.load();
|
| 430 |
|
| 431 |
-
// Show popup
|
| 432 |
playerPopup.classList.add('active');
|
| 433 |
-
document.body.style.overflow = 'hidden';
|
| 434 |
|
| 435 |
-
// Play video after
|
| 436 |
setTimeout(() => {
|
| 437 |
videoPlayer.play().catch(error => {
|
| 438 |
-
console.error(
|
| 439 |
alert(`Error playing video: ${error.message}. Make sure the URL is accessible.`);
|
| 440 |
});
|
| 441 |
}, 300);
|
|
|
|
|
|
|
|
|
|
| 442 |
}
|
| 443 |
|
| 444 |
// Close popup function
|
|
@@ -462,14 +455,14 @@
|
|
| 462 |
// Close popup when clicking close button
|
| 463 |
closePopup.addEventListener('click', closePlayerPopup);
|
| 464 |
|
| 465 |
-
// Close popup when clicking outside
|
| 466 |
playerPopup.addEventListener('click', function(e) {
|
| 467 |
if (e.target === playerPopup) {
|
| 468 |
closePlayerPopup();
|
| 469 |
}
|
| 470 |
});
|
| 471 |
|
| 472 |
-
// Video
|
| 473 |
playPauseBtn.addEventListener('click', function() {
|
| 474 |
if (videoPlayer.paused) {
|
| 475 |
videoPlayer.play();
|
|
@@ -489,9 +482,9 @@
|
|
| 489 |
fullscreenBtn.addEventListener('click', function() {
|
| 490 |
if (videoPlayer.requestFullscreen) {
|
| 491 |
videoPlayer.requestFullscreen();
|
| 492 |
-
} else if (videoPlayer.webkitRequestFullscreen) {
|
| 493 |
videoPlayer.webkitRequestFullscreen();
|
| 494 |
-
} else if (videoPlayer.msRequestFullscreen) {
|
| 495 |
videoPlayer.msRequestFullscreen();
|
| 496 |
}
|
| 497 |
});
|
|
@@ -500,12 +493,12 @@
|
|
| 500 |
videoPlayer.muted = !videoPlayer.muted;
|
| 501 |
});
|
| 502 |
|
| 503 |
-
// Keyboard controls (active when popup is visible)
|
| 504 |
document.addEventListener('keydown', function(e) {
|
| 505 |
if (!playerPopup.classList.contains('active')) return;
|
| 506 |
|
| 507 |
switch(e.key) {
|
| 508 |
-
case ' ':
|
| 509 |
if (videoPlayer.paused) {
|
| 510 |
videoPlayer.play();
|
| 511 |
} else {
|
|
@@ -542,7 +535,7 @@
|
|
| 542 |
}
|
| 543 |
});
|
| 544 |
|
| 545 |
-
// Double
|
| 546 |
let lastTap = 0;
|
| 547 |
let tapTimeout;
|
| 548 |
|
|
@@ -552,15 +545,20 @@
|
|
| 552 |
clearTimeout(tapTimeout);
|
| 553 |
|
| 554 |
if (tapLength < 500 && tapLength > 0) {
|
|
|
|
| 555 |
const playerRect = videoPlayer.getBoundingClientRect();
|
| 556 |
const clickX = e.clientX - playerRect.left;
|
| 557 |
const playerWidth = playerRect.width;
|
| 558 |
|
|
|
|
| 559 |
if (clickX < playerWidth / 3) {
|
|
|
|
| 560 |
videoPlayer.currentTime = Math.max(0, videoPlayer.currentTime - 10);
|
| 561 |
} else if (clickX > (playerWidth * 2) / 3) {
|
|
|
|
| 562 |
videoPlayer.currentTime = Math.min(videoPlayer.duration, videoPlayer.currentTime + 10);
|
| 563 |
} else {
|
|
|
|
| 564 |
if (videoPlayer.paused) {
|
| 565 |
videoPlayer.play();
|
| 566 |
} else {
|
|
@@ -569,14 +567,21 @@
|
|
| 569 |
}
|
| 570 |
e.preventDefault();
|
| 571 |
} else {
|
|
|
|
| 572 |
tapTimeout = setTimeout(function() {
|
| 573 |
-
// Single tap action (
|
| 574 |
}, 300);
|
| 575 |
}
|
| 576 |
lastTap = currentTime;
|
| 577 |
});
|
| 578 |
|
| 579 |
-
// Fix for fullscreen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
| 581 |
document.addEventListener('webkitfullscreenchange', handleFullscreenChange);
|
| 582 |
document.addEventListener('mozfullscreenchange', handleFullscreenChange);
|
|
@@ -587,22 +592,24 @@
|
|
| 587 |
document.webkitFullscreenElement ||
|
| 588 |
document.mozFullScreenElement) {
|
| 589 |
console.log('Entered fullscreen mode');
|
|
|
|
| 590 |
const fullscreenVideo = document.fullscreenElement ||
|
| 591 |
-
|
| 592 |
-
|
| 593 |
if (fullscreenVideo === videoPlayer) {
|
| 594 |
videoPlayer.style.width = '100%';
|
| 595 |
videoPlayer.style.height = '100%';
|
| 596 |
}
|
| 597 |
} else {
|
| 598 |
console.log('Exited fullscreen mode');
|
|
|
|
| 599 |
videoPlayer.style.width = '100%';
|
| 600 |
videoPlayer.style.height = '100%';
|
| 601 |
}
|
| 602 |
}
|
| 603 |
|
| 604 |
-
// Initialize
|
| 605 |
fetchVideoData();
|
| 606 |
</script>
|
| 607 |
</body>
|
| 608 |
-
</html>
|
|
|
|
| 318 |
return;
|
| 319 |
}
|
| 320 |
|
| 321 |
+
// Calculate start and end index for current page
|
| 322 |
const startIndex = (currentPage - 1) * videosPerPage;
|
| 323 |
const endIndex = Math.min(startIndex + videosPerPage, filteredVideos.length);
|
| 324 |
const currentVideos = filteredVideos.slice(startIndex, endIndex);
|
|
|
|
| 332 |
</div>
|
| 333 |
`).join('');
|
| 334 |
|
| 335 |
+
// Add click event listeners to video items
|
| 336 |
document.querySelectorAll('.video-item').forEach(item => {
|
| 337 |
item.addEventListener('click', function() {
|
| 338 |
const index = parseInt(this.getAttribute('data-index'));
|
| 339 |
if (!isNaN(index) && index >= 0 && index < filteredVideos.length) {
|
|
|
|
| 340 |
playVideo(filteredVideos[index]);
|
| 341 |
}
|
| 342 |
});
|
|
|
|
| 346 |
// Function to render pagination
|
| 347 |
function renderPagination() {
|
| 348 |
const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
|
| 349 |
+
|
| 350 |
if (totalPages <= 1) {
|
| 351 |
pagination.innerHTML = '';
|
| 352 |
return;
|
| 353 |
}
|
| 354 |
|
| 355 |
+
// Determine which page buttons to show
|
| 356 |
let buttons = [];
|
| 357 |
if (totalPages <= 7) {
|
| 358 |
+
// Show all pages if 7 or fewer
|
| 359 |
for (let i = 1; i <= totalPages; i++) {
|
| 360 |
buttons.push(i);
|
| 361 |
}
|
| 362 |
} else {
|
| 363 |
+
// Always include first page
|
| 364 |
buttons.push(1);
|
| 365 |
+
|
| 366 |
+
// Add ellipsis if current page is more than 3
|
| 367 |
if (currentPage > 3) {
|
| 368 |
buttons.push('...');
|
| 369 |
}
|
| 370 |
+
|
| 371 |
+
// Add pages around current page
|
| 372 |
const startPage = Math.max(2, currentPage - 1);
|
| 373 |
const endPage = Math.min(totalPages - 1, currentPage + 1);
|
| 374 |
for (let i = startPage; i <= endPage; i++) {
|
| 375 |
buttons.push(i);
|
| 376 |
}
|
| 377 |
+
|
| 378 |
+
// Add ellipsis if current page is less than totalPages - 2
|
| 379 |
if (currentPage < totalPages - 2) {
|
| 380 |
buttons.push('...');
|
| 381 |
}
|
| 382 |
+
|
| 383 |
+
// Always include last page
|
| 384 |
buttons.push(totalPages);
|
| 385 |
}
|
| 386 |
|
| 387 |
+
// Create pagination HTML
|
| 388 |
pagination.innerHTML = buttons.map(button => {
|
| 389 |
if (button === '...') {
|
| 390 |
return '<span class="page-btn">...</span>';
|
| 391 |
}
|
| 392 |
return `<button class="page-btn ${button === currentPage ? 'active' : ''}" data-page="${button}">${button}</button>`;
|
| 393 |
}).join('');
|
| 394 |
+
|
| 395 |
+
// Add click event listeners to page buttons
|
| 396 |
document.querySelectorAll('.page-btn[data-page]').forEach(button => {
|
| 397 |
button.addEventListener('click', function() {
|
| 398 |
currentPage = parseInt(this.getAttribute('data-page'));
|
|
|
|
| 403 |
});
|
| 404 |
}
|
| 405 |
|
| 406 |
+
// Function to play video
|
| 407 |
+
function playVideo(video) {
|
| 408 |
currentVideo = video;
|
| 409 |
currentTitle.textContent = video.title;
|
| 410 |
|
| 411 |
+
// Handle different types of URLs (direct or Hugging Face)
|
| 412 |
let videoUrl = video.url;
|
|
|
|
| 413 |
|
| 414 |
+
// Check if this is a Hugging Face URL and handle accordingly
|
| 415 |
+
if (videoUrl.includes('huggingface.co')) {
|
| 416 |
+
// URLs for private repositories should already include token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
}
|
| 418 |
|
| 419 |
+
videoPlayer.src = videoUrl;
|
| 420 |
videoPlayer.load();
|
| 421 |
|
| 422 |
+
// Show popup
|
| 423 |
playerPopup.classList.add('active');
|
|
|
|
| 424 |
|
| 425 |
+
// Play video after showing popup
|
| 426 |
setTimeout(() => {
|
| 427 |
videoPlayer.play().catch(error => {
|
| 428 |
+
console.error('Error playing video:', error);
|
| 429 |
alert(`Error playing video: ${error.message}. Make sure the URL is accessible.`);
|
| 430 |
});
|
| 431 |
}, 300);
|
| 432 |
+
|
| 433 |
+
// Disable scrolling on body when popup is active
|
| 434 |
+
document.body.style.overflow = 'hidden';
|
| 435 |
}
|
| 436 |
|
| 437 |
// Close popup function
|
|
|
|
| 455 |
// Close popup when clicking close button
|
| 456 |
closePopup.addEventListener('click', closePlayerPopup);
|
| 457 |
|
| 458 |
+
// Close popup when clicking outside content
|
| 459 |
playerPopup.addEventListener('click', function(e) {
|
| 460 |
if (e.target === playerPopup) {
|
| 461 |
closePlayerPopup();
|
| 462 |
}
|
| 463 |
});
|
| 464 |
|
| 465 |
+
// Video controls
|
| 466 |
playPauseBtn.addEventListener('click', function() {
|
| 467 |
if (videoPlayer.paused) {
|
| 468 |
videoPlayer.play();
|
|
|
|
| 482 |
fullscreenBtn.addEventListener('click', function() {
|
| 483 |
if (videoPlayer.requestFullscreen) {
|
| 484 |
videoPlayer.requestFullscreen();
|
| 485 |
+
} else if (videoPlayer.webkitRequestFullscreen) { /* Safari */
|
| 486 |
videoPlayer.webkitRequestFullscreen();
|
| 487 |
+
} else if (videoPlayer.msRequestFullscreen) { /* IE11 */
|
| 488 |
videoPlayer.msRequestFullscreen();
|
| 489 |
}
|
| 490 |
});
|
|
|
|
| 493 |
videoPlayer.muted = !videoPlayer.muted;
|
| 494 |
});
|
| 495 |
|
| 496 |
+
// Keyboard controls (only active when popup is visible)
|
| 497 |
document.addEventListener('keydown', function(e) {
|
| 498 |
if (!playerPopup.classList.contains('active')) return;
|
| 499 |
|
| 500 |
switch(e.key) {
|
| 501 |
+
case ' ': // Space
|
| 502 |
if (videoPlayer.paused) {
|
| 503 |
videoPlayer.play();
|
| 504 |
} else {
|
|
|
|
| 535 |
}
|
| 536 |
});
|
| 537 |
|
| 538 |
+
// Double tap controls for mobile/touch devices
|
| 539 |
let lastTap = 0;
|
| 540 |
let tapTimeout;
|
| 541 |
|
|
|
|
| 545 |
clearTimeout(tapTimeout);
|
| 546 |
|
| 547 |
if (tapLength < 500 && tapLength > 0) {
|
| 548 |
+
// Double tap detected
|
| 549 |
const playerRect = videoPlayer.getBoundingClientRect();
|
| 550 |
const clickX = e.clientX - playerRect.left;
|
| 551 |
const playerWidth = playerRect.width;
|
| 552 |
|
| 553 |
+
// Determine click position (left, center, or right third)
|
| 554 |
if (clickX < playerWidth / 3) {
|
| 555 |
+
// Left side - backward
|
| 556 |
videoPlayer.currentTime = Math.max(0, videoPlayer.currentTime - 10);
|
| 557 |
} else if (clickX > (playerWidth * 2) / 3) {
|
| 558 |
+
// Right side - forward
|
| 559 |
videoPlayer.currentTime = Math.min(videoPlayer.duration, videoPlayer.currentTime + 10);
|
| 560 |
} else {
|
| 561 |
+
// Center - play/pause
|
| 562 |
if (videoPlayer.paused) {
|
| 563 |
videoPlayer.play();
|
| 564 |
} else {
|
|
|
|
| 567 |
}
|
| 568 |
e.preventDefault();
|
| 569 |
} else {
|
| 570 |
+
// Single tap - wait to see if it becomes a double tap
|
| 571 |
tapTimeout = setTimeout(function() {
|
| 572 |
+
// Single tap action (do nothing or implement something)
|
| 573 |
}, 300);
|
| 574 |
}
|
| 575 |
lastTap = currentTime;
|
| 576 |
});
|
| 577 |
|
| 578 |
+
// Fix for fullscreen and sound issues
|
| 579 |
+
videoPlayer.addEventListener('loadedmetadata', function() {
|
| 580 |
+
// Ensure volume is set
|
| 581 |
+
videoPlayer.volume = 1.0;
|
| 582 |
+
});
|
| 583 |
+
|
| 584 |
+
// Fix for fullscreen mode
|
| 585 |
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
| 586 |
document.addEventListener('webkitfullscreenchange', handleFullscreenChange);
|
| 587 |
document.addEventListener('mozfullscreenchange', handleFullscreenChange);
|
|
|
|
| 592 |
document.webkitFullscreenElement ||
|
| 593 |
document.mozFullScreenElement) {
|
| 594 |
console.log('Entered fullscreen mode');
|
| 595 |
+
// Force video to take full size of screen
|
| 596 |
const fullscreenVideo = document.fullscreenElement ||
|
| 597 |
+
document.webkitFullscreenElement ||
|
| 598 |
+
document.mozFullScreenElement;
|
| 599 |
if (fullscreenVideo === videoPlayer) {
|
| 600 |
videoPlayer.style.width = '100%';
|
| 601 |
videoPlayer.style.height = '100%';
|
| 602 |
}
|
| 603 |
} else {
|
| 604 |
console.log('Exited fullscreen mode');
|
| 605 |
+
// Reset styles when exiting fullscreen
|
| 606 |
videoPlayer.style.width = '100%';
|
| 607 |
videoPlayer.style.height = '100%';
|
| 608 |
}
|
| 609 |
}
|
| 610 |
|
| 611 |
+
// Initialize
|
| 612 |
fetchVideoData();
|
| 613 |
</script>
|
| 614 |
</body>
|
| 615 |
+
</html>
|