utterances.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <script src="https://utteranc.es/client.js"
  2. repo="{{ .Site.Params.comments.utterances.repo }}"
  3. issue-term="{{ .Site.Params.comments.utterances.issueTerm }}"
  4. {{ with .Site.Params.comments.utterances.label }}
  5. label="{{ . }}"
  6. {{ end }}
  7. crossorigin="anonymous"
  8. async
  9. >
  10. </script>
  11. <style>
  12. .utterances {
  13. max-width: unset;
  14. }
  15. </style>
  16. <script>
  17. function setUtterancesTheme(theme) {
  18. let utterances = document.querySelector('.utterances iframe');
  19. if (utterances) {
  20. utterances.contentWindow.postMessage(
  21. {
  22. type: 'set-theme',
  23. theme: `github-${theme}`
  24. },
  25. 'https://utteranc.es'
  26. );
  27. }
  28. }
  29. addEventListener('message', event => {
  30. if (event.origin !== 'https://utteranc.es') return;
  31. setUtterancesTheme(document.documentElement.dataset.scheme)
  32. });
  33. window.addEventListener('onColorSchemeChange', (e) => {
  34. setUtterancesTheme(e.detail)
  35. })
  36. </script>