Jianshu.com 简书文章列表

辅助简书跳转列表插件,简书的markdown过于简陋,没有目录结构,这里做了个插件辅助。 增加了缓动,修正了因为顶部遮挡导致标签遮挡的问题

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

  1. // ==UserScript==
  2. // @name Jianshu.com 简书文章列表
  3. // @namespace https://www.jianshu.com/u/15893823363f
  4. // @version 3.1
  5. // @description 辅助简书跳转列表插件,简书的markdown过于简陋,没有目录结构,这里做了个插件辅助。 增加了缓动,修正了因为顶部遮挡导致标签遮挡的问题
  6. //https://cdn.jsdelivr.net/npm/marked/marked.min.js
  7. //https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
  8. //https://code.createjs.com/1.0.0/tweenjs.min.js
  9. // @author Zszen John
  10. // @match https://www.jianshu.com/p/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. let isDebug = 1
  17. let poolLink = [];
  18. document.title = '';
  19. setTimeout(function () {
  20. let div = $('<div id="zszen_jianshu" class="简书列表" style="border-radius:5px;font-size:13;line-height:17px;overflow:hidden; position:fixed; left:2%; top:9%; z-index:9999;height: 25px; width: 53px;border:3px solid #65E1FF;background-color:#ffffff"></div>');
  21. $('body').append(div);
  22. 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:2px;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="font-weight:800;color:#65E1FF;font-size:13px">目录</font></h4>');
  23. div.append(title);
  24. 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>
  25. div.append(items);
  26. document.title = $('h1.title').html();
  27. if(document.title.length>8){
  28. document.title = document.title.substr(0,8)+'..';
  29. }
  30. for(let i=1;i<=7;i++){
  31. $('h'+i).not('.title').not('#title_jianshu').each(function(idx,el){
  32. $(el).attr('id','h'+i+'_'+idx)
  33. });
  34. //DLOG('id','h'+i+'_'+idx);
  35. }
  36. //let oldIndent = 999;
  37. let oldItems = [items];
  38. DLOG($('h1').not((idx,el)=>{return false}));
  39. $('h1,h2,h3,h4,h5,h6,h7').not('.title').not('#title_jianshu').not('[align="center"]').each(function(idx,el){
  40. //poolLink.push($(el).html());
  41. let indent = parseInt($(el)[0].tagName[1]);
  42. let unit = $('<li indent="'+indent+'" style="line-height:18px;align:left"></li>');//;font-size:12px
  43. //let link = $('<a href="#'+$(el).attr('id')+'">'+$(el).html()+'</a>');
  44. let link = $('<a focus="'+$(el).attr('id')+'">'+$(el).html()+'</a>');
  45. unit.append(link);
  46. link.on('mouseover',(evt)=>{
  47. evt.currentTarget.style.color = '#0F839E';
  48. evt.currentTarget.style.fontWeight = 600;
  49. });
  50. link.on('mouseout',(evt)=>{
  51. evt.currentTarget.style.color = '#333333';
  52. evt.currentTarget.style.fontWeight = 100;
  53. });
  54. link.on('click',(evt)=>{
  55. let bt = $(evt.currentTarget);
  56. let target = $('#'+bt.attr('focus'));
  57. let motionTo = target.offset().top-60;
  58. //createjs.Tween.get($(document)).to({alpha:1}, 1000);//.call(handleComplete);
  59. $('body,html').animate({scrollTop: motionTo}, 'normal', 'swing');
  60. });
  61. let lastEl = null;
  62. for(let i=oldItems.length-1;i>=0;i--){
  63. lastEl = oldItems[i];
  64. let distance = (oldItems.length-1)*6
  65. if(i>0){
  66. let lastIndent = parseInt(lastEl.attr('indent'));
  67. //DLOG(i,indent,lastIndent);
  68. if(indent<=lastIndent){
  69. oldItems.pop();
  70. continue;
  71. }else{
  72. unit.css({'text-indent':distance+'px','font-size':Math.max(15-i*2,11)+'px','font-weight':'100'})
  73. lastEl.append(unit);
  74. oldItems.push(unit);
  75. }
  76. }else{
  77. unit.css({'text-indent':distance+'px','font-size':Math.max(15-i*2,11)+'px','font-weight':'100'})
  78. lastEl.append(unit);
  79. oldItems.push(unit);
  80. }
  81. break;
  82. }
  83. //oldIndent = indent;
  84. });
  85.  
  86. $(window).resize(updateWin);
  87. updateWin();
  88.  
  89. //showList();
  90. //showList();
  91. // recursivelySelf(1);
  92. // DLOG(poolLink);
  93. },1000);
  94.  
  95. // function recursivelySelf(level){
  96. // if(level>6)return;
  97. // $('h'+level).not('.title').each(function(idx,el){
  98. // poolLink.push($(el).html());
  99. // recursivelySelf(level+1);
  100. // })
  101. // }
  102.  
  103. function updateWin(){
  104. let div = $('div#zszen_jianshu');
  105. if($(window).width()<970){
  106. hideList();
  107. div.on('mouseover',showList)
  108. div.on('mouseout',hideList)
  109. }else{
  110. showList();
  111. div.off('mouseover',showList)
  112. div.off('mouseout',hideList)
  113. }
  114. }
  115.  
  116. function showList(){
  117. //DLOG(document.title);
  118. let h = $('div#zszen_jianshu').find('ol#itemList_jianshu').height()+50;
  119. $('h4#title_jianshu').css({'text-align':'left',width:'500%'})
  120. $('h4#title_jianshu').children().html(document.title);
  121. $('div#zszen_jianshu').css({width:'155px',height:h+'px'})
  122. $('div#zszen_jianshu').find('font#title').css({'font-size':'16px'})
  123. $('div#zszen_jianshu').find('ol#itemList_jianshu').show();
  124. }
  125.  
  126. function hideList(){
  127. $('h4#title_jianshu').children().html('目录');
  128. $('h4#title_jianshu').css({'text-align':'center',width:'100%'})
  129. $('div#zszen_jianshu').css({width:'53px',height:'30px'})
  130. $('div#zszen_jianshu').find('font#title').css({'font-size':'13px'})
  131. $('div#zszen_jianshu').find('ol#itemList_jianshu').hide();
  132. }
  133.  
  134. function DLOG(...args){
  135. if(isDebug) console.log.apply(this,args);
  136. }
  137.  
  138. // Your code here...
  139. })();