Quick nav

Adding quick-navigation links

目前为 2015-07-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Quick nav
  3. // @version 2.1
  4. // @description Adding quick-navigation links
  5. // @author nicael
  6. // @include *://*.stackexchange.com/questions/*
  7. // @include *://*stackoverflow.com/questions/*
  8. // @include *://*serverfault.com/questions/*
  9. // @include *://*superuser.com/questions/*
  10. // @include *://*askubuntu.com/questions/*
  11. // @include *://*stackapps.com/questions/*
  12. // @include *://*mathoverflow.net/questions/*
  13. // @grant none
  14. // @namespace https://greasyfork.org/users/9713
  15. // ==/UserScript==
  16.  
  17. $("body").append('<div style="text-align:right; position:fixed;top:20%;left:1px;"><div class="quick-nav" style="margin: 0 auto;width:80%;overflow:scroll;padding:5px;text-align:left;background-color:rgba(200,200,200,0.4)"><b>Quick navigation</b><hr><a href="#">Back to question</a><hr></div></div>');
  18.  
  19. if($(document).width()<1350){$(".quick-nav").hide();}else{$(".quick-nav").show();}
  20.  
  21. navControl();
  22.  
  23.  
  24. $(window).resize(function(){
  25. if($(document).width()<1350){$(".quick-nav").fadeOut();}else{$(".quick-nav").fadeIn();}
  26. navControl();
  27. })
  28.  
  29. function navControl(){
  30. var width = ($(document).width()-$("#question-header").css("width").replace("px",""))/2-30;
  31. $(".quick-nav").parent().css({"width":width+"px"});
  32. }
  33.  
  34. var answers = [];
  35. var votes = [];
  36. var owners = [];
  37. var reps = [];
  38. $(".answer").each(function(){
  39. answers.push($(this).data("answerid"));
  40. votes.push($(this).find(".vote-count-post").text());
  41. owners.push($(this).find(".post-signature:last a[href^='/users']").text());
  42. var rep = $(this).find(".post-signature:last .reputation-score").text();
  43. if($(this).find(".post-signature:last .community-wiki").length==0){
  44. if(rep!=""){
  45. reps.push(rep);
  46. } else {
  47. reps.push("del");
  48. }
  49. } else {
  50. reps.push("cw");
  51. }
  52. });
  53. for(var i=0;i<answers.length;i++){
  54. if(reps[i]=="cw"){
  55. $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Community Wiki Answer</a><br>');
  56. } else if(reps[i]=="del"){
  57. $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer by deleted user</a><br>');
  58. } else {
  59. $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer by '+owners[i]+' ('+reps[i]+')</a><br>');
  60. }
  61. }
  62. if(answers.length>18){
  63. $(".quick-nav").css({"height":"400px"})
  64. }