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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
<!-- ............自定义尾部代码开始............ -->
<div id="post-bottom-bar" class="post-bottom-bar">
<div class="bottom-bar-inner">
<!-- 左边 -->
<div class="bottom-bar-items social-share" style="float: left;">
<span class="bottom-bar-item bottom-bar-facebook">
<a id="bottom-d" href="javascript:void(0)" target="_blank">点赞</a>
</span>
<span class="bottom-bar-item bottom-bar-twitter">
<a id="bottom-g" href="javascript:void(0)"" target="_blank">关注</a>
</span>
<span class="bottom-bar-item bottom-bar-qrcode">
<a id="bottom-s" href="javascript:void(0)" target="_blank">收藏</a>
</span>
</div>
<!-- 右边 -->
<div class="bottom-bar-items right" style="float: right;">
<span class="bottom-bar-item"><a id="mbottom-left" href="javascript:void(0);">←</a></span>
<span class="bottom-bar-item"><a id="mbottom-right" href="javascript:void(0);">→</a></span>
<span class="bottom-bar-item"><a href="#mfooter">↓</a></span>
<span class="bottom-bar-item"><a href="#mtop">↑</a></span>
</div>
</div>
</div>
<a name="mfooter"></a>
<!-- ............自定义尾部代码结束............ -->
<script type="text/javascript" src="https://unpkg.com/nprogress@0.2.0/nprogress.js"></script>
<script type="text/javascript">
//设置title
var tt = document.title;
tt = tt.replace("Ethan_Zhou - 博客园", "Blog-E");
document.title = tt;
/**
用来设置初始时需要执行的js
*/
$(document).ready(function(){
//加载顶部进度条
NProgress.start();
NProgress.done();
$("#myProgressBar").hide();
//设置背景图片地址
if ($("#head_bg_img").val()!=null && $("#head_bg_img").val()!="") {
$("#myheader_bg").css("background-image","url("+$("#head_bg_img").val()+")");
}else{
$("#myheader_bg").css("background-image","url(https://i.loli.net/2019/01/31/5c52e73546215.jpg)");
}
//标题
$("#mypost_title_h").html($("#cb_post_title_url").html());
//正文和标题淡入
$("#mainContent").css("opacity","1");
$("#mainContent").css("margin-top","0");
$("#mypost_title").css("opacity","1");
//更改iocn图标
var linkObject = document.createElement("link");
linkObject.rel = "shortcut icon";
linkObject.href = "https://i.loli.net/2019/01/31/5c52e907bfa56.png";
document.getElementsByTagName("head")[0].appendChild(linkObject);
})
/**
设置ajax请求加载完所有数据时执行的js
*/
setTimeout(afterAjax,1000);
function afterAjax(){
//假如不是首页
var now_url = window.location.href.toLowerCase();
if (now_url.indexOf("bloge/p/")>=0) {
//获取文章标签
var tag = null;
if ($("#EntryTag").html()!=null && $("#EntryTag").html()!= "") {
tag = $("#EntryTag").html();
tag = tag.substring(3,tag.length);
}else{
tag = "<a href='https://cnblogs.com/BlogE'>暂无标签</a>";
}
//获取文章分类
var classification = null;
if ($("#BlogPostCategory").html()!=null && $("#BlogPostCategory").html()!= "") {
classification = $("#BlogPostCategory").html();
classification = classification.substring(3,classification.length);
}else{
classification = "<a href='https://cnblogs.com/BlogE'>暂未分类</a>";
}
var ftitle = "Published on "+ $("#post-date").html() + " in " + classification
+ " with <a href='https://cnblogs.com/BlogE'>Blog-E</a>";
//设置副标题标题
$("#mypost_title_f").html(ftitle);
//设置标题标签按钮
$("#mypost_title_e").html(tag.replace(",",""));
//设置底部导航条上一篇下一篇文章
var pnp = $("#post_next_prev a");
$("#mbottom-left").attr("href",pnp[1].href);
if (pnp.length>2) {
$("#mbottom-right").attr("href",pnp[3].href);
}
}
$("#myheader_bg").css("filter","blur(0px)");
}
/**
自定义的js方法
*/
//设置底部导航条点击事件
$("#bottom-g").click(function(){
follow('5dfde587-1816-e711-845c-ac853d9f53ac');
})
$("#bottom-s").click(function(){
AddToWz(cb_entryId);return false;
})
var now_url = window.location.href.toLowerCase();
if (now_url.indexOf("bloge/p/")==-1 && now_url.indexOf("bloge/diary/")==-1){
$("#bottom-s").hide();
$("#bottom-d").html("友链");
$("#bottom-d").attr("href","https://www.cnblogs.com/BlogE/p/links.html");
//分离博文
var allday = $(".day");
allday.each(function() {
var nowday = $(this);
var post = $("<div id='posts'></div>");
nowday.children().each(function() {
if ($(this).attr("id") != "posts") {
if($(this).attr("class") == "postCon"){
var pic=$(this).find("img");
if(pic.length==1 && pic.hasClass("on")){
var postimg=$("<div class='post-img'></div>");
postimg.css("background-image","url("+pic.attr("src")+")");
post.prepend(postimg);
post.css("padding-top","0");
pic.hide();
}
}
post.append($(this));
}
if ($(this).attr("class") == "postDesc") {
$(".forFlow").append(post);
post = $("<div id='posts'></div>");
}
})
})
allday.remove();
$(".forFlow").append($(".topicListFooter[id!=homepage_top_pager]"));
}else{
var url = window.location.href;
var lastUrl = url.substring(url.lastIndexOf("/")+1);
var mpageId = lastUrl.substring(0,lastUrl.indexOf("."));
$("#bottom-d").click(function(){
DiggIt(mpageId,cb_blogId,1);
green_channel_success(this,'谢谢推荐!');
})
}
//通过滚动条控制导航条的展现隐藏
var oldScrollNum = 0;
window.onscroll = function(){
var t = document.documentElement.scrollTop || document.body.scrollTop;
//下滑
if (t>oldScrollNum) {
if (t>120) {
$("#mynavbar").css("margin-top","-70px");//顶部导航
$("#post-bottom-bar").css("bottom","-3pc");//底部导航
$(".forkme").fadeOut();
if(document.body.clientWidth<1000){
$("#mynavbar_menu").slideUp();
var ON_CLASS_NAME = 'site-nav-on';
$(".site-nav-toggle").removeClass(ON_CLASS_NAME);
}
}
if (t>300) {
$("#right_meun").css("display","inline-block");//右侧导航
}
//上拉
}else{
//防止用a链接跳转也触发效果
if (oldScrollNum-t<20) {
$("#mynavbar").css("margin-top","0px");//顶部导航
$("#post-bottom-bar").css("bottom","0");//底部导航
if(document.body.clientWidth>=1000)
$(".forkme").fadeIn();
}
if (t<=300) {
$("#right_meun").css("display","none");//右侧导航
}
}
oldScrollNum = t;
}
//移动端菜单收缩/展开
$(".site-nav-toggle").click(function() {
var ON_CLASS_NAME = 'site-nav-on';
if ($(this).hasClass(ON_CLASS_NAME)) {
$("#mynavbar_menu").slideUp();
$(this).removeClass(ON_CLASS_NAME);
} else {
$("#mynavbar_menu").slideDown();
$(this).addClass(ON_CLASS_NAME);
}
})
//背景大图点击模糊||清晰
$("#myheader_cover").click(function(){
if ($("#myheader_bg").css("filter") == "blur(3px)") {
$("#myheader_bg").css("filter","blur(0px)");
}else{
$("#myheader_bg").css("filter","blur(3px)");
}
})
</script>
<script type="text/javascript">
var setMyBlog = {
setCopyright: function() {
//设置版权信息,转载出处自动根据页面url生成
var info_str = '<p>作者:<a target="_blank">@ethan_zhou</a><br>'+
'本文为作者原创,转载请注明出处:<a class="uri"></a></p><hr></hr>';
info = $(info_str);
info_a = info.find("a");
url = window.location.href;
if (url.indexOf("#") >= 0)
url = url.slice(0, url.indexOf("#"));
$(info_a[0]).attr("href","https://github.com/ethan-enhe");
$(info_a[1]).attr("href",url).text(url);
$("#cnblogs_post_body").prepend(info);
},
setCodeRow: function(){
// 代码行号显示
$("pre code").each(function(){
$(this).html("<ol><li>" + $(this).html().replace(/\n/g,"\n</li><li>") +"\n</li></ol>");
});
},
setAtarget: function() {
// 博客内的链接在新窗口打开
$("#cnblogs_post_body a").each(function(){
this.target = "_blank";
})
},
setContent: function() {
// 根据h2、h3标签自动生成目录
var captions_ori = $("#cnblogs_post_body h2"),
captions_ori2 = $("#cnblogs_post_body h3"),
captions = $("#cnblogs_post_body h2,#cnblogs_post_body h3").clone(),
content = $("<ul id='right_meun'></ul>");
$("#cnblogs_post_body").prepend(content.append(captions));
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><ul></ul></li>';
} else {
// add by BlogE 增加h3链接跳转
index2 += 1;
$('<a name="' + '_caption' + index2 + '"></a>').insertBefore(captions_ori2[index2]);
$("#"+index+"li ul").append("<li><a href='#_caption" + index2 + "' style='color:#5f5f5f;'>" +self.innerHTML+"</a></li>");
return ;
}
});
},
setSearch: function() {
var search = document.createElement('div');
search.innerHTML="<input type=\"text\" id=\"q\" onkeydown=\"return zzk_go_enter(event);\" class=\"input_my_zzk\"> <input onclick=\"zzk_go()\" type=\"button\" value=\"找找看\" id=\"btnZzk\" class=\"btn_my_zzk\">";
search.setAttribute('id','searchblogpost');
document.getElementById("mynavbar_menu").appendChild(search);
},
runAll: function() {
/* 运行所有方法
* setAtarget() 博客园内标签新窗口打开
* setContent() 设置目录(仅在窗口够大时)
* setCopyright() 设置版权信息
* setSearch() 开启站内搜
* setCodeRow() 代码行号显示
*/
this.setAtarget();
this.setContent();
this.setCopyright();
//this.setSearch();
this.setCodeRow();
}
}
setMyBlog.runAll();
</script>
|