fuck chrome

This commit is contained in:
2026-07-14 17:59:37 +02:00
parent ef531bf6a2
commit 56e17a8e27
2 changed files with 79 additions and 64 deletions

View File

@@ -155,12 +155,13 @@ window.cancelAnimFrame = (function () {
} }
}; };
window.loadedThumbs = window.loadedThumbs || new Set();
let lazyObserver; let lazyObserver;
window.initLazyLoading = () => { window.initLazyLoading = () => {
if (!('IntersectionObserver' in window)) { const getFinalBg = (thumb) => {
document.querySelectorAll('.lazy-thumb').forEach(thumb => {
let bg = thumb.dataset.bg; let bg = thumb.dataset.bg;
if (bg) { if (!bg) return null;
const mode = thumb.getAttribute('data-mode'); const mode = thumb.getAttribute('data-mode');
const blurNsfw = localStorage.getItem('blurNsfw') === 'true'; const blurNsfw = localStorage.getItem('blurNsfw') === 'true';
const blurNsfl = localStorage.getItem('blurNsfl') === 'true'; const blurNsfl = localStorage.getItem('blurNsfl') === 'true';
@@ -176,9 +177,26 @@ window.cancelAnimFrame = (function () {
if (shouldBlurThis && !thumb.classList.contains('revealed')) { if (shouldBlurThis && !thumb.classList.contains('revealed')) {
bg = bg.replace('.webp', '_blur.webp'); bg = bg.replace('.webp', '_blur.webp');
} }
const finalBg = window.applyThumbCacheBust(bg); return window.applyThumbCacheBust(bg);
};
// Synchronously resolve any already-loaded thumbnails before observer starts
document.querySelectorAll('.lazy-thumb').forEach(thumb => {
const finalBg = getFinalBg(thumb);
if (finalBg && window.loadedThumbs.has(finalBg)) {
thumb.style.backgroundImage = `url('${finalBg}')`;
thumb.classList.add('loaded');
thumb.classList.remove('lazy-thumb');
}
});
if (!('IntersectionObserver' in window)) {
document.querySelectorAll('.lazy-thumb').forEach(thumb => {
const finalBg = getFinalBg(thumb);
if (finalBg) {
thumb.style.backgroundImage = `url('${finalBg}')`; thumb.style.backgroundImage = `url('${finalBg}')`;
thumb.classList.remove('lazy-thumb'); thumb.classList.remove('lazy-thumb');
window.loadedThumbs.add(finalBg);
} }
}); });
return; return;
@@ -191,35 +209,28 @@ window.cancelAnimFrame = (function () {
const thumb = entry.target; const thumb = entry.target;
let bg = thumb.dataset.bg; let bg = thumb.dataset.bg;
if (bg && !thumb.classList.contains('loaded')) { if (bg && !thumb.classList.contains('loaded')) {
const mode = thumb.getAttribute('data-mode'); const finalBg = getFinalBg(thumb);
const blurNsfw = localStorage.getItem('blurNsfw') === 'true'; if (finalBg) {
const blurNsfl = localStorage.getItem('blurNsfl') === 'true';
const blurSfw = localStorage.getItem('blurSfw') === 'true';
const blurUntagged = localStorage.getItem('blurUntagged') === 'true';
let shouldBlurThis = false;
if (mode === 'nsfw') shouldBlurThis = blurNsfw;
else if (mode === 'nsfl') shouldBlurThis = blurNsfl;
else if (mode === 'sfw') shouldBlurThis = blurSfw;
else if (mode === 'null' || !mode) shouldBlurThis = blurUntagged;
if (shouldBlurThis && !thumb.classList.contains('revealed')) {
bg = bg.replace('.webp', '_blur.webp');
}
bg = window.applyThumbCacheBust(bg);
const img = new Image(); const img = new Image();
img.onload = () => { img.src = finalBg;
thumb.style.backgroundImage = `url('${bg}')`; if (img.complete && img.naturalWidth > 0) {
thumb.style.backgroundImage = `url('${finalBg}')`;
thumb.classList.add('loaded'); thumb.classList.add('loaded');
thumb.classList.remove('lazy-thumb'); thumb.classList.remove('lazy-thumb');
window.loadedThumbs.add(finalBg);
} else {
img.onload = () => {
thumb.style.backgroundImage = `url('${finalBg}')`;
thumb.classList.add('loaded');
thumb.classList.remove('lazy-thumb');
window.loadedThumbs.add(finalBg);
}; };
img.onerror = () => { img.onerror = () => {
const retries = parseInt(thumb.dataset.retries || '0'); const retries = parseInt(thumb.dataset.retries || '0');
if (retries < 3) { if (retries < 3) {
thumb.dataset.retries = retries + 1; thumb.dataset.retries = retries + 1;
setTimeout(() => { setTimeout(() => {
img.src = bg + '?r=' + Date.now(); img.src = finalBg + '?r=' + Date.now();
}, 1000); }, 1000);
} else { } else {
// All retries exhausted — show fallback for audio items // All retries exhausted — show fallback for audio items
@@ -231,7 +242,8 @@ window.cancelAnimFrame = (function () {
thumb.classList.remove('lazy-thumb'); thumb.classList.remove('lazy-thumb');
} }
}; };
img.src = bg; }
}
} }
lazyObserver.unobserve(thumb); lazyObserver.unobserve(thumb);
} }
@@ -2108,6 +2120,7 @@ window.cancelAnimFrame = (function () {
window.initSidebarRightToggle(); window.initSidebarRightToggle();
const loadPageAjax = async (url, replace = true, options = {}) => { const loadPageAjax = async (url, replace = true, options = {}) => {
console.log('[f0ck-debug] loadPageAjax called:', { url, replace, options, isNavigating });
if (isNavigating) return; if (isNavigating) return;
// Immediately restore scrollability and hide modals // Immediately restore scrollability and hide modals
@@ -2405,7 +2418,7 @@ window.cancelAnimFrame = (function () {
const needsFullHtmlFetch = isProfile || isUserHall || isUserHalls || isTags || isHall || isHalls || isComments || isNotifs || isAdmin || isMod || isSettings || isStatic || isMessages || isAbyss; const needsFullHtmlFetch = isProfile || isUserHall || isUserHalls || isTags || isHall || isHalls || isComments || isNotifs || isAdmin || isMod || isSettings || isStatic || isMessages || isAbyss;
const fetchHeaders = { 'Credentials': 'include', 'Cache-Control': 'no-store' }; const fetchHeaders = { 'Credentials': 'include', 'Cache-Control': 'no-cache' };
if (!needsFullHtmlFetch) { if (!needsFullHtmlFetch) {
fetchHeaders['X-Requested-With'] = 'XMLHttpRequest'; fetchHeaders['X-Requested-With'] = 'XMLHttpRequest';
} }
@@ -2415,7 +2428,7 @@ window.cancelAnimFrame = (function () {
const response = await fetch(needsFullHtmlFetch ? url : ajaxUrl, { const response = await fetch(needsFullHtmlFetch ? url : ajaxUrl, {
credentials: 'include', credentials: 'include',
headers: fetchHeaders, headers: fetchHeaders,
cache: 'no-store' cache: 'no-cache'
}); });
if (needsFullHtmlFetch) { if (needsFullHtmlFetch) {
@@ -2933,7 +2946,7 @@ window.cancelAnimFrame = (function () {
} }
} catch (err) { } catch (err) {
console.error(err); console.error('[f0ck-debug] loadPageAjax failed with error:', err);
window.location.href = url; // Fallback window.location.href = url; // Fallback
} finally { } finally {
isNavigating = false; isNavigating = false;
@@ -3431,6 +3444,7 @@ window.cancelAnimFrame = (function () {
// Intercept clicks // Intercept clicks
document.addEventListener('click', (e) => { document.addEventListener('click', (e) => {
const target = e.target.nodeType === 3 ? e.target.parentElement : e.target; const target = e.target.nodeType === 3 ? e.target.parentElement : e.target;
console.log('[f0ck-debug] Document clicked, target:', target);
// Check for mode selection (only applies to <a href="/mode/..."> links, not plain buttons) // Check for mode selection (only applies to <a href="/mode/..."> links, not plain buttons)
const modeBtn = target.closest('.mode-btn'); const modeBtn = target.closest('.mode-btn');
@@ -3685,6 +3699,7 @@ window.cancelAnimFrame = (function () {
if (!isSpecialLink && (pathname === '/' || pathname.startsWith('/halls') || pathname.startsWith('/h/') || pathname.startsWith('/notifications') || pathname.startsWith('/tag') || pathname.startsWith('/user/') || pathname.match(/^\/(image|video|audio)/) || pathname.match(/\/p\/\d+/) || pathname.match(/^\/\d+/) || pathname.match(/^\/(about|rules|terms|upload|subscriptions|stats|docs|settings|admin|mod|ranking|messages|meme|memes)/) || pathname.startsWith('/abyss'))) { if (!isSpecialLink && (pathname === '/' || pathname.startsWith('/halls') || pathname.startsWith('/h/') || pathname.startsWith('/notifications') || pathname.startsWith('/tag') || pathname.startsWith('/user/') || pathname.match(/^\/(image|video|audio)/) || pathname.match(/\/p\/\d+/) || pathname.match(/^\/\d+/) || pathname.match(/^\/(about|rules|terms|upload|subscriptions|stats|docs|settings|admin|mod|ranking|messages|meme|memes)/) || pathname.startsWith('/abyss'))) {
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
console.log('[f0ck-debug] Intercepted link navigation:', { pathname, href: anyLink.href });
let targetUrl = anyLink.href; let targetUrl = anyLink.href;
// Strip strict param if present to rely on session and keep URL clean // Strip strict param if present to rely on session and keep URL clean

View File

@@ -262,7 +262,7 @@ export default (router, tpl) => {
return res.reply({ return res.reply({
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate', 'Cache-Control': 'no-cache, must-revalidate, proxy-revalidate',
'Pragma': 'no-cache', 'Pragma': 'no-cache',
'Expires': '0' 'Expires': '0'
}, },