feat(интерфейс): светлая тема при первом визите, тёмная — по выбору

Первый визит больше не уходит в тёмную тему из-за системной настройки: без
сохранённого выбора страница светлая. Переключатель по-прежнему главнее системы,
выбор остаётся после перезагрузки. Проверка на первую страницу смотрит системную
тёмную настройку и повторный визит.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-18 21:30:20 +10:00
co-authored by Claude Code
parent 7ae5fff7e2
commit df5bfd93b1
10 changed files with 36 additions and 13 deletions
+1 -1
View File
@@ -447,7 +447,7 @@ th[data-hint] { cursor: help; text-decoration: underline dotted;
/* Тема и оформление — до первой отрисовки, иначе человек видит вспышку чужого вида.
Две независимые оси: data-theme (светлая/тёмная) и data-design (набор оформления). */
var DESIGNS=['calm','dense','bold','glass'];
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){var d='calm';try{var v=localStorage.getItem('design');if(DESIGNS.indexOf(v)>=0)d=v;}catch(e){}document.documentElement.setAttribute('data-design',d);})();
function toggleTheme(){var n=document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark';document.documentElement.setAttribute('data-theme',n);try{localStorage.setItem('theme',n);}catch(e){}applyThemeIcon();}
function applyThemeIcon(){var b=document.getElementById('theme-toggle');if(b)b.textContent=document.documentElement.getAttribute('data-theme')==='dark'?'☀ Светлая тема':'🌙 Тёмная тема';}
+3 -3
View File
@@ -441,7 +441,7 @@ button { font-family: inherit; }
@container main-col (max-width: 480px) { .badge-label { display: none; } }
/* ===== Тёмная тема (Ководство: тёплый «не-чёрный» фон, «не-белый» текст, */
/* акцент чуть подсвечен для контраста; переключатель + системное предпочтение) ===== */
/* акцент чуть подсвечен для контраста; переключатель + сохранённый выбор) ===== */
html { color-scheme: light; }
:root[data-theme="dark"] {
color-scheme: dark;
@@ -476,12 +476,12 @@ html { color-scheme: light; }
</style>
<script>
/* Тема ДО первой отрисовки — без мигания (FOUC).
Приоритет: сохранённый выбор → системное предпочтение → светлая. */
Приоритет: сохранённый выбор → светлая (системную тему не наследуем). */
(function () {
try {
var t = localStorage.getItem('theme');
if (t !== 'dark' && t !== 'light') {
t = (window.matchMedia && matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
t = 'light';
}
document.documentElement.setAttribute('data-theme', t);
} catch (e) {}
+1 -1
View File
@@ -30,7 +30,7 @@ html { color-scheme: light; }
:root[data-theme="dark"] button:hover { background: #c2564a; }
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
</script>
</head>
<body>
+1 -1
View File
@@ -43,7 +43,7 @@ html { color-scheme: light; }
}
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
</script>
</head>
<body>
+1 -1
View File
@@ -34,7 +34,7 @@ html { color-scheme: light; }
:root[data-theme="dark"] .draft { background: #3a3218; border-color: #8a7a2a; color: #e5d68a; }
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
</script>
</head>
<body>
+1 -1
View File
@@ -53,7 +53,7 @@ html { color-scheme: light; }
@media (max-width: 640px) { #theme-fab { top: auto; bottom: .9rem; right: .9rem; } }
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
function toggleTheme(){var n=document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark';document.documentElement.setAttribute('data-theme',n);try{localStorage.setItem('theme',n);}catch(e){}applyThemeIcon();if(typeof renderCaptcha==='function')renderCaptcha();}
function applyThemeIcon(){var b=document.getElementById('theme-fab');if(b)b.textContent=document.documentElement.getAttribute('data-theme')==='dark'?'☀':'☾';}
document.addEventListener('DOMContentLoaded',applyThemeIcon);
+1 -1
View File
@@ -50,7 +50,7 @@ html { color-scheme: light; }
@media (max-width: 640px) { #theme-fab { top: auto; bottom: .9rem; right: .9rem; } }
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
function toggleTheme(){var n=document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark';document.documentElement.setAttribute('data-theme',n);try{localStorage.setItem('theme',n);}catch(e){}applyThemeIcon();}
function applyThemeIcon(){var b=document.getElementById('theme-fab');if(b)b.textContent=document.documentElement.getAttribute('data-theme')==='dark'?'☀':'☾';}
document.addEventListener('DOMContentLoaded',applyThemeIcon);
+1 -1
View File
@@ -69,7 +69,7 @@ td.bar-cell { width: 38%; }
try {
var t = localStorage.getItem('theme');
if (t !== 'dark' && t !== 'light') {
t = (window.matchMedia && matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
t = 'light';
}
document.documentElement.setAttribute('data-theme', t);
} catch (e) {}
+1 -1
View File
@@ -30,7 +30,7 @@ html { color-scheme: light; }
}
</style>
<script>
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t='light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
</script>
</head>
<body>
+25 -2
View File
@@ -53,8 +53,11 @@ def site(tmp_path_factory):
srv.server_close()
def _страница(browser, site, width=1280, height=900):
ctx = browser.new_context(viewport={"width": width, "height": height})
def _страница(browser, site, width=1280, height=900, color_scheme=None):
opts = {"viewport": {"width": width, "height": height}}
if color_scheme:
opts["color_scheme"] = color_scheme
ctx = browser.new_context(**opts)
pg = ctx.new_page()
pg.set_default_timeout(8000)
pg._errors = []
@@ -240,3 +243,23 @@ def test_витрина_следует_теме_и_помнит_выбор(brows
assert not pg._errors, pg._errors
finally:
ctx.close()
def test_первый_визит_светлый_даже_при_тёмной_системе(browser, site):
"""Первый визит без сохранённого выбора — светлая тема, даже если система тёмная.
Выбор пользователя по-прежнему главнее: переключил в тёмную — она и останется."""
pg, ctx = _страница(browser, site, color_scheme="dark")
try:
assert pg.evaluate("() => localStorage.getItem('theme')") is None
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "light"
фон = pg.evaluate("() => getComputedStyle(document.getElementById('login-screen')).backgroundColor")
assert фон == "rgb(246, 241, 234)", f"первый визит не в светлой палитре: {фон}"
pg.click("#login-fab")
assert pg.evaluate("() => localStorage.getItem('theme')") == "dark"
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "dark"
pg.reload()
pg.wait_for_selector("#login-screen", state="visible")
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "dark"
assert not pg._errors, pg._errors
finally:
ctx.close()