Blog Garden automatically generates chapter directory index

Chapter 1 - Source Code

<script language="javascript" type="text/javascript">
// Generate directory index list
function GenerateContentList()
{
    var jquery_h3_list = $( ' #cnblogs_post_body h3 ' ); // If your chapter title is not h3, just replace the h3 here
     if (jquery_h3_list.length> 0)
    {
        var content = '<a name="_labelTop"></a>';
        content    += '<div id="navCategory">';
        content    += '<p style="font-size:18px"><b>阅读目录</b></p>';
        content    += '<ul>';
        for(var i =0;i<jquery_h3_list.length;i++)
        {
            var go_to_top = '<div style="text-align: right"><a href="#_labelTop">回到顶部</a><a name="_label' + i + '"></a></div>';
            $(jquery_h3_list[i]).before(go_to_top);
            var li_content = '<li><a href="#_label' + i + '">' + $(jquery_h3_list[i]).text() + '</a></li>';
            content += li_content;
        }
        content    += '</ul>';
        content    += '</div>';
        if($('#cnblogs_post_body').length != 0 )
        {
            $($('#cnblogs_post_body')[0]).prepend(content);
        }
    }    
}
GenerateContentList();
</script>

Chapter 2 - Use

Instructions:
     After logging in to the blog park, open the background management of the blog park, switch to the "Settings" tab, paste the above code into the "Footer HTML Code" area and save it.

Note: The h3 extracted from the above js code is used as the title of the chapter. If your title is not h3, please modify it yourself in the code comment. In addition to generating a directory index at the beginning of the article, the code
     A "back to top" link will also be generated at the bottom right corner of each chapter (that is, the upper right corner of the next chapter title) to facilitate readers to return to the table of contents. The directory structure of this article is the effect of automatic generation,
     If you find it useful, give it a try.

Chapter 3 - Source Blog Link

http://www.cnblogs.com/wangqiguo/p/4355032.html#3913995

Chapter 4

 

Thanks again to the source blogger for the code~ (*^▽^*)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325203483&siteId=291194637