|
1 | 1 | <!-- https://giscus.app/ --> |
2 | 2 | <script type="text/javascript"> |
3 | | - $(function () { |
4 | | - const origin = "https://giscus.app"; |
5 | | - const iframe = "iframe.giscus-frame"; |
6 | | - const lightTheme = "light"; |
7 | | - const darkTheme = "dark_dimmed"; |
| 3 | + (function () { |
| 4 | + const origin = 'https://giscus.app'; |
| 5 | + const iframe = 'iframe.giscus-frame'; |
| 6 | + const lightTheme = 'light'; |
| 7 | + const darkTheme = 'dark_dimmed'; |
| 8 | + |
8 | 9 | let initTheme = lightTheme; |
| 10 | + const html = document.documentElement; |
9 | 11 |
|
10 | | - if ($("html[data-mode=dark]").length > 0 |
11 | | - || ($("html[data-mode]").length == 0 |
12 | | - && window.matchMedia("(prefers-color-scheme: dark)").matches)) { |
| 12 | + if ( |
| 13 | + (html.hasAttribute('data-mode') && |
| 14 | + html.getAttribute('data-mode') === 'dark') || |
| 15 | + (!html.hasAttribute('data-mode') && |
| 16 | + window.matchMedia('(prefers-color-scheme: dark)').matches) |
| 17 | + ) { |
13 | 18 | initTheme = darkTheme; |
14 | 19 | } |
15 | 20 |
|
16 | 21 | let giscusAttributes = { |
17 | | - "src": "https://giscus.app/client.js", |
18 | | - "data-repo": "{{ site.comments.giscus.repo}}", |
19 | | - "data-repo-id": "{{ site.comments.giscus.repo_id }}", |
20 | | - "data-category": "{{ site.comments.giscus.category }}", |
21 | | - "data-category-id": "{{ site.comments.giscus.category_id }}", |
22 | | - "data-mapping": "{{ site.comments.giscus.mapping | default: 'pathname' }}", |
23 | | - "data-reactions-enabled": "{{ site.comments.giscus.reactions_enabled | default: '1' }}", |
24 | | - "data-emit-metadata": "0", |
25 | | - "data-theme": initTheme, |
26 | | - "data-input-position": "{{ site.comments.giscus.input_position | default: 'bottom' }}", |
27 | | - "data-lang": "{{ site.comments.giscus.lang | default: lang }}", |
28 | | - "crossorigin": "anonymous", |
29 | | - "async": "" |
| 22 | + src: 'https://giscus.app/client.js', |
| 23 | + 'data-repo': '{{ site.comments.giscus.repo}}', |
| 24 | + 'data-repo-id': '{{ site.comments.giscus.repo_id }}', |
| 25 | + 'data-category': '{{ site.comments.giscus.category }}', |
| 26 | + 'data-category-id': '{{ site.comments.giscus.category_id }}', |
| 27 | + 'data-mapping': '{{ site.comments.giscus.mapping | default: 'pathname' }}', |
| 28 | + 'data-reactions-enabled': '{{ site.comments.giscus.reactions_enabled | default: '1' }}', |
| 29 | + 'data-emit-metadata': '0', |
| 30 | + 'data-theme': initTheme, |
| 31 | + 'data-input-position': '{{ site.comments.giscus.input_position | default: 'bottom' }}', |
| 32 | + 'data-lang': '{{ site.comments.giscus.lang | default: lang }}', |
| 33 | + crossorigin: 'anonymous', |
| 34 | + async: '' |
30 | 35 | }; |
31 | 36 |
|
32 | | - let giscusScript = document.createElement("script"); |
33 | | - Object.entries(giscusAttributes).forEach(([key, value]) => giscusScript.setAttribute(key, value)); |
34 | | - document.getElementById("tail-wrapper").appendChild(giscusScript); |
| 37 | + let giscusScript = document.createElement('script'); |
| 38 | + Object.entries(giscusAttributes).forEach(([key, value]) => |
| 39 | + giscusScript.setAttribute(key, value) |
| 40 | + ); |
| 41 | + document.getElementById('tail-wrapper').appendChild(giscusScript); |
35 | 42 |
|
36 | | - addEventListener("message", (event) => { |
37 | | - if (event.source === window && event.data && |
38 | | - event.data.direction === ModeToggle.ID) { |
| 43 | + addEventListener('message', (event) => { |
| 44 | + if ( |
| 45 | + event.source === window && |
| 46 | + event.data && |
| 47 | + event.data.direction === ModeToggle.ID |
| 48 | + ) { |
39 | 49 | /* global theme mode changed */ |
40 | 50 | const mode = event.data.message; |
41 | | - const theme = (mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme); |
| 51 | + const theme = mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme; |
42 | 52 |
|
43 | 53 | const message = { |
44 | 54 | setConfig: { |
|
49 | 59 | const giscus = document.querySelector(iframe).contentWindow; |
50 | 60 | giscus.postMessage({ giscus: message }, origin); |
51 | 61 | } |
52 | | - |
53 | 62 | }); |
54 | | - |
55 | | - }); |
| 63 | + })(); |
56 | 64 | </script> |
0 commit comments