-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathfoot.html
executable file
·254 lines (244 loc) · 9.95 KB
/
foot.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<script>
/**
* @author:[email protected]
* @version:2020-07-01
*/
window.config = {
avatar: 'https://pic.cnblogs.com/face/2002946/20200629092428.png',
github: 'makergyt',
gallery: '1796566'
}
</script>
<!-- 下方内容请勿擅自修改,除非知道明确含义,如进行完善和扩展,请fork源码(https://github.com/MakerGYT/cnblogs-theme-next)后提交pull request;-->
<!-- 引入在线字体-->
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Noto Serif SC:wght@400;500;700&display=swap&subset=latin,latin-ext">
<!-- 引入图标库-->
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- 更改高亮样式-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/styles/github.min.css" rel="stylesheet">
<!-- 顶部滚动条-->
<script src="https://cdn.jsdelivr.net/gh/djyde/ToProgress/ToProgress.min.js"></script>
<script type="text/javascript">
let progressBar = new ToProgress({
color: getComputedStyle(document.documentElement).getPropertyValue('--primary-color')
})
progressBar.reset()
// 如未做大幅修改,请保留下方内容
$('#poweredby').append(' & <a href="https://github.com/makergyt/cnblogs-theme-next">cnblogs-theme-next</a>')
// 获取默认基础信息
window.isPost = $('.forFlow').find('#post_detail').length ? true : false;
window.blogSlug = currentBlogApp;
var footerOverTestArray = $($("#footer")[0].childNodes[2]).text().trim().split(" ");
config = Object.assign({
siteTitle: $('#Header1_HeaderTitle').text(),
author: footerOverTestArray[footerOverTestArray.length - 1],
avatar: $('.author_avatar').attr('src'),
github: blogSlug,
gallery: null
}, config);
var linkObject = document.createElement("link");
linkObject.rel = "shortcut icon";
linkObject.href = config.avatar;
// 设置摘要
function setDesc() {
$('#cnblogs_post_description').css('display', 'block')
$('#cnblogs_post_description').prepend('<h3 id="post-description-meta">摘 要</h3>')
// 由于标签是网络请求,可能在修改dom后返回,故重新请求后再修改
$.ajax({
url: getAjaxBaseUrl() + "CategoriesTags.aspx",
type: "get",
contentType: "application/json; charset=utf-8",
data: {
blogId: cb_blogId,
postId: cb_entryId,
},
cache: !1,
dataType: "text",
timeout: 1e4,
success: function (n) {
n && $("#cnblogs_post_description").append(n.replace('EntryTag', 'post-keyword').replace('标签', '关键词'))
$('#EntryTag').remove()
}
})
}
// 设置参考文献标题
function setFoot() {
$('.footnotes').prepend('<h2 id="-参考文献" class="footnotes-meta">参 考 文 献</h2>')
}
// 设置左侧目录
function setContent() {
if ($('#post-toc-wrap').length) return;
var toc = $('<div id="post-toc-wrap"><h3 style="text-align:center">目录</h3></div>')
$('#blog-news').prepend(toc)
var captions_ori = $("#cnblogs_post_body h2"),
captions_ori2 = $("#cnblogs_post_body h3"),
captions = $("#cnblogs_post_body h2,#cnblogs_post_body h3").clone(),
content = $("<ol id='post-toc'></ol>");
toc.append(content.append(captions));
toc.append('<div class="back-to-top" onclick="toScroll(0,500)"><i class="fa fa-arrow-up"></i> <span id="btc-persent">0%</span></div>')
var index = -1, index2 = -1;
captions.replaceWith(function () {
var self = this;
if (self.tagName == "H2" || self.tagName == "h2") {
// 设置点击目录跳转
index += 1;
$('<a name="' + '_caption_' + index + '"></a>').insertBefore(captions_ori[index]);
return '<li id="' + index + 'li"><a href="#_caption_' + index + '">' + self.innerHTML + '</a><ol></ol></li>';
} else {
index2 += 1;
$('<a name="' + '_caption' + index2 + '"></a>').insertBefore(captions_ori2[index2]);
$("#" + index + "li ol").append("<li><a href='#_caption" + index2 + "' style='color:#5f5f5f;'>" + self.innerHTML + "</a></li>");
return;
}
});
}
// 滚动至顶部
function toScroll(endScroll, time) {
$('html,body').stop().animate({ scrollTop: endScroll }, time);
}
function onScroll() {
// 上拉至指定位置贴顶
var oldScrollNum = 0;
window.onscroll = function () {
var t = document.documentElement.scrollTop || document.body.scrollTop;
if (t > oldScrollNum) {
if (t > 135) {
$('.site-author').remove()
$('#sidebar_categories').hide()
setContent()
}
if (t > 270) {
$("#post-toc-wrap").addClass("affix");
}
} else {
if (t <= 135) {
$('#post-toc-wrap').remove()
$('#sidebar_categories').show()
setAuthor()
}
if (t <= 270) {
$("#post-toc-wrap").removeClass("affix");
}
}
oldScrollNum = t;
// 滚动条
var docHeight = $(document).height(),
windowHeight = $(window).height(),
scrollPercent = (t / (docHeight - windowHeight)) * 100;
progressBar.setProgress(scrollPercent);
$('#btc-persent').replaceWith('<span id="btc-persent">' + scrollPercent.toFixed() + '%</span>')
}
}
function setAuthor() {
if ($('.site-author').length) return;
var siteAuthor = $('<div class="site-author motion-element"><img class="site-author-image" src="' + config.avatar + '"><p class="site-author-name">' + config.author + '</p></div>');
siteAuthor.append('<div class="site-state">' + $('.blogStats').html() + '</div>')
var links = $('<div class="links-of-author"></div>')
links.append('<div class="links-of-author-item"><a href="https://msg.cnblogs.com/send/'+ config.author+'"><i class="fa fa-fw fa-envelope"></i></a></div>'
+'<div class="links-of-author-item"><a id="blog_nav_rss" href="https://www.cnblogs.com/'+blogSlug+'/rss/" data-rss="https://www.cnblogs.com/'+blogSlug+'/rss/" style="display: inline !important;"><i class="fa fa-fw fa-rss"></i></a></div>')
$('#blog-news').prepend(siteAuthor.append(links))
}
// 设置导航区
function setNav() {
var url = window.location.href;
$('.brand').attr('href', '/' + blogSlug)
$('.site-title').text(config.siteTitle)
$('.menu-item-home a:first').attr('href', '/' + blogSlug)
$('.menu-item-archives a:first').attr('href', '/' + blogSlug+'/p')
if(config.gallery) {
$('.menu-item-gallery a:first').attr('href', '/' + blogSlug+'/gallery/'+config.gallery+'.html')
$('.menu-item-gallery').css('display','block')
if(/gallery/.test(url)){
$('.menu-item-home').removeClass('menu-item-active')
$('.menu-item-gallery').addClass('menu-item-active')
}
}
if(/(\/p)$/.test(url)) {
$('.menu-item-home').removeClass('menu-item-active')
$('.menu-item-archives').addClass('menu-item-active')
}
}
// 设置右上角github跳转链接
function setGithub() {
$('.github-corner').attr('href', 'https://github.com/' + config.github)
}
// 在响应式设计中,菜单折叠打开事件
function setToggle() {
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', () => {
event.currentTarget.classList.toggle('toggle-close');
var e = document.querySelector('.site-nav'),
t = e.classList.contains('site-nav-on') ? 'slideUp' : 'slideDown';
'function' == typeof Velocity ? Velocity(e, t, {
duration: 200,
complete: function () {
e.classList.toggle('site-nav-on')
}
}) : e.classList.toggle('site-nav-on')
});
}
function setCommentStyle() {
let t = $(".feedbackItem");
if (t.length > 0) {
$.each(t, function (t) {
let e = $(this)
, n = e.find(".feedbackCon")
, o = e.find(".feedbackListSubtitle")
, i = n.length ? n.find(".blog_comment_body") : []
, s = ""
, a = i.length ? i.attr("id").split("_") : void 0;
if (a && a.length > 0) {
let t = a[a.length - 1]
, n = t.toString().match(/[0-9]/g);
$.isArray(n) && (t = n.join(""));
let o = $("#comment_" + t + "_avatar")
, i = o.length > 0 ? $.trim(o.text()) : "https://cdn.jsdelivr.net/gh/BNDong/Cnblogs-Theme-SimpleMemory@master/img/webp/default_avatar.webp"
, l = $("#a_comment_author_" + t)
, c = l.length ? l.attr("href") : "javascropt:void(0);";
s = '<div class="feedbackAvatar"><a href="' + c + '" target="_blank"><img src="' + i + '"/></a></div>',
e.prepend(s)
}
o.length && o.find(".louzhu").length && o.addClass("feedbackListSubtitle-louzhu")
})
}
}
function setPreNext() {
var pnp = $("#post_next_prev a");
if(!pnp.length) return;
var cont = $('#post_next_prev').text();
var wrapper = $('<div class="post_next_prev"><div class="pre-block"></div><div class="next-block"></div></div>')
$("#post_next_prev").replaceWith(wrapper)
var pre = $('<a href="'+pnp[1].href+'"><div class="post_next_prev_label">◄上一篇</div><div>'+pnp[1].innerText+'</div></a>')
if(pnp.length>2){
$('.pre-block').append(pre)
var next = $('<a href="'+pnp[3].href+'"><div class="post_next_prev_label">下一篇►</div><div>'+pnp[3].innerText+'</div></a>')
$('.next-block').append(next)
} else {
if(/上一篇/.test(cont)) {
$('.pre-block').append(pre)
} else if(/下一篇/.test(cont)) {
var next = $('<a href="'+pnp[1].href+'"><div class="post_next_prev_label">下一篇►</div><div>'+pnp[1].innerText+'</div></a>')
$('.next-block').append(next)
}
}
}
setGithub();
setToggle();
setNav();
setTimeout(() => {
setAuthor();
}, 500);
// 只对文章页
if (isPost) {
setFoot();
// 由于加载需要时间故增加延时后操作
setTimeout(() => {
setDesc();
setPreNext();
onScroll();
}, 500);
setTimeout( () => {
setCommentStyle()
}, 1000)
}
</script>