主题备份

image

页面定制CSS
image

/* 隐藏一些乱七八糟的东西 */
.navbar, 
#top_nav, 
#lnkBlogLogo, 
#cnblogs_ch, 
.ad_text_commentbox, 
#opt_under_post, 
#cnblogs_c1, 
#under_post_card1, 
#cnblogs_c2, 
#under_post_card2,
.postCon, .clear, .dayTitle, #blogTitle h2 {
    display: none;
}
body{
      font-family: "Lantinghei SC","Open Sans","Lucida Grande",Helvetica,"PingFang SC",STheiti,Verdana,"microsoft yahei","simsun",Geneva,sans-serif;

}
/* .forFlow {
    visibility: hidden;
} */

/* 设置logo */
#Header1_HeaderTitle{
    background-image: -webkit-linear-gradient(left,blue,#66ffff 10%,#cc00ff 20%,#CC00CC 30%, #CCCCFF 40%, #00FFFF 50%,#CCCCFF 60%,#CC00CC 70%,#CC00FF 80%,#66FFFF 90%,blue 100%);
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    -webkit-background-size: 200% 100%;
    -webkit-animation: masked-animation 4s linear infinite;
}
@keyframes masked-animation {
    0% {
        background-position: 0  0;
    }
    100% {
        background-position: -100%  0;
    }
}
/* 导航栏 */
#navList li {
    list-style-type: none;
    float: left;
    margin-left: 20px;
    font-size: 16px;
}
/* logo 和 导航栏 */
#header {
    height: 60px;
    border-bottom: 6px double #e8dede;
}
#blogTitle {
    width: 30%;
}
#navigator {
    width: 70%;
    height: 60px;
    line-height: 40px;
}
#header div {
    float: left;
}
.blogStats{
    margin-left: 60px;
}

body {
    font-size: 12px;
}

#home {
    width: 1024px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
}
a {
    text-decoration: none;
    color: #0000ee;
}
a:hover {
    text-decoration: underline;
    color: #ff6600;
}
/* 文章列表 */
.day {
    width: 100%;
    float: left;
    margin-top: 10px;
    /* margin-left: 100px; */
}
.day div {
    /* width: 200px; */
    float: left;
}
.day .postTitle {
    width: 300px;
    font-size: 14px;
}
.day .postDesc {
    width: 360px;
    margin-left: 36px;
}
/* 文章详情 - 文章标题等 */
.post .postDesc {
    width: 60%;
    text-align: right;
    margin-left: 40%;
    border-bottom: 1px solid #e8dede;
}
.post .postTitle {
    text-align: center;
}
#cnblogs_post_body {
    font-size: 14px;
    padding: 36px 26px;
    border-bottom: 1px solid #e8dede;
}

#cnblogs_post_body p {
    text-indent: 0;
    line-height: 2;
    letter-spacing: 1px;
}
/* 分页 */
.topicListFooter {
text-align: center;
    margin-right: 0;
    margin-top: 20px;
    height: 30px;
    float: left;
    width: 100%;
    border-top: 1px solid #e8dede;
}
#nav_next_page {
    font-size: 12px;
    margin: 10px 0;
    text-align: center;
    color: #2e6ab1;
    line-height: 200%;
}
#nav_next_page a {
        border: 1px solid #9aafe5;
    color: #2e6ab1;
    margin: 0 2px;
    padding: 2px 5px;
    text-decoration: none;
}

#footer{
    width: inherit;
    text-align: center;
    position: absolute;
    bottom: 30px;
}
#sidebar_search > h3 { display: none;}
#widget_my_zzk {
left: 150px;
    position: absolute;
    top: 16px;
    z-index: 2222;
}
#mainContent{display: flex;
    flex-direction: column;
    padding-bottom: 90px;
}
#BlogPostCategory {
    /* margin-bottom: 10px; */
    width: 50%;
    float: left;
    text-align: right;
    padding: 0px 20px 0px 0px;
    box-sizing: border-box;
}
#EntryTag {
    /* margin-top: 0 !important; */
    width: 50%;
    float: left;
    padding: 0px 0px 0px 20px;
    box-sizing: border-box;
}
#blog_post_info {
        width: 100%;
    float: left;
}

#green_channel {
    height: 50px;
    padding: 6px 0;
    /* line-height: 24px; */
    margin-bottom: 10px;
    margin-top: 0;
    border: #FFF 1px dashed;
    font-size: 12px;
    width: 50%;
    text-align: center;
    box-sizing: border-box;
    float: right;
}

#author_profile {
    float: left;
    width: 50%;
    /* margin-top: 0; */
    /* margin-bottom: 10px; */
    color: #000;
    /* margin-left: 0; */
    /* font-size: 12px; */
}

#div_digg {
    /* float: right; */
    /* margin-bottom: 10px; */
    margin-right: 0;
    font-size: 12px;
    width: 100%;
    /* text-align: center; */
    margin-top: 0;
}
.buryit {
    float: left;
}

.comment_textarea {
    width: 100%;
}

.hljs {
    font-family: Menlo;
    font-size: 14px;
}
cnblogs-markdown :not(pre,div,td)>code, .blogpost-body :not(pre,div,td)>code {
    font-family: inherit;
    font-size: 14px;
    /* padding: 0 5px;
    line-height: 1.8;
    margin: 0 3px;
    display: inline-block;
    overflow-x: auto;
    vertical-align: middle;
    border-radius: 3px;
    background-color: #f6f6f6;
    color: #e83e8c; */
}

/*生成博客目录的CSS start*/
#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;
    width: auto;
    height: auto; 
}
#sideBarTab{
    float:left;
    width:30px; 
    border:1px solid #e5e5e5;
    border-right:none;
    text-align:center;
    background:#ffffff;
}
 
#sideBarContents{
    float:left;
    overflow:auto; 
    overflow-x:hidden;!important;
    width: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;
}
/*生成博客目录的CSS end*/

页首html代码

<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>

页脚html

<script type="text/javascript" language="javascript">
    const obj = {
        favicon: 'https://img.alicdn.com/imgextra/i1/O1CN01HvRSoA1yfb7WcDsXJ_!!6000000006606-73-tps-32-32.ico'
    }
    if (obj.favicon) {
        // 替换网站icon
        var linkObject = document.createElement('link');
        linkObject.rel = "shortcut icon";
        linkObject.href = obj.favicon;
        document.getElementsByTagName("head")[0].appendChild(linkObject);
    }
    // 处理单天合并文章
    const manyArticle = $('.day');
    if (manyArticle && manyArticle.length) {
        let newArticlesStr = '';
        for (let i = 0; i < manyArticle.length; i++) {
            const article = manyArticle[i];
            // console.log(article)
            // console.log(article.outerHTML)           
            if (article && article.children && article.children.length >= 12) {
                // console.log(article.children)
                const articleChildren = article.children;
                const str = `
                        <div class="day">
                            ${articleChildren[0].outerHTML}
                            ${articleChildren[1].outerHTML}
                            ${articleChildren[2].outerHTML}
                            <div class="clear"></div>
                            ${articleChildren[4].outerHTML}
                            <div class="clear"></div>
                        </div>
                        <div class="day">
                            ${articleChildren[7].outerHTML}
                            ${articleChildren[8].outerHTML}
                            ${articleChildren[9].outerHTML}
                            <div class="clear"></div>
                            ${articleChildren[10].outerHTML}
                            <div class="clear"></div>
                        </div>
                `
                
                newArticlesStr += str
            } else {
                newArticlesStr += article.outerHTML
            }
            // console.log(article.children.length)
        }
        // console.log(newArticlesStr)
        // 分页显示
        const forFlow = $('.forFlow')[0].children;
        let pageHtml = '';
        // console.log($('.forFlow'))
        if (forFlow && forFlow.length) {
            pageHtml = forFlow[forFlow.length - 2].outerHTML
        }
        
        // console.log(newArticlesStr)
        $('#mainContent')[0].innerHTML = `<div class="forFlow"> ${newArticlesStr} </div> ${pageHtml}`;
        // $('.forFlow').empty();
        // $('.forFlow').append(newArticlesStr)
        // $(".forFlow").css("visibility","visible");
    }

    // 替换摘要下的作者、时间等
    const postDesc = $('.postDesc');
    if (postDesc && postDesc.length) {
        for (let i = 0; i < postDesc.length; i++) {
            const postDescEle = postDesc[i];
            const firstChildData = postDesc[i].firstChild.data;

            const firstChildDataArr = firstChildData.split('\n');
            const timeStr = firstChildDataArr[0];
            const timeStrNew = timeStr.replace('posted @ ', '');
            let postDescStr = `<span class="create_time">${timeStrNew}</span>&nbsp;&nbsp;&nbsp;&nbsp;`;
            const postDescChildren = postDescEle.children;
            if (postDescChildren && postDescChildren.length) {
                for (let y = 0; y < postDescChildren.length; y++) {
                    const postDescChild = postDescChildren[y];
                    const postDescChildrenHtml = postDescChild.outerHTML;
                    postDescStr += `&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildrenHtml} `;
                }

            }
            postDesc[i].innerHTML = postDescStr;

        }
    }

    // 文章详情 - 将文章阅读量等信息移动到标题下边
    const postDom = $('.post');
    if (postDom && postDom[0] && postDom[0].children && postDom[0].children.length) {
        const postChildren = postDom[0].children;
        console.log(postChildren[3].children)
        const postDescChildren = postChildren[3].children;
        const newPostDescStr = `
            <div class="postDesc"> 创建时间:${postDescChildren[1].outerHTML} &nbsp;&nbsp;&nbsp;&nbsp;作者:${postDescChildren[2].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp; 阅读:${postDescChildren[3].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;评论:${postDescChildren[4].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[5].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[6].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[7].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[8].outerHTML}</div>
        `
        const str = `      
            ${postChildren[0].outerHTML}
            ${newPostDescStr}
            ${postChildren[1].outerHTML}
            ${postChildren[2].outerHTML}
        `;
         $('.post')[0].innerHTML = str;
        // console.log(postDom.children)
    }
</script>
posted @ 2023-07-05 18:15  万般自然  阅读(7)  评论(0编辑  收藏  举报