部落格園細節美化,打磨
原作者
感謝 @Summertime-Wu 巨佬寫出這樣漂亮簡潔的主題,本蒟蒻是在原主題的基礎上改的。
原主題地址:https://www.cnblogs.com/summertime-wu/p/9356736.html。
本人新手,如有可改進之處,歡迎指出
優化
新增 fork me on github 角標,節省選單空間
在頁首程式碼中添加了以下內容:
<div class="forkme"> <a href="https://github.com/ethan-enhe"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://i.loli.net/2019/02/03/5c56804b26dd9.png" alt="Fork me on GitHub"></a> </div>
然後在 css 中把這個 div 的 width 和 height 調成了 149px,z-index 調成了 999。
又在頁尾程式碼中註釋 “通過滾動條控制導航條的展現隱藏” 的後面添加了 $(".forkme").fadeOut()/fadeIn();
。完結撒花!
選單移動端自適應
在移動端把選單摺疊成≡
的樣式,說來話長,可以直接見程式碼(模仿hexo的next主題)。
標題高度自適應(避免標題太長導致被正文擋住)
#mypost_title {
position: absolute;
bottom: 0px;
}
新增評論功能,美化文字框
去除原來評論區域的cssdisplay: none
div.commentform input.author { background-color: #ffba4d; width: 150px; border-radius: 8px; } div.commentform textarea.comment_textarea { border-radius: 5px; } input[type=button] { width: 80px; height: 30px; border-width: 0px; border-radius: 200px; background: #1E90FF; cursor: pointer; outline: none; font-family: Microsoft YaHei; color: white; }
修改不能識別主頁的 bug(比如說把 BlogE 寫成 bLoGe,或者點選回到頂端按鈕之後重新整理頁面等等)
由於部落格園部落格主頁可以由多種方式訪問,http/https,甚至你的自定義域名都不用區分大小寫!
舉個栗子:https://www.cnblogs.com/BlogE 與 https://www.cnblogs.com/bLoGe 都可以訪問我的部落格主頁。
那麼這時你就需要一個一個的特判,在if的括號裡寫64個條件!
正難則反,其實我們只需確認網址不包括/p/
即可!
var now_url = window.location.href.toLowerCase();
if (now_url.indexOf("bloge/p/")>=0) {
blablabla...
}
在主頁隱藏收藏文章按鈕
如題,閒的沒事就在判斷主頁的if裡面給收藏圖示來了個hide()
在文章頁面顯示文章的 tags
原作者在文章頁面把文章分類顯示了兩遍,我作為一名強迫症晚期患者,就改成了上面顯示分類,下面顯示文章tag。修改afterAjax()
這個函式:
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)");
}
修復原文地址顯示錯誤
有時在博文中點選完目錄跳轉之後再重新整理頁面,setCopyright()
函式生成的版權資訊會顯示(以這篇文章為例)https://www.cnblogs.com/BlogE/p/beautifycnblogs.html#_caption4
這樣的東西。然而我卻不想要他顯示url後面的#_caption4
這個玩意。何以解憂?唯有slice()
!於是我改寫了一下這個函式
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);
},
美化程式碼塊
使用highlight.js換了個程式碼主題,重寫了新增程式碼行號的函式(原理是給每行程式碼外邊套一個<ol>
和<li>
標籤,借鑑這篇文章),設定了程式碼不折行等等,同時模仿了這個網站的程式碼塊顏色樣式。
選單新增 Font Awesome 圖示
覺得選單沒有圖示略顯單調,於是引用了Font Awesome的css和js。如果你的部落格因此載入過慢,你可以刪掉掉頁首html中形如<i class="fas fa-xxxx"></i>
的東西,和註釋<!-- ............Font Awesome............ -->
後邊的內容。
細節美化
做了以下的移動端調整(下面程式碼不包含移動端摺疊選單的內容)
/*移動端*/
@media screen and (max-width: 1000px) {
.forkme {display: none;}
#searchblogpost {display: none !important;}
#mypost_title {left: 0%;}
#right_meun {display: none !important;}
#main {width: 80%;}
}
測試中功能
博文列表中顯示文章插圖
在文章的摘要中“插入右側圖片”時,如要顯示該圖片,只需為其加上一個“on”的class,比如:
<img src="https://github.com/liriliri/eruda/raw/master/doc/banner.jpg" class="desc_img on">
開啟站內搜尋
目前版本的程式碼預設不會顯示站內搜尋(效果不穩定),如果您想要嘗試這個功能,可以取消註釋this.setSearch
。歡迎在評論區中反饋使用中的出現的bug肯定不會出現bug。
最終程式碼及使用方法
主題選擇bluesky,然後把以下程式碼中我的使用者名稱和自定義域名等內容替換成你自己的,然後再把所有程式碼複製到部落格設定中對應的位置即可。
自定義css
.forkme {
position: fixed;
right: 0px;
top: 0px;
height: 149px;
width: 149px;
z-index: 999;
}
#sideBar{
display: none;
}
#mainContent{
width: 100%;
box-shadow: 0 0 0;
border-radius: 0px;
opacity: 0;
transition:0.5s;
margin-top:40px;
}
#main{
width: 45%;
background-color: white;
/*max-width: 700px;*/
}
body{
background-image: none;
background-color: white;
font-family: Menlo,Bitstream Vera Sans Mono,DejaVu Sans Mono,Monaco,Consolas,monospace !important;
line-height: 1.8;
}
#cnblogs_post_body{
font-size: 16px;
}
.c_b_p_desc_readmore {
display: -webkit-inline-box;
}
#taglist_title {
font-size: 22px;
}
#posts {
box-shadow: 0 0 5px #251a1a4f;
border-radius: 15px;
margin-bottom: 38px;
padding-top: 32px;
}
.post-img {
position: relative;
display: inherit;
min-height: 250px;
background-position: 50% 50%;
background-size: cover;
}
.dayTitle {
border: 1px solid #f5e305;
margin-top: 20px;
margin-left: 32px;
margin-right: 32px;
}
.postTitle {
margin-left: 32px;
margin-right: 32px;
}
#posts .postCon {
margin-left: 32px;
margin-right: 32px;
}
#green_channel{
display: none;
}
#post_next_prev{
display: none;
}
.post-img{
/*margin-top: 0;*/
border-top-left-radius: 15px;
border-top-right-radius: 15px;
}
#EntryTag {
display: none;
}
/** 去除廣告 */
#cb_post_title_url{
display: none;
}
#cnblogs_c1{
display: none;
}
#cnblogs_c2{
display: none;
}
#ad_t2{
display: none;
}
#kb_block{
display:none
}
#under_post_news{
display:none
}
#header{
display:none
}
#BlogPostCategory{
display: none;
}
#comment_nav{
display: none;
}
.postDesc {
border-bottom: none;
margin-left: 32px;
margin-right: 32px;
}
#author_profile_follow{
display: none;
}
/** 自定義樣式 */
/* 載入條 */
#myProgressBar{
width: 15%;
height: 2px;
background-color: #eb5055;
position: fixed;
top: 0;
left: 0;
z-index: 999;
}
#nprogress {
pointer-events: none;
}
#nprogress .bar {
background: #eb5055;
position: fixed;
z-index: 1031;
top: 0;
left: 0;
width: 100%;
height: 2px;
}
#nprogress .peg {
display: block;
position: absolute;
right: 0px;
width: 100px;
height: 100%;
box-shadow: 0 0 10px #eb5055, 0 0 5px #eb5055;
opacity: 1.0;
-webkit-transform: rotate(3deg) translate(0px, -4px);
-ms-transform: rotate(3deg) translate(0px, -4px);
transform: rotate(3deg) translate(0px, -4px);
}
#nprogress .spinner {
display: block;
position: fixed;
z-index: 1031;
top: 15px;
right: 15px;
}
#nprogress .spinner-icon {
width: 18px;
height: 18px;
box-sizing: border-box;
border: solid 2px transparent;
border-top-color: #eb5055;
border-left-color: #eb5055;
border-radius: 50%;
-webkit-animation: nprogress-spinner 400ms linear infinite;
animation: nprogress-spinner 400ms linear infinite;
}
.nprogress-custom-parent {
overflow: hidden;
position: relative;
}
.nprogress-custom-parent #nprogress .spinner,
.nprogress-custom-parent #nprogress .bar {
position: absolute;
}
@-webkit-keyframes nprogress-spinner {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes nprogress-spinner {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/** 導航欄 */
#mynavbar{
width: 100%;
height: 70px;
position: fixed;
display: block;
top: 0px;
z-index: 100;
background-color: white;
transition:0.5s ease-in-out;
box-shadow: 0 1px 5px rgba(0,0,0,.1);
}
#mynavbar_menu{
display: inline-block;
width: auto;
position: fixed;
right: 13%;
/* float: right; */
text-align: right;
line-height: 68px;
}
#mynavbar_menu a{
padding: 0 10px;
font-size: 14px;
outline: 0;
color: #313131bd !important;
font-weight: 900;
text-decoration: none;
}
#mynavbar_menu a:hover{
color: #eb5055 !important;
}
#searchblogpost {
display: inline-block;
}
/** 頭部 */
#myheader{
background-color: #75b7ef!important;
margin-top:70px;
position: relative;
width: 100%;
height: 300px;
}
#myheader_bg{
width:100%;
height:300px;
background-position: center;
background-size: cover;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
filter: blur(3px);
position: absolute;
}
#myheader_cover{
position: relative;
margin-top: 70px;
width: 100%;
height: 300px;
background-color: rgba(0, 0, 0, 0.25);
}
#mypost_title{
position: absolute;
bottom: 0px;
left: 20%;
padding: 30px 25px 20px;
max-width: 700px;
color: white;
transition:0.5s;
opacity: 0;
}
#mypost_title_e{
margin: 0;
padding: 5px 0 15px;
}
#mypost_title_e a{
border: 1px solid #6fa3ef;
border-radius: 15px;
background: #6fa3ef;
color: #fff;display: inline-block;
margin: 4px 8px 0 0;
padding: 0 15px;
letter-spacing: 0;
font-weight: 600;
font-size: 13px;outline: 0;text-decoration: none;
transition: 0.5s;
}
#mypost_title_e a:nth-child(1n) {
color: #fff;
border: 1px solid #6fa3ef;
border-radius: 15px;
background: #6fa3ef;
}
#mypost_title_e a:nth-child(2n) {
color: #fff;
border: 1px solid #ff9800;
border-radius: 15px;
background: #ff9800
}
#mypost_title_e a:nth-child(3n) {
color: #fff;
border: 1px solid #46c47c;
border-radius: 15px;
background: #46c47c
}
#mypost_title_e a:nth-child(4n) {
color: #fff;
border: 1px solid #f9bb3c;
border-radius: 15px;
background: #f9bb3c
}
#mypost_title_e a:nth-child(5n) {
color: #fff;
border: 1px solid #bc99c4;
border-radius: 15px;
background: #bc99c4
}
#mypost_title_e a:nth-child(6n) {
color: #fff;
border: 1px solid #e8583d;
border-radius: 15px;
background: #e8583d
}
#mypost_title_e a:before{
content: "# "
}
#mypost_title_e a:hover{
background-color: white;
border: 1px solid white;
color:black;
}
#mypost_title_f a{
color: white;
}
#mypost_title_f a:hover{
text-decoration:none;
}
/** 右側導航 */
#right_meun{
position: fixed;
z-index: 2;
top: 100px;
left: 70%;
display: none;
text-align: left;
border-left: 1px solid #ddd;
font-size: 12px;
}
#right_meun li{
list-style: none!important;
}
#right_meun a{
display: inline-table;
margin-left: 5px;
white-space: nowrap;
text-decoration: none;
color: #313131 !important;
outline: 0;
border-bottom: 0 !important;
}
#right_meun a:hover{
color: #eb5055;
}
#right_meun>li::before {
position: relative;
top: 0;
left: -4px;
display: inline-block;
width: 7px;
height: 7px;
content: '';
border-radius: 50%;
background-color: #eb5055;
}
/* 底部導航 */
#post-bottom-bar{
position: fixed;
right: 0;
bottom: 0;
left: 0;
z-index: 2;
height: 3pc;
border-top: 1px solid #e0e0e0;
background-color: #fff;
margin: 0;
padding: 0;
transition: 0.5s ease-in-out;
}
#post-bottom-bar a{
text-decoration: none!important;
}
.post-bottom-bar .bottom-bar-inner{
margin: 0 auto;
padding: 0 10px;
max-width: 900px;
}
.bottom-bar-items{
margin: 0 0 0 10px;
color: #313131;
font-size: 14px !important;
line-height: 3pc;float: left;
}
.post-bottom-bar{
margin: 0 0 0 10px;
color: #313131;
font-size: 14px;
line-height: 3pc;
}
.post-bottom-bar .social-share .bottom-bar-item {
padding: 4px;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-facebook a {
background-color: #4267b2;
color: #fff;
}
.post-bottom-bar .social-share .bottom-bar-item a {
padding: 2px 10px;
border-radius: 15px;
}
.post-bottom-bar .bottom-bar-item a {
margin: 0;
padding: 9pt;
border: 0;
background: 0 0;
color: #313131;
font-size: 14px;
line-height: 3pc;
cursor: pointer;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-twitter a {
background-color: #1b95e0;
color: #fff;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-qrcode a {
background-color: #5f5f5f;
color: #fff;
}
.bottom-bar-item a:hover{
color: #eb5055;
}
/** MarkDown樣式調整 */
.cnblogs-markdown .hljs {
font-size: 16px!important;
padding: 15px!important;
border: 0 solid #3d7e9a !important;
border-left-width: 5px!important;
white-space: pre;
border-radius: 0px !important;
}
.cnblogs-markdown code {
background: #eee !important;
border: 0px !important;
color: #333 !important;
font-size: 16px!important;
}
code ol {
padding-left: 20px !important;
}
.cnblogs-markdown h2{
font-weight: 500;
margin: 20px 0;
}
.cnblogs-markdown h2:before{
content: "#";
color: #eb5055;
position: relative;
top: 0;
left: -12px;
}
#cnblogs_post_body h3{
font-size: 16px;
font-weight: bold;
line-height: 1.5;
margin: 10px 0;
}
.cnblogs-markdown h3:before{
content: "##";
color: #2175bc;
position: relative;
top: 0;
left: -8px;
}
.postBody blockquote, .postCon blockquote{
background-image: none;
border-left: 5px solid #DDDFE4;
background-color: #EEF0F4;
width: 100%;
padding: 6px 0 6px 25px;
}
blockquote{
border:0;
}
.postBody ul li, .postCon ul li {
list-style: initial;
}
a:hover {
text-decoration: none;
}
#cnblogs_post_body a {
color: #0593d3;
border-bottom: none;
border-bottom: 1px solid #0593d3;
}
/* code加上行數 */
.cnblogs-markdown .syntaxhighlighter table td.code {
width:95% !important;
}
.cnblogs-markdown .syntaxhighlighter code {
font-family: "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace!important;
padding: 0 !important;
border-radius: 0 !important;
background-color: transparent !important;
}
.cnblogs-markdown .syntaxhighlighter code:before,
.cnblogs-markdown .syntaxhighlighter code:before {
letter-spacing: -0.5em;
}
/** 更改瀏覽器滾動條和選中字型背景顏色 */
::selection {
background-color: #FF5722;
color: #fff;
}
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-thumb {
min-height: 28px;
background-color: #c2c2c2;
background-clip: padding-box;
}
::-webkit-scrollbar-track-piece {
background-color: #fff;
}
*, :after, :before {
box-sizing: border-box;
}
#under_post_kb{
display: none;
}
/* 評論優化 */
input[type=button] {
width: 80px;
height: 30px;
border-width: 0px;
border-radius: 200px;
background: #1E90FF;
cursor: pointer;
outline: none;
font-family: Microsoft YaHei;
color: white;
}
.commentbox_title_left {
color: #3397ff;
}
div.commentform textarea.comment_textarea {
border-radius: 5px;
}
div.commentform input.author {
background-color: #ffba4d;
width: 150px;
border-radius: 8px;
}
#commentform_title {
display: none;
}
.login_tips {
display: none;
}
/*移動端*/
@media screen and (max-width: 1000px) {
.forkme {display: none;}
.post-img {min-height: 175px;}
#mynavbar_menu {
display: none;
margin-top: 16px;
padding-left: 0;
text-align: left;
width: 100px;
box-shadow: 0 0 1px wheat;
line-height: 49px;
}
#mynavbar_menu a {
display: block;
padding: 0 10px;
background-color: #eee;
}
.site-nav-toggle {display: inline-block !important;}
#searchblogpost {display: none !important;}
#mypost_title {left: 0%;}
#right_meun {display: none !important;}
#main {width: 80%;}
}
/* 選單三條槓 */
span.btn-bar {
display: block;
margin-top: 4px;
width: 22px;
height: 2px;
background: #555;
border-radius: 1px;
}
.site-nav-toggle button {
margin: 0;
padding: 1px 6px;
background: transparent;
border: none;
}
.site-nav-toggle {
position: fixed;
right: 7%;
line-height: 73px;
}
頁首html
<!-- ............自定義首部程式碼開始............ -->
<!-- 自定義進度條 -->
<div id="myProgressBar"></div>
<!-- github fork me -->
<div class="forkme">
<a href="https://github.com/ethan-enhe"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://i.loli.net/2019/02/03/5c56804b26dd9.png" alt="Fork me on GitHub"></a>
</div>
<!-- 自定義導航條 -->
<div id="mynavbar">
<div style="position:relative;width:100%;height:70px;margin:0 auto;">
<a style="width: auto;height: 22px;margin-left: 25px;" href="https://www.cnblogs.com/BlogE">
<img style="width: auto;height: 22px;outline: 0;margin-top: 23.5px;" src="https://i.loli.net/2019/01/31/5c52e907bfa56.png">
</a>
<div id="mynavbar_menu">
<a href="https://www.cnblogs.com/BlogE/"><i class="fas fa-home"></i> Home</a>
<a href="https://www.cnblogs.com/BlogE/tag/"><i class="fas fa-tag"></i> Tags</a>
<a href="https://www.cnblogs.com/BlogE/rss"><i class="fas fa-rss-square"></i> Rss</a>
<a href="https://www.cnblogs.com/BlogE/p/about.html"><i class="fas fa-question"></i> About</a>
</div>
<div class="site-nav-toggle" style="display: none;">
<button aria-label="切換導航欄">
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
</div>
<!-- 自定義頭部錨點 -->
<a name="mtop"></a>
<!-- 自定義頭部 -->
<div id="myheader">
<!-- 背景圖片 -->
<div id="myheader_bg"></div>
<!-- 遮罩層 -->
<div id="myheader_cover">
<!-- 部落格標題 -->
<div id="mypost_title">
<div id="mypost_title_h" style="font-weight: 500;font-size: 30px;">Blog-E</div>
<div id="mypost_title_f"></div>
<div id="mypost_title_e"><a href="https://www.cnblogs.com/BlogE/">路漫漫其修遠兮,吾將上下而求索。</a></div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://files.cnblogs.com/files/BlogE/tomorrow.css">
<script src="https://files.cnblogs.com/files/BlogE/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- ............Font Awesome............ -->
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/all.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/v4-shims.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
<!-- ............自定義首部程式碼結束............ -->
頁尾html
<!-- ............自定義尾部程式碼開始............ -->
<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/[email protected]/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>
P.S.喜新厭舊的我又轉用jekyll弄部落格了,以後這個部落格也許不會更了,不過也歡迎大家參觀我的新部落格blog-e.tk