46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
/* Синхронная ранняя установка data-theme + data-high-contrast + критические стили. */
|
|
(function () {
|
|
var KEY = "theme";
|
|
var HC_KEY = "wespHighContrast";
|
|
var saved = localStorage.getItem(KEY);
|
|
var theme =
|
|
saved === "dark" || saved === "light" || saved === "organic" ? saved : "dark";
|
|
var root = document.documentElement;
|
|
root.dataset.theme = theme;
|
|
|
|
var hcSaved = localStorage.getItem(HC_KEY);
|
|
var highContrast =
|
|
hcSaved === "1"
|
|
? true
|
|
: hcSaved === "0"
|
|
? false
|
|
: !!(window.matchMedia && window.matchMedia("(prefers-contrast: more)").matches);
|
|
root.dataset.highContrast = highContrast ? "true" : "false";
|
|
|
|
var ORGANIC_LOGO_FILTER =
|
|
"brightness(0) saturate(100%) invert(43%) sepia(19%) saturate(747%) " +
|
|
"hue-rotate(118deg) brightness(92%) contrast(87%)";
|
|
|
|
var ORGANIC_LOGO_FILTER_HC =
|
|
"brightness(0) saturate(100%) invert(28%) sepia(22%) saturate(900%) " +
|
|
"hue-rotate(118deg) brightness(88%) contrast(96%)";
|
|
|
|
var organicLogoFilter =
|
|
theme === "organic" && highContrast ? ORGANIC_LOGO_FILTER_HC : ORGANIC_LOGO_FILTER;
|
|
|
|
var css =
|
|
'html{background:#f5f7fa}' +
|
|
'html[data-theme="dark"]{background:#12181b}' +
|
|
'html[data-theme="organic"]{background:#f6f6f4}' +
|
|
'html[data-theme="organic"] .nav-brand .logo.logo--light-theme,' +
|
|
'html[data-theme="organic"] .mobile-brand .logo.logo--light-theme{' +
|
|
"filter:" +
|
|
organicLogoFilter +
|
|
"!important}";
|
|
|
|
var el = document.createElement("style");
|
|
el.id = "wesp-theme-critical";
|
|
el.textContent = css;
|
|
document.head.appendChild(el);
|
|
})();
|