diff --git a/components/theme-client.php b/components/theme-client.php index 48ae94d..715ea10 100644 --- a/components/theme-client.php +++ b/components/theme-client.php @@ -11,7 +11,7 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv let shown = initial; const canonical = value => typeof value === 'string' && value.length <= 128 && /^v1:(light|dark):(manual|preland):[A-Za-z0-9_-]{16,64}(?![\s\S])/.test(value) ? value : null; const themeOf = value => value.split(':')[1]; - function read() { + function readCookie() { try { for (const part of document.cookie.split(';')) { const cookie = part.trim(); @@ -20,6 +20,11 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv if (value) return value; } } catch (_) {} + return null; + } + function read() { + const cookie = readCookie(); + if (cookie) return cookie; try { return canonical(window.localStorage.getItem(key)); } catch (_) { return null; } } function apply(theme) { @@ -66,5 +71,12 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv document.addEventListener('DOMContentLoaded', refresh); document.addEventListener('pjax:end', refresh); refresh(); + // Только первый boot зеркалит валидную cookie и уведомляет другие вкладки + // о server import. Read-only refresh/reinit не создают цикл storage events. + const bootCookie = readCookie(); + if (bootCookie) { + apply(themeOf(bootCookie)); + try { if (window.localStorage.getItem(key) !== bootCookie) window.localStorage.setItem(key, bootCookie); } catch (_) {} + } })(, );