Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

22 lines
774B

  1. <script type="module">
  2. import * as DarkModeToggle from 'https://unpkg.com/dark-mode-toggle';
  3. const toggle = document.querySelector('dark-mode-toggle');
  4. const body = document.body;
  5. // Set or remove the `dark` class the first time.
  6. body.classList.remove('dark');
  7. body.classList.remove('light');
  8. if (toggle.mode === 'dark') {
  9. body.classList.add('dark')
  10. } else {
  11. body.classList.add('light')
  12. }
  13. // Listen for toggle changes (which includes `prefers-color-scheme` changes)
  14. // and toggle the `dark` class accordingly.
  15. toggle.addEventListener('colorschemechange', () => {
  16. body.classList.toggle('dark', toggle.mode === 'dark');
  17. body.classList.toggle('light', toggle.mode !== 'dark');
  18. });
  19. </script>