Greasy Fork is available in English.

Quick nav

Adding quick-navigation links

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name Quick nav
  3. // @version 2.2
  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://greatest.deepsurf.us/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><span class="lsep">|</span> <a href="#" id="sts">settings<hr><a href="#">Back to question</a><hr></div></div>');
  18.  
  19. if(!localStorage.quickNavRealtime){
  20. localStorage.quickNavRealtime="enable";
  21. }
  22.  
  23. if(localStorage.quickNavRealtime=="enable"){
  24. var realtime = " checked";
  25. }
  26. if(localStorage.quickNavRealtime=="disable"){
  27. var realtime = "";
  28. }
  29. if(!localStorage.quickNavRealtimeFreq){
  30. localStorage.quickNavRealtimeFreq="5";
  31. }
  32.  
  33. $("#sts").toggle(function(){
  34. $(this).after('<div id="panel-sts"><input type="checkbox" id="enable-realtime"'+realtime+'> real-time updates<hr></div>');
  35.  
  36.  
  37. },function(){
  38. $(this).next().remove();
  39. })
  40.  
  41. $("body").on("change","#enable-realtime",function(){
  42. if($(this).attr("checked")==undefined){
  43. localStorage.quickNavRealtime="disable";
  44. } else {
  45. localStorage.quickNavRealtime="enable";
  46. }
  47. location.reload();
  48. })
  49.  
  50.  
  51.  
  52.  
  53.  
  54. if($(document).width()<1350){$(".quick-nav").hide();}else{$(".quick-nav").show();}
  55.  
  56. navControl();
  57.  
  58.  
  59. $(window).resize(function(){
  60. if($(document).width()<1350){$(".quick-nav").fadeOut();}else{$(".quick-nav").fadeIn();}
  61. navControl();
  62. })
  63.  
  64. function navControl(){
  65. var width = ($(document).width()-$("#question-header").css("width").replace("px",""))/2-30;
  66. $(".quick-nav").parent().css({"width":width+"px"});
  67. }
  68.  
  69. quickNavFill();
  70.  
  71. function quickNavFill(){
  72. console.log("update");
  73. var answers = [];
  74. var votes = [];
  75. var owners = [];
  76. var reps = [];
  77. $(".answer").each(function(){
  78. answers.push($(this).data("answerid"));
  79. votes.push($(this).find(".vote-count-post").text());
  80. owners.push($(this).find(".post-signature:last a[href^='/users']").text());
  81. var rep = $(this).find(".post-signature:last .reputation-score").text();
  82. if($(this).find(".post-signature:last .community-wiki").length==0){
  83. if(rep!=""){
  84. reps.push(rep);
  85. } else {
  86. reps.push("del");
  87. }
  88. } else {
  89. reps.push("cw");
  90. }
  91.  
  92. });
  93. $(".quick-link").each(function(){
  94. $(this).next().remove();
  95. $(this).remove();
  96. })
  97. for(var i=0;i<answers.length;i++){
  98. if(reps[i]=="cw"){
  99. $(".quick-nav").append('<a class="quick-link" href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Community Wiki Answer</a><br>');
  100.  
  101. } else if(reps[i]=="del"){
  102. $(".quick-nav").append('<a class="quick-link" href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer by deleted user</a><br>');
  103. } else {
  104. $(".quick-nav").append('<a class="quick-link" href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer by '+owners[i]+' ('+reps[i]+')</a><br>');
  105.  
  106. }
  107. }
  108. if(answers.length>18){
  109. $(".quick-nav").css({"height":"400px"})
  110. }
  111.  
  112.  
  113.  
  114. }
  115.  
  116. if(localStorage.quickNavRealtime=="enable"){
  117. setInterval(function(){quickNavFill()},250);
  118. }