// ==UserScript==
// @name Jianshu.com 简书文章列表
// @namespace http://tampermonkey.net/
// @version 1.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
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
let isDebug = 1
let poolLink = [];
document.title = '';
setTimeout(function () {
let div = $('
');
$('body').append(div);
let title = $('目录
');
div.append(title);
let items = $('
');//{{item.title}}
div.append(items);
document.title = $('h1.title').html();
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 = $('');//;font-size:12px
let link = $(''+$(el).html()+'');
unit.append(link);
link.on('mouseover',(evt)=>{
evt.currentTarget.style.color = '#ff0000';
})
link.on('mouseout',(evt)=>{
evt.currentTarget.style.color = '#333333';
})
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(function() {
if($(window).width()<970){
hideList();
div.on('mouseover',showList)
div.on('mouseout',hideList)
}else{
showList();
div.off('mouseover',showList)
div.off('mouseout',hideList)
}
});
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 showList(){
//DLOG(document.title);
let h = $('div#zszen_jianshu').find('ol#itemList_jianshu').height()+50;
$('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('目录');
$('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...
})();