From e0c435009b362a2df1b5544dea182b98db3325ee Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Sat, 23 May 2026 20:21:47 +0200 Subject: [PATCH] better filters --- public/s/js/f0ckm.js | 50 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/public/s/js/f0ckm.js b/public/s/js/f0ckm.js index 79902d4..2c86283 100644 --- a/public/s/js/f0ckm.js +++ b/public/s/js/f0ckm.js @@ -555,6 +555,8 @@ window.cancelAnimFrame = (function () { 'content-warning-modal', 'gchat-img-modal', 'image-modal', 'info-modal' ]; modalIds.forEach(id => { + // Don't close the filter modal during a background mime-filter reload + if (id === 'excluded-tags-overlay' && window._keepFilterModal) return; const el = document.getElementById(id); if (el) { el.classList.remove('show', 'visible'); @@ -3050,6 +3052,10 @@ window.cancelAnimFrame = (function () { // Sync state immediately via cookie to avoid race conditions document.cookie = `mode=${window.activeMode}; Path=/; Max-Age=31536000`; + // Keep filter modal open if the click came from inside it + const fromFilterModal = !!modeBtn.closest('#excluded-tags-overlay'); + if (fromFilterModal) window._keepFilterModal = true; + // Update mode via AJAX fetch(modeBtn.href, { headers: { 'X-Requested-With': 'XMLHttpRequest' }, @@ -3068,21 +3074,28 @@ window.cancelAnimFrame = (function () { const isGridView = document.querySelector('.posts, .tags-grid'); const isItemView = document.getElementById('prev') || document.getElementById('next'); + let reloadPromise = null; if (isGridView) { // Reload current page without ?mode= in the URL — server picks up mode from session/cookie const currentUrl = new URL(window.location.href); currentUrl.searchParams.delete('mode'); - loadPageAjax(currentUrl.toString(), true, { skipCache: true }); + reloadPromise = loadPageAjax(currentUrl.toString(), true, { skipCache: true }); } else if (isItemView) { // Directly update nav links for the new mode without keepMedia complexity updateNavForMode(window.activeMode); } + + if (fromFilterModal) { + Promise.resolve(reloadPromise).finally(() => { window._keepFilterModal = false; }); + } } else { + if (fromFilterModal) window._keepFilterModal = false; // Fallback window.location.href = modeBtn.href; } }) .catch(err => { + if (fromFilterModal) window._keepFilterModal = false; console.error("Mode update failed:", err); window.location.href = modeBtn.href; }); @@ -6930,17 +6943,30 @@ document.addEventListener("DOMContentLoaded", function () { // Sync UI immediately (Before AJAX) if (window.updateMimeLabel) window.updateMimeLabel(); - // Trigger reload context-aware - const postsEl = document.querySelector('.posts, .tags-grid'); - if (postsEl) { - if (window.loadPageAjax) window.loadPageAjax(url.toString(), { skipPush: true }); - } else if (document.getElementById('main')?.classList.contains('item-view') || document.querySelector('.item-layout-container, .item-main-content')) { - // On item view, refresh the context but KEEP media playing - if (window.loadItemAjax) window.loadItemAjax(url.toString(), true, { keepMedia: true }); - } else { - // Fallback for non-AJAX pages - window.location.reload(); - } + // Trigger reload context-aware + const fromModal = !!menu.closest('#excluded-tags-overlay'); + const postsEl = document.querySelector('.posts, .tags-grid'); + let reloadPromise = null; + + // Set flag so hideAllModals (called inside loadPageAjax) skips the filter overlay + if (fromModal) window._keepFilterModal = true; + + if (postsEl) { + reloadPromise = window.loadPageAjax ? window.loadPageAjax(url.toString(), { skipPush: true }) : null; + } else if (document.getElementById('main')?.classList.contains('item-view') || document.querySelector('.item-layout-container, .item-main-content')) { + // On item view, refresh the context but KEEP media playing + reloadPromise = window.loadItemAjax ? window.loadItemAjax(url.toString(), true, { keepMedia: true }) : null; + } else { + // Fallback for non-AJAX pages + if (!fromModal) window.location.reload(); + } + + // Clear the flag once the reload finishes (or immediately if no promise) + if (fromModal) { + Promise.resolve(reloadPromise).finally(() => { + window._keepFilterModal = false; + }); + } }; document.querySelectorAll('.nav-mime-menu').forEach(menu => {