Test

Мой JS
Anonymous
javascript
02/19/2026 7:20 AM
992 B
10
Indexable
/* ============================================================
   Theme toggle
   ============================================================ */
(function () {
  const STORAGE_KEY = 'cp-theme';

  function getSavedTheme() {
    const saved = localStorage.getItem(STORAGE_KEY);
    if (saved !== null) return saved === 'dark';
    return window.matchMedia('(prefers-color-scheme: dark)').matches;
  }

  function applyTheme(dark) {
    document.body.classList.toggle('dark', dark);
    // sync html class too (set by inline script before body load)
    document.documentElement.classList.toggle('dark', dark);
    const btn = document.getElementById('theme-toggle');
    if (btn) btn.textContent = dark ? '☀' : '☾';
  }
Editor is loading...
Leave a Comment