csdn.net CSDN博客目录列表

辅助CSDN跳转列表插件

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

  1. // ==UserScript==
  2. // @name csdn.net CSDN博客目录列表
  3. // @namespace https://www.jianshu.com/u/15893823363f
  4. // @version 2.0
  5. // @description 辅助CSDN跳转列表插件
  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://blog.csdn.net/*/article/details/*
  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="CSDN列表" style="border-radius:5px;font-size:13;line-height:17px;overflow:hidden; position:fixed; left:18%; top:9%; z-index:9999;height: 25px; width: 53px;border:3px solid #00CBA0;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:2pxpx;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:#00CBA0;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-article').html();
  27. if(document.title.length>8){
  28. document.title = document.title.substr(0,10)+'..';
  29. }
  30. // for(let i=1;i<=7;i++){
  31. // $('h'+i).not((idx,el)=>{return $(el).attr('class')!=undefined || $(el).attr('id')}).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. //$('h1,h2,h3,h4,h5,h6,h7').not('.title').not('#title_jianshu').
  39. $('div.blog-content-box').find('h1,h2,h3,h4,h5,h6,h7,strong').not((idx,el)=>{return $(el).attr('class')!=undefined || $(el).attr('id')}).each(function(idx,el){
  40. let indent = getTagLevel(el);
  41. let idName = 'h'+indent+'_'+idx;
  42. $(el).attr('id',idName);
  43. DLOG(indent);
  44. let unit = $('<li indent="'+indent+'" style="line-height:18px;align:left"></li>');//;font-size:12px
  45. let link = $('<a focus="'+idName+'">'+$(el).text()+'</a>');
  46. unit.append(link);
  47. //DLOG('>>>',link);
  48. link.on('mouseover',(evt)=>{
  49. DLOG(evt.currentTarget);
  50. evt.currentTarget.style.color = '#00CBA0';
  51. evt.currentTarget.style.fontWeight = 600;
  52. });
  53. link.on('mouseout',(evt)=>{
  54. evt.currentTarget.style.color = '#333333';
  55. evt.currentTarget.style.fontWeight = 100;
  56. });
  57. link.on('click',(evt)=>{
  58. let bt = $(evt.currentTarget);
  59. let target = $('#'+bt.attr('focus'));
  60. let motionTo = target.offset().top-60;
  61. //createjs.Tween.get($(document)).to({alpha:1}, 1000);//.call(handleComplete);
  62. $('body,html').animate({scrollTop: motionTo}, 'normal', 'swing');
  63. });
  64. DLOG(unit.attr('indent'))
  65. let lastEl = null;
  66. for(let i=oldItems.length-1;i>=0;i--){
  67. lastEl = oldItems[i];
  68. let distance = (oldItems.length-1)*6
  69. if(i>0){
  70. let lastIndent = parseInt(lastEl.attr('indent'));
  71. DLOG(i,indent,lastIndent);
  72. if(indent<=lastIndent){
  73. oldItems.pop();
  74. continue;
  75. }else{
  76. unit.css({'text-indent':distance+'px','font-size':Math.max(15-i*2,11)+'px','font-weight':'100'})
  77. lastEl.append(unit);
  78. oldItems.push(unit);
  79. }
  80. }else{
  81. unit.css({'text-indent':distance+'px','font-size':Math.max(15-i*2,11)+'px','font-weight':'100'})
  82. lastEl.append(unit);
  83. oldItems.push(unit);
  84. }
  85. break;
  86. }
  87. //oldIndent = indent;
  88. });
  89.  
  90. //$(window).resize(updateWin);
  91. updateWin();
  92.  
  93. //showList();
  94. //showList();
  95. // recursivelySelf(1);
  96. // DLOG(poolLink);
  97. },1000);
  98.  
  99. // function recursivelySelf(level){
  100. // if(level>6)return;
  101. // $('h'+level).not('.title').each(function(idx,el){
  102. // poolLink.push($(el).html());
  103. // recursivelySelf(level+1);
  104. // })
  105. // }
  106.  
  107. function getTagLevel(el){
  108. let indent = 0;
  109. if($(el)[0].tagName=='STRONG'){
  110. indent = 6;
  111. }else{
  112. indent = parseInt($(el)[0].tagName[1]);
  113. }
  114. return indent;
  115. }
  116.  
  117. function updateWin(){
  118. let div = $('div#zszen_jianshu');
  119. if($(window).width()<0){
  120. hideList();
  121. div.on('mouseover',showList)
  122. div.on('mouseout',hideList)
  123. }else{
  124. showList();
  125. div.off('mouseover',showList)
  126. div.off('mouseout',hideList)
  127. }
  128. }
  129.  
  130. function showList(){
  131. //DLOG(document.title);
  132. let h = $('div#zszen_jianshu').find('ol#itemList_jianshu').height()+$('h4#title_jianshu').height()+30;
  133. $('h4#title_jianshu').css({'text-align':'left',width:'500%'})
  134. $('h4#title_jianshu').children().html(document.title);
  135. $('div#zszen_jianshu').css({width:'155px',height:h+'px'})
  136. $('div#zszen_jianshu').find('font#title').css({'font-size':'16px'})
  137. $('div#zszen_jianshu').find('ol#itemList_jianshu').show();
  138. }
  139.  
  140. function hideList(){
  141. $('h4#title_jianshu').children().html('目录');
  142. $('h4#title_jianshu').css({'text-align':'center',width:'100%'})
  143. $('div#zszen_jianshu').css({width:'53px',height:'30px'})
  144. $('div#zszen_jianshu').find('font#title').css({'font-size':'13px'})
  145. $('div#zszen_jianshu').find('ol#itemList_jianshu').hide();
  146. }
  147.  
  148. function DLOG(...args){
  149. args.unshift('[DEBUG]:')
  150. if(isDebug) console.log.apply(this,args);
  151. }
  152.  
  153. // Your code here...
  154. })();