-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63706e0
commit a9ea151
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function appendGiscusScript() { | ||
const pageDiv = document.querySelector('#content > main'); | ||
|
||
if (!pageDiv) { | ||
console.error('Could not find div with class "page"'); | ||
return; | ||
} | ||
// 创建评论容器 | ||
const commentsDiv = document.createElement('div'); | ||
commentsDiv.className = 'giscus'; | ||
pageDiv.appendChild(commentsDiv); | ||
|
||
// 创建 script 元素 | ||
const script = document.createElement('script'); | ||
// 设置脚本属性 | ||
script.src = "https://giscus.app/client.js"; | ||
script.setAttribute("data-repo", "zigcc/zig-cookbook"); | ||
script.setAttribute("data-repo-id", "R_kgDOK34kdA"); | ||
script.setAttribute("data-category", "General"); | ||
script.setAttribute("data-category-id", "DIC_kwDOK34kdM4Clt_g"); | ||
script.setAttribute("data-mapping", "pathname"); | ||
script.setAttribute("data-strict", "1"); | ||
script.setAttribute("data-reactions-enabled", "1"); | ||
script.setAttribute("data-emit-metadata", "0"); | ||
script.setAttribute("data-input-position", "bottom"); | ||
script.setAttribute("data-theme", "preferred_color_scheme"); | ||
script.setAttribute("data-lang", "en"); | ||
script.setAttribute("crossorigin", "anonymous"); | ||
script.async = true; | ||
|
||
// 将脚本追加到 body 末尾 | ||
pageDiv.appendChild(script); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', appendGiscusScript); |