Files
newznab-tmux/resources/views/partials/theme-init.blade.php
T
2026-03-03 15:50:36 +01:00

23 lines
907 B
PHP

{{--
Dark mode and color scheme initialization - MUST be included at the very top of <head>,
BEFORE any CSS/Vite tags, to prevent white flash on page load.
This tiny blocking script applies the 'dark' class and data-color-scheme to <html> synchronously
before the browser paints any content.
--}}
<script nonce="{{ csp_nonce() }}">
(function() {
var d = document.documentElement;
@auth
var t = '{{ auth()->user()->theme_preference ?? "light" }}';
var scheme = '{{ auth()->user()->color_scheme ?? "blue" }}';
@else
var t = localStorage.getItem('theme') || 'light';
var scheme = localStorage.getItem('color_scheme') || 'blue';
@endauth
if (t === 'dark' || (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
d.classList.add('dark');
}
d.setAttribute('data-color-scheme', scheme);
})();
</script>