博客园主题美化
7月24日更新
具体细节见博客园美化.语雀
主要处理了评论输入框的宽度,增加了对点赞按钮美化,调整侧边栏到左侧。
添加目录参考:为博客园添加目录的方法总结 - 妙音天女 - 博客园
音乐播放参考:博客园简约主题simple-color - YJLAugus - 博客园
设置博客网页图标
<script type="text/javascript" language="javascript">
//Setting ico for cnblogs
var linkObject = document.createElement('link');
linkObject.rel = "shortcut icon";
linkObject.href = "https://files-cdn.cnblogs.com/files/lingr7/favicon.ico";
document.getElementsByTagName("head")[0].appendChild(linkObject);
</script>
音乐播放
放在页脚
<script src="https://blog-static.cnblogs.com/files/lingr7/APlayer.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/lingr7/Meting.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/lingr7/DPlayer.min.js"></script>
放在页首
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
<!-- 点击头像搞怪音乐 -->
<audio id="voice" src="https://files-cdn.cnblogs.com/files/yjlaugus/dududu.gif"></audio>
<!-- 点击头像搞怪音乐 -->
<!-- 音乐播放器 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css">
<link rel="stylesheet" href="https://blog-static.cnblogs.com/files/lingr7/DPlayer.min.css">
<div id="aplayer" class="aplayer" data-id="162116100" data-server="netease" data-type="playlist" data-fixed="true" data-listfolded="true" data-order="random" data-theme="#2D8CF0"></div>
<!-- 音乐播放器end data-id="162116100" data-server="netease" 指的是网易云的歌单id,可以按照网易云的歌单播放-->
回到顶部小火箭
放在页首
<link href="http://files.cnblogs.com/files/lingr7/cnblog-scroller.css" type="text/css" rel="stylesheet">
<script src="http://files.cnblogs.com/files/lingr7/scrollspy.js" type="text/javascript"></script>
<script src="http://files.cnblogs.com/files/lingr7/stickUp.min.js" type="text/javascript"></script>
<script src="http://files.cnblogs.com/files/lingr7/cnblog-scroller.js" type="text/javascript"></script>
<style>
#back-top {
position: fixed;
bottom: 10px;
right: 5px;
z-index: 99;
}
#back-top span {
50px;
height: 64px;
display: block;
background:url(http://images.cnblogs.com/cnblogs_com/seanshao/855033/o_rocket.png) no-repeat center center;
}
#back-top a{outline:none}
</style>
<script type="text/javascript">
$(function() {
// hide #back-top first
$("#back-top").hide();
// fade in #back-top
$(window).scroll(function() {
if ($(this).scrollTop() > 500) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-top a').click(function() {
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
</script>
<p id="back-top" style="display:none"><a href="#top"><span></span></a></p>
基本底子
<link rel="stylesheet" href="/css/blog-common.min.css?v=sqi5FxOybx6gjGoG6Zfy1wD-0AwznLNLYOVx7Y9tIN0">
<link id="MainCss" rel="stylesheet" href="/skins/lessismore/bundle-lessismore.min.css?v=1lmBABNvH1t9BXpkhb10bZN9f1c0Xr-rdf30O35tbrs">
<link type="text/css" rel="stylesheet" href="https://blog-static.cnblogs.com/files/lingr7/back_tengluozi.css">
<link id="mobile-style" media="only screen and (max- 767px)" type="text/css" rel="stylesheet" href="/skins/lessismore/bundle-lessismore-mobile.min.css?v=netr1CuSsXZ0CExbtEiL-uTF8pqcWT8cR0el_b5SyJM">
博客侧边栏公告(支持HTML代码) (支持 JS 代码):放社交图标、头像和音乐播放
<!-- 头像 -->
<div class="av">
<img class="but" itemprop="image" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_20010106335437898999.jpg" style="cursor:pointer;"width= "100%" alt="lingr7" />
</div>
<div class="cont">
我的个人博客站:<a href="https://lingr7.coding.me/">lingr7.coding.me</a>
<br></br>
<a href="https://www.yuque.com/lingr7/blog" title="语雀" target="_blank">
<img id="yuque_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_191125030713yuque.png" alt="" style="border: 0pt none;" width = 30 height=30></a>
<a href="https://github.com/lingr7" title="Github" target="_blank">
<img id="github_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_github.png" alt="" style="border: 0pt none;" width = 30 height=30> </a>
<a href="mailto:lingr7@qq.com" title="邮箱" target="_blank">
<img id="mail_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_gmail.png" alt="" style="border: 0pt none;" width = 30 height=30></a>
<a href="https://weibo.com/lingr7/" title="微博" target="_blank">
<img id="weibo_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_weibo.png" alt="" style="border: 0pt none;" width = 30 height=30></a>
<a href="http://wpa.qq.com/msgrd?v=3&uin=1694892905&site=qq&menu=yes" title="QQ对话" target="_blank">
<img id="qq_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_qq.png" alt="" style="border: 0pt none;" width = 30 height=30> </a>
<a href="https://www.cnblogs.com/lingr7/rss" title="订阅Feed" target="_blank">
<img id="feed_icon" src="https://images.cnblogs.com/cnblogs_com/lingr7/1566573/o_rss%20(2).png" alt="" style="border: 0pt none;" width = 30 height=30></a>
</div>
<!-- 头像 -->
<!-- 头像 -->
<!-- 头像搞怪音乐 -->
<script>
$(document).ready(function() {
var voice = document.getElementById('voice'); //获取到audio元素
$('.but').click(function() { //点击文字事件
if (voice.paused) { //判断音乐是否在播放中,暂停状态
voice.play(); //音乐播放
$('.but').text('暂停'); //切换文字
} else { //播放状态
voice.pause(); //音乐停止
$('.but').text('播放'); //切换文字
}
});
});
</script>
<!-- 头像搞怪音乐 -->
<!--随笔发布信息-->
<script>
if ($("#topics")!=null){
$("#cnblogs_post_body").before("<p class='publishinfo'><img src='https://img.shields.io/badge/Post-"+$("#post-date").text().replace(/-/g,"--").replace(/ /g,"%20").replace(/:/g,"%3A")+"-blue'/>"+
"<img src='https://img.shields.io/badge/Read-" + $("#post_view_count").text() + "-red'/>" +
"<img src='https://img.shields.io/badge/Comment-" + $("#post_comment_count").text() + "-green'/><br/>" +
"</p>")
}
</script>
页面定制css代码
/*生成博客目录的CSS*/
#uprightsideBar{
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
text-align:left;
position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
top:50px;
right:0px;
auto;
height: auto;
}
#sideBarTab{
float:left;
30px;
border:1px solid #e5e5e5;
border-right:none;
text-align:center;
background:#ffffff;
}
#sideBarContents{
float:left;
overflow:auto;
overflow-x:hidden;!important;
200px;
min-height:108px;
max-height:460px;
border:1px solid #e5e5e5;
border-right:none;
background:#ffffff;
}
#sideBarContents dl{
margin:0;
padding:0;
}
#sideBarContents dt{
margin-top:5px;
margin-left:5px;
}
#sideBarContents dd, dt {
cursor: pointer;
}
#sideBarContents dd:hover, dt:hover {
color:#A7995A;
}
#sideBarContents dd{
margin-left:20px;
}
页首
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
<!-- 点击头像搞怪音乐 -->
<audio id="voice" src="https://files-cdn.cnblogs.com/files/yjlaugus/dududu.gif"></audio>
<!-- 点击头像搞怪音乐 -->
<!-- 音乐播放器 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css">
<link rel="stylesheet" href="https://blog-static.cnblogs.com/files/lingr7/DPlayer.min.css">
<div id="aplayer" class="aplayer" data-id="162116100" data-server="netease" data-type="playlist" data-fixed="true" data-listfolded="true" data-order="random" data-theme="#2D8CF0"></div>
<!-- 音乐播放器end -->
<!-- 图片灯箱 -->
<!-- <link rel="stylesheet" href="https://blog-static.cnblogs.com/files/lingr7/zoom.css"> -->
<!-- 图片灯箱 -->
<link rel="stylesheet" href="/css/blog-common.min.css?v=sqi5FxOybx6gjGoG6Zfy1wD-0AwznLNLYOVx7Y9tIN0">
<link id="MainCss" rel="stylesheet" href="/skins/lessismore/bundle-lessismore.min.css?v=1lmBABNvH1t9BXpkhb10bZN9f1c0Xr-rdf30O35tbrs">
<link type="text/css" rel="stylesheet" href="https://blog-static.cnblogs.com/files/lingr7/back_tengluozi.css">
<link id="mobile-style" media="only screen and (max- 767px)" type="text/css" rel="stylesheet" href="/skins/lessismore/bundle-lessismore-mobile.min.css?v=netr1CuSsXZ0CExbtEiL-uTF8pqcWT8cR0el_b5SyJM">
<link href="http://files.cnblogs.com/files/lingr7/cnblog-scroller.css" type="text/css" rel="stylesheet">
<script src="http://files.cnblogs.com/files/lingr7/scrollspy.js" type="text/javascript"></script>
<script src="http://files.cnblogs.com/files/lingr7/stickUp.min.js" type="text/javascript"></script>
<script src="http://files.cnblogs.com/files/lingr7/cnblog-scroller.js" type="text/javascript"></script>
<style>
#back-top {
position: fixed;
bottom: 10px;
right: 5px;
z-index: 99;
}
#back-top span {
50px;
height: 64px;
display: block;
background:url(http://images.cnblogs.com/cnblogs_com/seanshao/855033/o_rocket.png) no-repeat center center;
}
#back-top a{outline:none}
</style>
<script type="text/javascript">
$(function() {
// hide #back-top first
$("#back-top").hide();
// fade in #back-top
$(window).scroll(function() {
if ($(this).scrollTop() > 500) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-top a').click(function() {
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
</script>
<p id="back-top" style="display:none"><a href="#top"><span></span></a></p>
<script language="javascript" type="text/javascript">
// 生成目录索引列表
// ref: http://www.cnblogs.com/wangqiguo/p/4355032.html
// modified by: zzq
function GenerateContentList()
{
var mainContent = $('#cnblogs_post_body');
var h2_list = $('#cnblogs_post_body h2');//如果你的章节标题不是h2,只需要将这里的h2换掉即可
if(mainContent.length < 1)
return;
if(h2_list.length>0)
{
var content = '<a name="_labelTop"></a>';
content += '<div id="navCategory" style="color:#152e97;">';
content += '<p style="font-size:18px;"><b>目录</b></p>';
content += '<ul>';
for(var i=0; i<h2_list.length; i++)
{
var go_to_top = '<div style="text-align: right;"><a href="#_labelTop" style="color:#f68a33">回到顶部</a><a name="_label' + i + '"></a></div>';
$(h2_list[i]).before(go_to_top);
var h3_list = $(h2_list[i]).nextAll("h3");
var li3_content = '';
for(var j=0; j<h3_list.length; j++)
{
var tmp = $(h3_list[j]).prevAll('h2').first();
if(!tmp.is(h2_list[i]))
break;
var li3_anchor = '<a name="_label' + i + '_' + j + '"></a>';
$(h3_list[j]).before(li3_anchor);
li3_content += '<li><a href="#_label' + i + '_' + j + '">' + $(h3_list[j]).text() + '</a></li>';
}
var li2_content = '';
if(li3_content.length > 0)
li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a><ul>' + li3_content + '</ul></li>';
else
li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a></li>';
content += li2_content;
}
content += '</ul>';
content += '</div><p> </p>';
content += '<hr style="height:1px;border:none;border-top:1px dashed #0066CC;"/>';
if($('#cnblogs_post_body').length != 0 )
{
$($('#cnblogs_post_body')[0]).prepend(content);
}
}
}
GenerateContentList();
</script>
页脚
<!--<script src="https://blog-static.cnblogs.com/files/lingr7/simple-0102.js"></script> -->
<script src="https://blog-static.cnblogs.com/files/lingr7/APlayer.min.js"></script>
<!-- <script src="https://blog-static.cnblogs.com/files/lingr7/zoom.js"></script> -->
<script src="https://blog-static.cnblogs.com/files/lingr7/Meting.min.js"></script>
<!-- 鼠标点击特效 -->
<!-- <script src="https://blog-static.cnblogs.com/files/lingr7/cursor-effects.js"></script> -->
<!-- 鼠标点击特效end -->
<script src="https://blog-static.cnblogs.com/files/lingr7/DPlayer.min.js"></script>
<script type="text/javascript" language="javascript">
//Setting ico for cnblogs
var linkObject = document.createElement('link');
linkObject.rel = "shortcut icon";
linkObject.href = "https://files-cdn.cnblogs.com/files/lingr7/favicon.ico";
document.getElementsByTagName("head")[0].appendChild(linkObject);
</script>
<script type="text/javascript">
/*
功能:生成博客目录的JS工具
测试:IE8,火狐,google测试通过
孤傲苍狼
2014-5-11
*/
var BlogDirectory = {
/*
获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top)
*/
getElementPosition:function (ele) {
var topPosition = 0;
var leftPosition = 0;
while (ele){
topPosition += ele.offsetTop;
leftPosition += ele.offsetLeft;
ele = ele.offsetParent;
}
return {top:topPosition, left:leftPosition};
},
/*
获取滚动条当前位置
*/
getScrollBarPosition:function () {
var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop;
return scrollBarPosition;
},
/*
移动滚动条,finalPos 为目的位置,internal 为移动速度
*/
moveScrollBar:function(finalpos, interval) {
//若不支持此方法,则退出
if(!window.scrollTo) {
return false;
}
//窗体滚动时,禁用鼠标滚轮
window.onmousewheel = function(){
return false;
};
//清除计时
if (document.body.movement) {
clearTimeout(document.body.movement);
}
var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
var dist = 0;
if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出
window.onmousewheel = function(){
return true;
}
return true;
}
if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离
dist = Math.ceil((finalpos - currentpos)/10);
currentpos += dist;
}
if (currentpos > finalpos) {
dist = Math.ceil((currentpos - finalpos)/10);
currentpos -= dist;
}
var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
window.scrollTo(0, currentpos);//移动窗口
if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出
{
window.onmousewheel = function(){
return true;
}
return true;
}
//进行下一步移动
var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")";
document.body.movement = setTimeout(repeat, interval);
},
htmlDecode:function (text){
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
},
/*
创建博客目录,
id表示包含博文正文的 div 容器的 id,
mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!),
interval 表示移动的速度
*/
createBlogDirectory:function (id, mt, st, interval){
//获取博文正文div容器
var elem = document.getElementById(id);
if(!elem) return false;
//获取div中所有元素结点
var nodes = elem.getElementsByTagName("*");
//创建博客目录的div容器
var divSideBar = document.createElement('DIV');
divSideBar.className = 'uprightsideBar';
divSideBar.setAttribute('id', 'uprightsideBar');
var divSideBarTab = document.createElement('DIV');
divSideBarTab.setAttribute('id', 'sideBarTab');
divSideBar.appendChild(divSideBarTab);
var h2 = document.createElement('H2');
divSideBarTab.appendChild(h2);
var txt = document.createTextNode('目录导航');
h2.appendChild(txt);
var divSideBarContents = document.createElement('DIV');
divSideBarContents.style.display = 'none';
divSideBarContents.setAttribute('id', 'sideBarContents');
divSideBar.appendChild(divSideBarContents);
//创建自定义列表
var dlist = document.createElement("dl");
divSideBarContents.appendChild(dlist);
var num = 0;//统计找到的mt和st
mt = mt.toUpperCase();//转化成大写
st = st.toUpperCase();//转化成大写
//遍历所有元素结点
for(var i=0; i<nodes.length; i++)
{
if(nodes[i].nodeName == mt|| nodes[i].nodeName == st)
{
//获取标题文本
var nodetext = nodes[i].innerHTML.replace(/</?[^>]+>/g,"");//innerHTML里面的内容可能有HTML标签,所以用正则表达式去除HTML的标签
nodetext = nodetext.replace(/ /ig, "");//替换掉所有的
nodetext = BlogDirectory.htmlDecode(nodetext);
//插入锚
nodes[i].setAttribute("id", "blogTitle" + num);
var item;
switch(nodes[i].nodeName)
{
case mt: //若为主标题
item = document.createElement("dt");
break;
case st: //若为子标题
item = document.createElement("dd");
break;
}
//创建锚链接
var itemtext = document.createTextNode(nodetext);
item.appendChild(itemtext);
item.setAttribute("name", num);
item.onclick = function(){ //添加鼠标点击触发函数
var pos = BlogDirectory.getElementPosition(document.getElementById("blogTitle" + this.getAttribute("name")));
if(!BlogDirectory.moveScrollBar(pos.top, interval)) return false;
};
//将自定义表项加入自定义列表中
dlist.appendChild(item);
num++;
}
}
if(num == 0) return false;
/*鼠标进入时的事件处理*/
divSideBarTab.onmouseenter = function(){
divSideBarContents.style.display = 'block';
}
/*鼠标离开时的事件处理*/
divSideBar.onmouseleave = function() {
divSideBarContents.style.display = 'none';
}
document.body.appendChild(divSideBar);
}
};
window.onload=function(){
/*页面加载完成之后生成博客目录*/
BlogDirectory.createBlogDirectory("cnblogs_post_body","h2","h3",20);
}
</script>