play currently focused video in tiktok mode

This commit is contained in:
Simon
2026-06-18 13:42:51 +00:00
parent 988e11b159
commit 6b36b97bd1
2 changed files with 41 additions and 5 deletions

View File

@@ -282,6 +282,7 @@ App.videos = App.videos || {};
const card = document.createElement('div');
card.className = 'video-card';
card.dataset.videoId = v.id;
const durationText = App.videos.formatDuration(v.duration);
const favoriteKey = App.favorites.getKey(v);
const uploaderText = v.uploader || '';
@@ -403,6 +404,31 @@ App.videos = App.videos || {};
App.videos.ensureViewportFilled();
};
// Finds whichever rendered video card is closest to the viewport's
// vertical center, used to open feed mode on the video the user is
// currently looking at instead of always starting from the top.
App.videos.getFocusedVideoId = function() {
const grid = document.getElementById('video-grid');
if (!grid) return null;
const cards = Array.from(grid.querySelectorAll('.video-card'));
if (!cards.length) return null;
const viewportCenter = window.innerHeight / 2;
let best = null;
let bestDistance = Infinity;
cards.forEach((card) => {
const rect = card.getBoundingClientRect();
if (rect.bottom <= 0 || rect.top >= window.innerHeight) return;
const distance = Math.abs((rect.top + rect.height / 2) - viewportCenter);
if (distance < bestDistance) {
bestDistance = distance;
best = card;
}
});
return (best || cards[0]).dataset.videoId || null;
};
App.videos.handleSearch = function(value) {
if (typeof value === 'string') {
const searchInput = document.getElementById('search-input');