|
1 | 1 | <!-- https://utteranc.es/ -->
|
2 |
| -<script src="https://utteranc.es/client.js" |
3 |
| - repo="{{ site.comments.utterances.repo }}" |
4 |
| - issue-term="{{ site.comments.utterances.issue_term }}" |
5 |
| - crossorigin="anonymous" |
6 |
| - async> |
7 |
| -</script> |
| 2 | +<script |
| 3 | + src="https://utteranc.es/client.js" |
| 4 | + repo="{{ site.comments.utterances.repo }}" |
| 5 | + issue-term="{{ site.comments.utterances.issue_term }}" |
| 6 | + crossorigin="anonymous" |
| 7 | + async |
| 8 | +></script> |
8 | 9 |
|
9 | 10 | <script type="text/javascript">
|
10 |
| - $(function() { |
11 |
| - const origin = "https://utteranc.es"; |
12 |
| - const iframe = "iframe.utterances-frame"; |
13 |
| - const lightTheme = "github-light"; |
14 |
| - const darkTheme = "github-dark"; |
| 11 | + (function () { |
| 12 | + const origin = 'https://utteranc.es'; |
| 13 | + const iframe = 'iframe.utterances-frame'; |
| 14 | + const lightTheme = 'github-light'; |
| 15 | + const darkTheme = 'github-dark'; |
15 | 16 | let initTheme = lightTheme;
|
| 17 | + const html = document.documentElement; |
16 | 18 |
|
17 |
| - if ($("html[data-mode=dark]").length > 0 |
18 |
| - || ($("html[data-mode]").length == 0 |
19 |
| - && window.matchMedia("(prefers-color-scheme: dark)").matches)) { |
| 19 | + if ( |
| 20 | + (html.hasAttribute('data-mode') && html.getAttribute('data-mode') === 'dark') || |
| 21 | + (!html.hasAttribute('data-mode') && window.matchMedia('(prefers-color-scheme: dark)').matches) |
| 22 | + ) { |
20 | 23 | initTheme = darkTheme;
|
21 | 24 | }
|
22 | 25 |
|
23 |
| - addEventListener("message", (event) => { |
| 26 | + addEventListener('message', (event) => { |
24 | 27 | let theme;
|
25 | 28 |
|
26 | 29 | /* credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347> */
|
27 | 30 | if (event.origin === origin) {
|
28 | 31 | /* page initial */
|
29 | 32 | theme = initTheme;
|
30 |
| - |
31 |
| - } else if (event.source === window && event.data && |
32 |
| - event.data.direction === ModeToggle.ID) { |
| 33 | + } else if (event.source === window && event.data && event.data.direction === ModeToggle.ID) { |
33 | 34 | /* global theme mode changed */
|
34 | 35 | const mode = event.data.message;
|
35 |
| - theme = (mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme); |
36 |
| - |
| 36 | + theme = mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme; |
37 | 37 | } else {
|
38 | 38 | return;
|
39 | 39 | }
|
40 | 40 |
|
41 | 41 | const message = {
|
42 |
| - type: "set-theme", |
| 42 | + type: 'set-theme', |
43 | 43 | theme: theme
|
44 | 44 | };
|
45 | 45 |
|
46 | 46 | const utterances = document.querySelector(iframe).contentWindow;
|
47 | 47 | utterances.postMessage(message, origin);
|
48 | 48 | });
|
49 |
| - |
50 |
| - }); |
| 49 | + })(); |
51 | 50 | </script>
|
0 commit comments