style: prettify utteranc
code snippet
This commit is contained in:
parent
f079bb7f5b
commit
bb589e8d31
1 changed files with 20 additions and 22 deletions
|
@ -1,51 +1,49 @@
|
||||||
<!-- https://utteranc.es/ -->
|
<!-- https://utteranc.es/ -->
|
||||||
<script src="https://utteranc.es/client.js"
|
<script
|
||||||
repo="{{ site.comments.utterances.repo }}"
|
src="https://utteranc.es/client.js"
|
||||||
issue-term="{{ site.comments.utterances.issue_term }}"
|
repo="{{ site.comments.utterances.repo }}"
|
||||||
crossorigin="anonymous"
|
issue-term="{{ site.comments.utterances.issue_term }}"
|
||||||
async>
|
crossorigin="anonymous"
|
||||||
</script>
|
async
|
||||||
|
></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function () {
|
||||||
const origin = "https://utteranc.es";
|
const origin = 'https://utteranc.es';
|
||||||
const iframe = "iframe.utterances-frame";
|
const iframe = 'iframe.utterances-frame';
|
||||||
const lightTheme = "github-light";
|
const lightTheme = 'github-light';
|
||||||
const darkTheme = "github-dark";
|
const darkTheme = 'github-dark';
|
||||||
let initTheme = lightTheme;
|
let initTheme = lightTheme;
|
||||||
|
|
||||||
if ($("html[data-mode=dark]").length > 0
|
if (
|
||||||
|| ($("html[data-mode]").length == 0
|
$('html[data-mode=dark]').length > 0 ||
|
||||||
&& window.matchMedia("(prefers-color-scheme: dark)").matches)) {
|
($('html[data-mode]').length == 0 && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||||||
|
) {
|
||||||
initTheme = darkTheme;
|
initTheme = darkTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener("message", (event) => {
|
addEventListener('message', (event) => {
|
||||||
let theme;
|
let theme;
|
||||||
|
|
||||||
/* credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347> */
|
/* credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347> */
|
||||||
if (event.origin === origin) {
|
if (event.origin === origin) {
|
||||||
/* page initial */
|
/* page initial */
|
||||||
theme = initTheme;
|
theme = initTheme;
|
||||||
|
} else if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
|
||||||
} else if (event.source === window && event.data &&
|
|
||||||
event.data.direction === ModeToggle.ID) {
|
|
||||||
/* global theme mode changed */
|
/* global theme mode changed */
|
||||||
const mode = event.data.message;
|
const mode = event.data.message;
|
||||||
theme = (mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme);
|
theme = mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
type: "set-theme",
|
type: 'set-theme',
|
||||||
theme: theme
|
theme: theme
|
||||||
};
|
};
|
||||||
|
|
||||||
const utterances = document.querySelector(iframe).contentWindow;
|
const utterances = document.querySelector(iframe).contentWindow;
|
||||||
utterances.postMessage(message, origin);
|
utterances.postMessage(message, origin);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue