Greasy Fork

Greasy Fork is available in English.

Jianshu.com 简书文章列表

辅助简书跳转列表插件,简书的markdown过于简陋,没有目录结构,这里做了个插件辅助

当前为 2019-04-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Jianshu.com 简书文章列表
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  辅助简书跳转列表插件,简书的markdown过于简陋,没有目录结构,这里做了个插件辅助
//https://cdn.jsdelivr.net/npm/marked/marked.min.js
//https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @author       You
// @match        https://www.jianshu.com/p/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let isDebug = 1
    let poolLink = [];
    document.title = '';
    setTimeout(function () {
        let div = $('<div id="zszen_jianshu" class="简书列表" style="font-size:13;line-height:17px;overflow:hidden; position:fixed; left:2%; top:9%; z-index:9999;height: 25px; width: 53px;border:2px solid #E0E3E5;background-color:#ffffff"></div>');
        $('body').append(div);
        let title = $('<h4 id="title_jianshu" style="text-align:left;width:500%;line-height:13px;margin-bottom:2px;margin-top:2px;line-height:1;padding-left:0px;padding-top:0px;-webkit-margin-before:.3em;-webkit-margin-after:.3em;-webkit-margin-start: 0px;-webkit-margin-end: 0px;font-weight: bold;"><font id="title" style="color:#1D4584;font-size:13px">目录</font></h4>');
        div.append(title);
        let items = $('<ol id="itemList_jianshu" style="width:300%;align:left;line-height:16px;text-align:left;padding-left:7px;padding-top:0px;color:#8B8E85"/>');//<font style="font-size:12px;color:#68ac10">{{item.title}}</font>
        div.append(items);
        document.title = $('h1.title').html();
        if(document.title.length>8){
            document.title = document.title.substr(0,8)+'..';
        }
        for(let i=1;i<=7;i++){
            $('h'+i).not('.title').not('#title_jianshu').each(function(idx,el){
                $(el).attr('id','h'+i+'_'+idx)
            });
            //DLOG('id','h'+i+'_'+idx);
		}
        //let oldIndent = 999;
        let oldItems = [items];
		$('h1,h2,h3,h4,h5,h6,h7').not('.title').not('#title_jianshu').not('[align="center"]').each(function(idx,el){
			//poolLink.push($(el).html());
            let indent = parseInt($(el)[0].tagName[1]);
            let unit = $('<li indent="'+indent+'" style="line-height:18px;align:left"></li>');//;font-size:12px
            let link = $('<a href="#'+$(el).attr('id')+'">'+$(el).html()+'</a>');
            unit.append(link);
            link.on('mouseover',(evt)=>{
                evt.currentTarget.style.color = '#1D8BEE';
                evt.currentTarget.style.fontWeight = 600;
            })
            link.on('mouseout',(evt)=>{
                evt.currentTarget.style.color = '#333333';
                evt.currentTarget.style.fontWeight = 100;
            })
            let lastEl = null;
            for(let i=oldItems.length-1;i>=0;i--){
                lastEl = oldItems[i];
                let distance = (oldItems.length-1)*6
                if(i>0){
                    let lastIndent = parseInt(lastEl.attr('indent'));
                    //DLOG(i,indent,lastIndent);
                    if(indent<=lastIndent){
                        oldItems.pop();
                        continue;
                    }else{
                        unit.css({'text-indent':distance+'px','font-size':(15-i*2)+'px','font-weight':'100'})
                        lastEl.append(unit);
                        oldItems.push(unit);
                    }
                }else{
                    unit.css({'text-indent':distance+'px','font-size':(15-i*2)+'px','font-weight':'100'})
                    lastEl.append(unit);
                    oldItems.push(unit);
                }
                break;
            }
			//oldIndent = indent;
		});

        $(window).resize(updateWin);
        updateWin();

        //showList();
        //showList();
        // recursivelySelf(1);
        // DLOG(poolLink);
    },1000);

    // function recursivelySelf(level){
    //     if(level>6)return;
    //     $('h'+level).not('.title').each(function(idx,el){
    //         poolLink.push($(el).html());
    //         recursivelySelf(level+1);
    //     })
    // }

    function updateWin(){
        let div = $('div#zszen_jianshu');
        if($(window).width()<970){
            hideList();
            div.on('mouseover',showList)
            div.on('mouseout',hideList)
        }else{
            showList();
            div.off('mouseover',showList)
            div.off('mouseout',hideList)
        }
    }

    function showList(){
        //DLOG(document.title);
        let h = $('div#zszen_jianshu').find('ol#itemList_jianshu').height()+50;
        $('h4#title_jianshu').css({'text-align':'left',width:'500%'})
        $('h4#title_jianshu').children().html(document.title);
        $('div#zszen_jianshu').css({width:'155px',height:h+'px'})
        $('div#zszen_jianshu').find('font#title').css({'font-size':'16px'})
        $('div#zszen_jianshu').find('ol#itemList_jianshu').show();
    }

    function hideList(){
        $('h4#title_jianshu').children().html('目录');
        $('h4#title_jianshu').css({'text-align':'center',width:'100%'})
        $('div#zszen_jianshu').css({width:'53px',height:'30px'})
        $('div#zszen_jianshu').find('font#title').css({'font-size':'13px'})
        $('div#zszen_jianshu').find('ol#itemList_jianshu').hide();
	}

    function DLOG(...args){
        if(isDebug) console.log.apply(this,args);
    }

    // Your code here...
})();