This commit is contained in:
2026-09-12 06:01:50 +02:00
parent 2913b03d50
commit 4f6223640f
15 changed files with 991 additions and 159 deletions
+115 -20
View File
@@ -3340,8 +3340,18 @@ window.cancelAnimFrame = (function () {
// Full page: Sync attributes (CRITICAL for fullscreen and theme state)
['theme', 'res'].forEach(attr => {
const val = doc.documentElement.getAttribute(attr);
if (val !== null) document.documentElement.setAttribute(attr, val);
else document.documentElement.removeAttribute(attr);
if (attr === 'theme') {
if (val && val.trim()) {
document.documentElement.setAttribute('theme', val.trim());
} else if (!document.documentElement.getAttribute('theme')) {
const cookieTheme = document.cookie.match(/(?:^|; )theme=([^;]*)/)?.[1];
const fallback = (cookieTheme && decodeURIComponent(cookieTheme)) || window.f0ckDefaultTheme || 'amoled';
document.documentElement.setAttribute('theme', fallback);
}
} else {
if (val !== null) document.documentElement.setAttribute(attr, val);
else document.documentElement.removeAttribute(attr);
}
});
// Sync body classes (CRITICAL for layout triggers)
@@ -4837,6 +4847,12 @@ window.cancelAnimFrame = (function () {
loadItemAjax(`/user/${encodeURIComponent(wUserHallOwner)}/hall/${encodeURIComponent(wUserHall)}/${targetKey}`, true, { transition: 'fade-zoom' });
} else if (wFavsUser) {
loadItemAjax(`/user/${encodeURIComponent(wFavsUser)}/favs/${targetKey}`, true, { transition: 'fade-zoom' });
} else if (wTagMatch) {
const wTag = decodeURIComponent(wTagMatch[1]);
loadItemAjax(`/tag/${encodeURIComponent(wTag).replace(/%2C/g, ',').replace(/%20/g, ' ')}/${targetKey}`, true, { transition: 'fade-zoom' });
} else if (wHallMatch) {
const wHall = decodeURIComponent(wHallMatch[1]);
loadItemAjax(`/h/${encodeURIComponent(wHall).replace(/%20/g, ' ')}/${targetKey}`, true, { transition: 'fade-zoom' });
} else {
loadItemAjax(`/${targetKey}`, true, { transition: 'fade-zoom' });
}
@@ -10369,6 +10385,8 @@ document.addEventListener("DOMContentLoaded", function () {
// Sync UI immediately (Before AJAX)
if (window.updateMimeLabel) window.updateMimeLabel();
document.dispatchEvent(new CustomEvent('f0ck:mimeChanged', { detail: { mime: newMime } }));
// Trigger reload context-aware
const fromModal = !!menu.closest('#excluded-tags-overlay');
const postsEl = document.querySelector('.posts, .tags-grid');
@@ -10656,6 +10674,8 @@ document.addEventListener('DOMContentLoaded', () => {
if (activeThumb) {
activeThumb.classList.remove('previewing');
activeThumb.classList.remove('touch-active');
const card = activeThumb.closest('.sidebar-video-card');
if (card) card.classList.remove('previewing');
activeThumb = null;
}
};
@@ -10677,7 +10697,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (mode === 'nsfw') shouldBlurThis = blurNsfw;
else if (mode === 'nsfl') shouldBlurThis = blurNsfl;
else if (mode === 'sfw') shouldBlurThis = blurSfw;
else if (mode === 'null' || !mode) shouldBlurThis = blurUntagged;
else if (mode === 'null' || mode === 'untagged' || !mode) shouldBlurThis = blurUntagged;
if (shouldBlurThis && !thumb.classList.contains('revealed')) {
return;
@@ -10700,6 +10720,8 @@ document.addEventListener('DOMContentLoaded', () => {
if (thumb !== activeThumb) return;
activeThumb.classList.add('previewing');
const card = activeThumb.closest('.sidebar-video-card');
if (card) card.classList.add('previewing');
const video = document.createElement('video');
video.src = `/b/${file}`;
@@ -10716,11 +10738,11 @@ document.addEventListener('DOMContentLoaded', () => {
video.classList.add('playing');
};
thumb.appendChild(video);
const container = thumb.classList.contains('sidebar-video-thumb-wrap')
? thumb
: (thumb.querySelector('.sidebar-video-thumb-wrap') || thumb);
container.appendChild(video);
activeVideo = video;
// Note: Hover prefetching of the first 512 KB has been removed to prevent
// Chromium cache locks and validation loop stalls on subsequent playback.
};
if (delay === 0) {
@@ -10732,7 +10754,14 @@ document.addEventListener('DOMContentLoaded', () => {
window.startHoverPreview = startPreview;
const handleEnter = (e) => {
const thumb = e.target.closest('.thumb');
let thumb = e.target.closest('.thumb');
if (!thumb) {
// The playback can ONLY start when exactly hovering class="sidebar-video-thumb"
const imgThumb = e.target.closest('.sidebar-video-thumb');
if (imgThumb) {
thumb = imgThumb.closest('.sidebar-video-thumb-wrap');
}
}
if (thumb && thumb !== activeThumb) {
startPreview(thumb, 150);
}
@@ -10741,7 +10770,7 @@ document.addEventListener('DOMContentLoaded', () => {
document.addEventListener('focusin', handleEnter);
const handleLeave = (e) => {
const thumb = e.target.closest('.thumb');
const thumb = e.target.closest('.thumb, .sidebar-video-thumb-wrap');
if (thumb) {
if (e.type === 'mouseout' && e.relatedTarget && thumb.contains(e.relatedTarget)) return;
clearPreview();
@@ -10757,7 +10786,13 @@ document.addEventListener('DOMContentLoaded', () => {
let touchBlockClick = false;
document.addEventListener('touchstart', (e) => {
const thumb = e.target.closest('.thumb');
let thumb = e.target.closest('.thumb');
if (!thumb) {
const imgThumb = e.target.closest('.sidebar-video-thumb');
if (imgThumb) {
thumb = imgThumb.closest('.sidebar-video-thumb-wrap');
}
}
if (thumb) {
// Only apply logic for items we want to preview
@@ -10782,7 +10817,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Capture phase click listener to stop navigation if we just activated
document.addEventListener('click', (e) => {
if (touchBlockClick) {
const thumb = e.target.closest('.thumb');
const thumb = e.target.closest('.thumb, .sidebar-video-thumb-wrap');
if (thumb && thumb === activeThumb) {
e.preventDefault();
e.stopImmediatePropagation();
@@ -12768,6 +12803,40 @@ document.addEventListener('click', (e) => {
return;
}
// Title text click to edit
const titleText = e.target.closest('.item_title_text');
if (titleText && !document.body.classList.contains('preview-as-user')) {
const container = titleText.closest('.item_title');
if (container) {
const editWrap = container.querySelector('.info-title-edit-wrap');
const input = container.querySelector('#info-title-input');
if (editWrap && input) {
e.preventDefault();
titleText.style.display = 'none';
editWrap.style.display = 'flex';
input.dataset.origVal = input.value;
input.focus();
if (input.value) {
input.select();
}
return;
}
}
}
// Close title editor when clicking outside .item_title
const openTitleWrap = document.querySelector('.item_title .info-title-edit-wrap');
if (openTitleWrap && openTitleWrap.style.display !== 'none' && !e.target.closest('.item_title')) {
const container = openTitleWrap.closest('.item_title');
const textEl = container?.querySelector('.item_title_text');
const input = container?.querySelector('#info-title-input');
openTitleWrap.style.display = 'none';
if (textEl) textEl.style.display = '';
if (input && input.dataset.origVal !== undefined) {
input.value = input.dataset.origVal;
}
}
// Title save button
const saveBtn = e.target.closest('#info-title-save');
if (saveBtn) {
@@ -12798,13 +12867,26 @@ document.addEventListener('click', (e) => {
saveBtn.disabled = false;
saveBtn.innerHTML = origIcon;
if (data.success) {
// Keep input form intact and update its value
input.value = data.title || '';
const savedTitle = (data.title || '').trim();
input.value = savedTitle;
input.dataset.origVal = savedTitle;
// Update any plain-text title display element
const textEl = container.querySelector('.item_title_text') || document.querySelector('.item_title_text');
if (textEl) {
textEl.textContent = data.title || '';
if (savedTitle) {
textEl.textContent = savedTitle;
textEl.classList.remove('no-title');
} else {
textEl.innerHTML = '<em>Add a title</em>';
textEl.classList.add('no-title');
}
textEl.style.display = '';
}
const editWrap = container.querySelector('.info-title-edit-wrap');
if (editWrap) {
editWrap.style.display = 'none';
}
// Invalidate cache so navigating next/prev fetches fresh HTML from server
@@ -12977,13 +13059,26 @@ document.addEventListener('click', (e) => {
}
});
// Handle Enter key on title input
// Handle Enter and Escape key on title input
document.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && e.target && e.target.id === 'info-title-input') {
e.preventDefault();
const container = e.target.closest('.item_title') || document;
const saveBtn = container.querySelector('#info-title-save') || document.getElementById('info-title-save');
if (saveBtn) saveBtn.click();
if (e.target && e.target.id === 'info-title-input') {
if (e.key === 'Enter') {
e.preventDefault();
const container = e.target.closest('.item_title') || document;
const saveBtn = container.querySelector('#info-title-save') || document.getElementById('info-title-save');
if (saveBtn) saveBtn.click();
} else if (e.key === 'Escape') {
e.preventDefault();
const container = e.target.closest('.item_title') || document;
const editWrap = container.querySelector('.info-title-edit-wrap');
const textEl = container.querySelector('.item_title_text');
const input = e.target;
if (editWrap) editWrap.style.display = 'none';
if (textEl) textEl.style.display = '';
if (input && input.dataset.origVal !== undefined) {
input.value = input.dataset.origVal;
}
}
}
});