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 bcb0262 commit 22af026
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions assets/override.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
// giscus 评论系统
//// 若当前 mdbook 主题为 Light 或 Rust ,则将 giscus 主题设置为 light
const getCurrentTheme = function () {
Expand Down Expand Up @@ -72,14 +72,14 @@

// translate-js 翻译系统
function initTranslate() {
try{
try {
translate.service.use('client.edge');
translate.listener.start();
translate.language.setLocal('chinese_simplified');
translate.setAutoDiscriminateLocalLanguage();
translate.language.setUrlParamControl();
translate.ignore.class.push('notTranslate');
translate.nomenclature.append('chinese_simplified','english',`
translate.nomenclature.append('chinese_simplified', 'english', `
哈姆语言之书=Hamud Book
哈姆语=the language of Hamud
哈姆德=the Hamud
Expand All @@ -93,38 +93,38 @@
`);
translate.execute();
}
catch(e){
catch (e) {
console.log('翻译系统出错:' + e);
}
}


var loadingBar = document.querySelector(".loading-bar");
var progress = document.querySelector(".loading-bar .progress");
var timer = null;
var progress = document.querySelector(".loading-bar .progress");
var timer = null;

function initAni() {
loadingBar = document.querySelector(".loading-bar");
progress = document.querySelector(".loading-bar .progress");
}
loadingBar = document.querySelector(".loading-bar");
progress = document.querySelector(".loading-bar .progress");
}

function endLoad() {
clearInterval(timer);
progress.style.width = "100%";
loadingBar.classList.remove("loading");

function endLoad(){
clearInterval(timer);
progress.style.width = "100%";
loadingBar.classList.remove("loading");

setTimeout(function () {
progress.style.width = 0;
}, 400);
}
setTimeout(function () {
progress.style.width = 0;
}, 400);
}


// PJAX 集成
let pjax;
//// 初始化 PJAX
function initPjax(){
try{
const Pjax = window.Pjax || function() {};
function initPjax() {
try {
const Pjax = window.Pjax || function () { };
pjax = new Pjax({
selectors: [
"head title",
Expand All @@ -138,7 +138,7 @@
]
})
}
catch(e){
catch (e) {
console.log('PJAX 出错:' + e);
}
}
Expand All @@ -157,28 +157,28 @@
//// 网页加载完毕后触发
window.addEventListener('DOMContentLoaded', () => initialize());
//// 翻译执行完成后触发
translate.listener.renderTaskFinish = function() {
translate.listener.renderTaskFinish = function () {
SetupGiscus(getCurrentLanguage(), getCurrentTheme());
}
//// Pjax 开始时执行的函数
document.addEventListener("pjax:send", function () {
var loadingBarWidth = 20;
var MAX_LOADING_WIDTH = 95;

loadingBar.classList.add("loading");
progress.style.width = loadingBarWidth + "%";
clearInterval(timer);
timer = setInterval(function () {
loadingBarWidth += 3;
if (loadingBarWidth > MAX_LOADING_WIDTH) {
loadingBarWidth = MAX_LOADING_WIDTH;
}
progress.style.width = loadingBarWidth + "%";
}, 500);
});
document.addEventListener("pjax:send", function () {
var loadingBarWidth = 20;
var MAX_LOADING_WIDTH = 95;

loadingBar.classList.add("loading");
progress.style.width = loadingBarWidth + "%";

clearInterval(timer);
timer = setInterval(function () {
loadingBarWidth += 3;

if (loadingBarWidth > MAX_LOADING_WIDTH) {
loadingBarWidth = MAX_LOADING_WIDTH;
}

progress.style.width = loadingBarWidth + "%";
}, 500);
});
//// 监听 Pjax 完成后,重新加载上面的函数
document.addEventListener("pjax:complete", function () {
SetupGiscus(getCurrentLanguage(), getCurrentTheme());
Expand Down

0 comments on commit 22af026

Please sign in to comment.