|
|
@ -1,12 +1,12 @@
|
|
|
|
(function() {
|
|
|
|
var initAll = function () {
|
|
|
|
var path = window.location.pathname;
|
|
|
|
var path = window.location.pathname;
|
|
|
|
if (path.endsWith("/print.html")) {
|
|
|
|
if (path.endsWith("/print.html")) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var images = document.querySelectorAll("main img")
|
|
|
|
var images = document.querySelectorAll("main img")
|
|
|
|
Array.prototype.forEach.call(images, function(img) {
|
|
|
|
Array.prototype.forEach.call(images, function (img) {
|
|
|
|
img.addEventListener("click", function() {
|
|
|
|
img.addEventListener("click", function () {
|
|
|
|
BigPicture({
|
|
|
|
BigPicture({
|
|
|
|
el: img,
|
|
|
|
el: img,
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -14,91 +14,106 @@
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Un-active everything when you click it
|
|
|
|
// Un-active everything when you click it
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) {
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
|
|
|
el.addEventHandler("click", function() {
|
|
|
|
el.addEventHandler("click", function () {
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) {
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
|
|
|
el.classList.remove("active");
|
|
|
|
el.classList.remove("active");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
el.classList.add("active");
|
|
|
|
el.classList.add("active");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var updateFunction = function() {
|
|
|
|
var updateFunction = function () {
|
|
|
|
|
|
|
|
var id = null;
|
|
|
|
var id;
|
|
|
|
|
|
|
|
var elements = document.getElementsByClassName("header");
|
|
|
|
var elements = document.getElementsByClassName("header");
|
|
|
|
Array.prototype.forEach.call(elements, function(el) {
|
|
|
|
Array.prototype.forEach.call(elements, function (el) {
|
|
|
|
if (window.pageYOffset >= el.offsetTop) {
|
|
|
|
if (window.pageYOffset >= el.offsetTop) {
|
|
|
|
id = el;
|
|
|
|
id = el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) {
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
|
|
|
el.classList.remove("active");
|
|
|
|
el.classList.remove("active");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function(el) {
|
|
|
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
|
|
|
|
|
|
|
if (id == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (id.href.localeCompare(el.href) == 0) {
|
|
|
|
if (id.href.localeCompare(el.href) == 0) {
|
|
|
|
el.classList.add("active");
|
|
|
|
el.classList.add("active");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Populate sidebar on load
|
|
|
|
var pagetoc = document.getElementsByClassName("pagetoc")[0];
|
|
|
|
window.addEventListener('load', function() {
|
|
|
|
var elements = document.getElementsByClassName("header");
|
|
|
|
var pagetoc = document.getElementsByClassName("pagetoc")[0];
|
|
|
|
Array.prototype.forEach.call(elements, function (el) {
|
|
|
|
var elements = document.getElementsByClassName("header");
|
|
|
|
var link = document.createElement("a");
|
|
|
|
Array.prototype.forEach.call(elements, function(el) {
|
|
|
|
|
|
|
|
var link = document.createElement("a");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Indent shows hierarchy
|
|
|
|
// Indent shows hierarchy
|
|
|
|
var indent = "";
|
|
|
|
var indent = "";
|
|
|
|
switch (el.parentElement.tagName) {
|
|
|
|
switch (el.parentElement.tagName) {
|
|
|
|
case "H1":
|
|
|
|
case "H1":
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
// case "H2":
|
|
|
|
case "H3":
|
|
|
|
// indent = "20px";
|
|
|
|
indent = "20px";
|
|
|
|
// break;
|
|
|
|
break;
|
|
|
|
case "H3":
|
|
|
|
case "H4":
|
|
|
|
indent = "20px";
|
|
|
|
indent = "40px";
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "H4":
|
|
|
|
default:
|
|
|
|
indent = "40px";
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
link.appendChild(document.createTextNode(el.text));
|
|
|
|
link.appendChild(document.createTextNode(el.text));
|
|
|
|
link.style.paddingLeft = indent;
|
|
|
|
link.style.paddingLeft = indent;
|
|
|
|
link.href = el.href;
|
|
|
|
link.href = el.href;
|
|
|
|
pagetoc.appendChild(link);
|
|
|
|
pagetoc.appendChild(link);
|
|
|
|
});
|
|
|
|
|
|
|
|
updateFunction.call();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
updateFunction.call();
|
|
|
|
|
|
|
|
|
|
|
|
// Handle active elements on scroll
|
|
|
|
// Handle active elements on scroll
|
|
|
|
window.addEventListener("scroll", updateFunction);
|
|
|
|
window.addEventListener("scroll", updateFunction);
|
|
|
|
|
|
|
|
|
|
|
|
var p = path.replace("index.html", "");
|
|
|
|
pagePath = pagePath.replace("index.md", "");
|
|
|
|
p = p.replace(".html", "");
|
|
|
|
pagePath = pagePath.replace(".md", "");
|
|
|
|
var strs = p.split("/");
|
|
|
|
if (pagePath.length > 0) {
|
|
|
|
if (strs[strs.length-1] == ""){
|
|
|
|
if (pagePath.charAt(pagePath.length-1) == "/"){
|
|
|
|
strs.pop()
|
|
|
|
pagePath = pagePath.substring(0, pagePath.length-1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
pagePath = "index"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var str = strs[strs.length-1];
|
|
|
|
|
|
|
|
var title = document.querySelector("main>h1,h2>a").textContent
|
|
|
|
// 选取浏览器默认使用的语言
|
|
|
|
var gitalk = new Gitalk({
|
|
|
|
const lang = navigator.language || navigator.userLanguage
|
|
|
|
clientID: '07ea0357feefeb9de502',
|
|
|
|
|
|
|
|
clientSecret: '2f362f6990633ad63f7455b06fc00f4e45c5847d',
|
|
|
|
// 若当前 mdbook 主题为 Light 或 Rust ,则将 giscuz 主题设置为 light
|
|
|
|
repo: 'rust-course-comments',
|
|
|
|
var theme = "transparent_dark";
|
|
|
|
owner: 'sunface',
|
|
|
|
const themeClass = document.getElementsByTagName("html")[0].className;
|
|
|
|
admin: ["sunface"],
|
|
|
|
if (themeClass.indexOf("light") != -1 || themeClass.indexOf("rust") != -1) {
|
|
|
|
labels: ['comments'],
|
|
|
|
theme = "light"
|
|
|
|
title: title,
|
|
|
|
}
|
|
|
|
createIssueManually: false,
|
|
|
|
|
|
|
|
id: str,
|
|
|
|
var script = document.createElement("script")
|
|
|
|
distractionFreeMode: true
|
|
|
|
script.type = "text/javascript";
|
|
|
|
});
|
|
|
|
script.src = "https://giscus.app/client.js";
|
|
|
|
gitalk.render('gitalk-container');
|
|
|
|
script.async = true;
|
|
|
|
})();
|
|
|
|
script.crossOrigin = "anonymous";
|
|
|
|
|
|
|
|
script.setAttribute("data-repo", "sunface/rust-course");
|
|
|
|
|
|
|
|
script.setAttribute("data-repo-id", "MDEwOlJlcG9zaXRvcnkxNDM4MjIwNjk=");
|
|
|
|
|
|
|
|
script.setAttribute("data-category", "章节评论区");
|
|
|
|
|
|
|
|
script.setAttribute("data-category-id", "DIC_kwDOCJKM9c4COQcP");
|
|
|
|
|
|
|
|
script.setAttribute("data-mapping", "specific");
|
|
|
|
|
|
|
|
script.setAttribute("data-term", pagePath);
|
|
|
|
|
|
|
|
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-lang", lang);
|
|
|
|
|
|
|
|
script.setAttribute("data-loading", "lazy");
|
|
|
|
|
|
|
|
document.getElementById("giscus-container").appendChild(script);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('load', initAll);
|