Skip to content

Commit

Permalink
【修复】主题切换问题
Browse files Browse the repository at this point in the history
  • Loading branch information
PJ-568 committed May 22, 2024
1 parent 8bfab5f commit 3c7576d
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions js/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
}

// giscus 评论系统
//// 若当前 mdbook 主题为 Light 或 Rust ,则将 giscus 主题设置为 light
const getCurrentTheme = function () {
var theme = "transparent_dark";
const themeClass = document.getElementsByTagName("html")[0].className;
if (themeClass.indexOf("light") != -1 || themeClass.indexOf("rust") != -1) {
theme = "light";
}
return theme;
}

//// 获取用户使用的语种并转换为 giscus 可识别的标记
const getCurrentLanguage = function () {
var lang = translate.language.getCurrent();
Expand Down Expand Up @@ -57,7 +47,7 @@
return giscus_lang;
}

var SetupGiscus = function (giscus_lang, theme) {
var SetupGiscus = function (giscus_lang) {
if (document.getElementById("giscus-container") != null) {
const script = document.createElement("script");
script.type = "text/javascript";
Expand All @@ -74,7 +64,7 @@
script.setAttribute("data-reactions-enabled", "1");
script.setAttribute("data-emit-metadata", "0");
script.setAttribute("data-input-position", "top");
script.setAttribute("data-theme", theme);
script.setAttribute("data-theme", 'light_high_contrast');
script.setAttribute("data-lang", giscus_lang);

script.crossOrigin = "anonymous";
Expand Down Expand Up @@ -186,7 +176,7 @@
includeHTML(); //// 引入
initTranslate(); //// 初始化页面翻译
initAni(); //// 初始化加载动画
SetupGiscus(getCurrentLanguage(), getCurrentTheme()); //// 初始化评论系统
SetupGiscus(getCurrentLanguage()); //// 初始化评论系统
}


Expand All @@ -195,7 +185,7 @@
window.addEventListener('DOMContentLoaded', () => initialize());
//// 翻译执行完成后触发
translate.listener.renderTaskFinish = function () {
SetupGiscus(getCurrentLanguage(), getCurrentTheme());
SetupGiscus(getCurrentLanguage());
}
//// Pjax 开始时执行的函数
document.addEventListener("pjax:send", function () {
Expand All @@ -218,7 +208,7 @@
});
//// 监听 Pjax 完成后,重新加载的函数
document.addEventListener("pjax:complete", function () {
SetupGiscus(getCurrentLanguage(), getCurrentTheme());
SetupGiscus(getCurrentLanguage());
includeHTML();
endLoad();
})
Expand Down

0 comments on commit 3c7576d

Please sign in to comment.