mirror of https://github.com/IoTcat/ushio-img.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
4.7 KiB
161 lines
4.7 KiB
4 years ago
|
/* ----
|
||
|
|
||
|
# Single Theme
|
||
|
# By: Dreamer-Paul
|
||
|
# Last Update: 2019.3.2
|
||
|
|
||
|
一个简洁大气,含夜间模式的 Typecho 博客模板。
|
||
|
|
||
|
本代码为奇趣保罗原创,并遵守 MIT 开源协议。欢迎访问我的博客:https://paugram.com
|
||
|
|
||
|
---- */
|
||
|
|
||
|
var Paul_Single = function (config) {
|
||
|
var that = this;
|
||
|
var body = document.body;
|
||
|
var content = ks.select(".post-content") || ks.select(".page-content");
|
||
|
|
||
|
// 菜单按钮
|
||
|
this.header = function () {
|
||
|
var menu = document.getElementsByClassName("head-menu")[0];
|
||
|
|
||
|
ks.select(".toggle-btn").onclick = function () {
|
||
|
menu.classList.toggle("active");
|
||
|
};
|
||
|
|
||
|
ks.select(".light-btn").onclick = this.night;
|
||
|
|
||
|
var search = document.getElementsByClassName("search-btn")[0];
|
||
|
var bar = document.getElementsByClassName("head-search")[0];
|
||
|
|
||
|
search.addEventListener("click", function () {
|
||
|
bar.classList.toggle("active");
|
||
|
})
|
||
|
};
|
||
|
|
||
|
// 关灯切换
|
||
|
this.night = function () {
|
||
|
if(body.classList.contains("neon")){
|
||
|
body.classList.remove("neon");
|
||
|
document.cookie = "night=false;" + "path=/;" + "max-age=21600";
|
||
|
}
|
||
|
else{
|
||
|
body.classList.add("neon");
|
||
|
document.cookie = "night=true;" + "path=/;" + "max-age=21600";
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// 目录树
|
||
|
this.tree = function () {
|
||
|
var id = 1;
|
||
|
var wrap = ks.select(".wrap");
|
||
|
var headings = content.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
||
|
|
||
|
if(headings.length > 0){
|
||
|
body.classList.add("has-trees");
|
||
|
|
||
|
var trees = ks.create("section", {
|
||
|
class: "article-list",
|
||
|
html: "<h4><span class=\"title auto-border\">目录</span></h4>"
|
||
|
});
|
||
|
|
||
|
ks.forEach(headings, function (t) {
|
||
|
var cls, text = t.innerText;
|
||
|
|
||
|
t.id = "title-" + id;
|
||
|
|
||
|
switch (t.tagName){
|
||
|
case "H2": cls = "item-2"; break;
|
||
|
case "H3": cls = "item-3"; break;
|
||
|
case "H4": cls = "item-4"; break;
|
||
|
case "H5": cls = "item-5"; break;
|
||
|
case "H6": cls = "item-6"; break;
|
||
|
}
|
||
|
|
||
|
trees.appendChild(ks.create("a", {class: cls, text: text, href: "#title-" + id}));
|
||
|
|
||
|
id++;
|
||
|
});
|
||
|
|
||
|
wrap.appendChild(trees);
|
||
|
|
||
|
function toggle_tree() {
|
||
|
var buttons = ks.select("footer .buttons");
|
||
|
var btn = ks.create("a", {class: "toggle-list"});
|
||
|
buttons.appendChild(btn);
|
||
|
|
||
|
btn.addEventListener("click", function () {
|
||
|
trees.classList.toggle("active");
|
||
|
})
|
||
|
}
|
||
|
toggle_tree();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// 自动添加外链
|
||
|
this.links = function () {
|
||
|
if(content.getElementsByTagName("a")){
|
||
|
ks.forEach(content, function (t) {
|
||
|
t.target = "_blank";
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
this.comment_list = function () {
|
||
|
ks.forEach(ks.selectAll(".comment-content a"), function(t){
|
||
|
var item = ks.select(t.getAttribute("href"));
|
||
|
|
||
|
t.onmouseover = function () {
|
||
|
item.classList.add("active");
|
||
|
};
|
||
|
|
||
|
t.onmouseout = function () {
|
||
|
item.classList.remove("active");
|
||
|
};
|
||
|
})
|
||
|
};
|
||
|
|
||
|
// 返回页首
|
||
|
this.to_top = function () {
|
||
|
var btn = document.getElementsByClassName("to-top")[0];
|
||
|
var scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
|
||
|
|
||
|
scroll >= window.innerHeight / 2 ? btn.classList.add("active") : btn.classList.remove("active");
|
||
|
};
|
||
|
|
||
|
this.header();
|
||
|
|
||
|
if(content){
|
||
|
this.tree();
|
||
|
this.links();
|
||
|
this.comment_list();
|
||
|
}
|
||
|
|
||
|
// 返回页首
|
||
|
window.addEventListener("scroll", this.to_top);
|
||
|
|
||
|
// 如果开启自动夜间模式
|
||
|
if(config.toggleNight){
|
||
|
var hour = new Date().getHours();
|
||
|
|
||
|
if(document.cookie.search(/night/) === -1 && (hour <= 5 || hour >= 22)){
|
||
|
document.body.classList.add("neon");
|
||
|
document.cookie = "night=true;" + "path=/;" + "max-age=21600";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 如果开启复制内容提示
|
||
|
if(config.copyNotice){
|
||
|
document.oncopy = function () {
|
||
|
ks.notice("复制内容请注明来源并保留版权信息!", {color: "yellow", overlay: true})
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// 图片缩放
|
||
|
ks.image(".post-content img, .page-content img");
|
||
|
|
||
|
// 请保留版权说明
|
||
|
if (window.console && window.console.log) {
|
||
|
console.log("%c Single %c https://paugram.com ","color: #fff; margin: 1em 0; padding: 5px 0; background: #ffa628;","margin: 1em 0; padding: 5px 0; background: #efefef;");
|
||
|
}
|