Skip to content

Commit

Permalink
Create utterances.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lwcarani committed Apr 5, 2024
1 parent fed0e9b commit 76b812f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions _includes/comments/utterances.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- https://utteranc.es/ -->
<script src="https://utteranc.es/client.js" repo="{{ site.comments.utterances.repo }}"
issue-term="{{ site.comments.utterances.issue_term }}" crossorigin="anonymous" async></script>

<script type="text/javascript">
(function () {
const origin = 'https://utteranc.es';
const iframe = 'iframe.utterances-frame';
const lightTheme = 'github-light';
const darkTheme = 'github-dark';
let initTheme = lightTheme;
const html = document.documentElement;

if (
(html.hasAttribute('data-mode') && html.getAttribute('data-mode') === 'dark') ||
(!html.hasAttribute('data-mode') && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
initTheme = darkTheme;
}

addEventListener('message', (event) => {
let theme;

/* credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347> */
if (event.origin === origin) {
/* page initial */
theme = initTheme;
} else if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
/* global theme mode changed */
const mode = event.data.message;
theme = mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme;
} else {
return;
}

const message = {
type: 'set-theme',
theme: theme
};

const utterances = document.querySelector(iframe).contentWindow;
utterances.postMessage(message, origin);
});
})();
</script>

0 comments on commit 76b812f

Please sign in to comment.