persistency mismatch
This commit is contained in:
@@ -549,18 +549,29 @@ window.cancelAnimFrame = (function () {
|
|||||||
img.src = randomImg;
|
img.src = randomImg;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize active mode: prefer mode cookie, then session, then legacy mode-btn
|
// Initialize active mode.
|
||||||
const _modeCookieRaw = document.cookie.split('; ').find(r => r.startsWith('mode='));
|
// For logged-in users, the server's f0ckSession.mode (sourced from user_options DB) is the
|
||||||
if (_modeCookieRaw) {
|
// authoritative cross-device truth. A stale local `mode` cookie from a previous session on
|
||||||
window.activeMode = +_modeCookieRaw.split('=')[1];
|
// this device could disagree (e.g. PC had ALL, mobile set SFW — PC cookie still says 3).
|
||||||
} else if (window.f0ckSession && window.f0ckSession.mode !== undefined) {
|
// Fix: prefer f0ckSession.mode when logged in and reconcile the local cookie to match.
|
||||||
|
// For guests: fall back to cookie (no session = cookie is the only persistence).
|
||||||
|
if (window.f0ckSession && window.f0ckSession.logged_in && window.f0ckSession.mode !== undefined) {
|
||||||
window.activeMode = +window.f0ckSession.mode;
|
window.activeMode = +window.f0ckSession.mode;
|
||||||
|
// Reconcile the local cookie so future reads are consistent on this device
|
||||||
|
document.cookie = `mode=${window.activeMode}; Path=/; Max-Age=31536000`;
|
||||||
} else {
|
} else {
|
||||||
// Legacy fallback: read from old .mode-btn.active if present
|
const _modeCookieRaw = document.cookie.split('; ').find(r => r.startsWith('mode='));
|
||||||
const activeModeBtn = document.querySelector('.mode-btn.active');
|
if (_modeCookieRaw) {
|
||||||
if (activeModeBtn && activeModeBtn.href) {
|
window.activeMode = +_modeCookieRaw.split('=')[1];
|
||||||
const modeMatch = activeModeBtn.href.match(/\/mode\/(\d)/);
|
} else if (window.f0ckSession && window.f0ckSession.mode !== undefined) {
|
||||||
if (modeMatch) window.activeMode = +modeMatch[1];
|
window.activeMode = +window.f0ckSession.mode;
|
||||||
|
} else {
|
||||||
|
// Legacy fallback: read from old .mode-btn.active if present
|
||||||
|
const activeModeBtn = document.querySelector('.mode-btn.active');
|
||||||
|
if (activeModeBtn && activeModeBtn.href) {
|
||||||
|
const modeMatch = activeModeBtn.href.match(/\/mode\/(\d)/);
|
||||||
|
if (modeMatch) window.activeMode = +modeMatch[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user