You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 satır
763B

  1. <script type="module">
  2. import * as DarkModeToggle from '/static/js/darkmode.mjs';
  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>