// ==UserScript==
// @name Jianshu.com 简书文章列表
// @namespace https://www.jianshu.com/u/15893823363f
// @version 3.1
// @description 辅助简书跳转列表插件,简书的markdown过于简陋,没有目录结构,这里做了个插件辅助。 增加了缓动,修正了因为顶部遮挡导致标签遮挡的问题
//https://cdn.jsdelivr.net/npm/marked/marked.min.js
//https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
//https://code.createjs.com/1.0.0/tweenjs.min.js
// @author Zszen John
// @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();
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];
DLOG($('h1').not((idx,el)=>{return false}));
$('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()+'');
let link = $(''+$(el).html()+'');
unit.append(link);
link.on('mouseover',(evt)=>{
evt.currentTarget.style.color = '#0F839E';
evt.currentTarget.style.fontWeight = 600;
});
link.on('mouseout',(evt)=>{
evt.currentTarget.style.color = '#333333';
evt.currentTarget.style.fontWeight = 100;
});
link.on('click',(evt)=>{
let bt = $(evt.currentTarget);
let target = $('#'+bt.attr('focus'));
let motionTo = target.offset().top-60;
//createjs.Tween.get($(document)).to({alpha:1}, 1000);//.call(handleComplete);
$('body,html').animate({scrollTop: motionTo}, 'normal', 'swing');
});
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':Math.max(15-i*2,11)+'px','font-weight':'100'})
lastEl.append(unit);
oldItems.push(unit);
}
}else{
unit.css({'text-indent':distance+'px','font-size':Math.max(15-i*2,11)+'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...
})();