選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

22 行
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>