Quick nav

Adding quick-navigation links

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

// ==UserScript==
// @name         Quick nav
// @version      2.1
// @description  Adding quick-navigation links
// @author       nicael
// @include        *://*.stackexchange.com/questions/*
// @include        *://*stackoverflow.com/questions/*
// @include        *://*serverfault.com/questions/*
// @include        *://*superuser.com/questions/*
// @include        *://*askubuntu.com/questions/*
// @include        *://*stackapps.com/questions/*
// @include        *://*mathoverflow.net/questions/*
// @grant        none
// @namespace    https://gf.qytechs.cn/users/9713
// ==/UserScript==

$("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>');

if($(document).width()<1350){$(".quick-nav").hide();}else{$(".quick-nav").show();}

navControl();


$(window).resize(function(){
    if($(document).width()<1350){$(".quick-nav").fadeOut();}else{$(".quick-nav").fadeIn();}
    navControl();
})

function navControl(){
    var width = ($(document).width()-$("#question-header").css("width").replace("px",""))/2-30;
    $(".quick-nav").parent().css({"width":width+"px"});
}

var answers = [];
var votes = [];
var owners = [];
var reps = [];
$(".answer").each(function(){
    answers.push($(this).data("answerid"));
    votes.push($(this).find(".vote-count-post").text());
    owners.push($(this).find(".post-signature:last a[href^='/users']").text());
    var rep = $(this).find(".post-signature:last .reputation-score").text();
    if($(this).find(".post-signature:last .community-wiki").length==0){
        if(rep!=""){
            reps.push(rep);
        } else {
            reps.push("del");
        }
    } else {
        reps.push("cw");
    }
    
});
for(var i=0;i<answers.length;i++){
    if(reps[i]=="cw"){
        $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Community Wiki Answer</a><br>');
        
    } else if(reps[i]=="del"){
        $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer by deleted user</a><br>');
    } else {
        $(".quick-nav").append('<a href="#'+answers[i]+'">'+(i+1)+'. ('+votes[i]+') Answer  by '+owners[i]+' ('+reps[i]+')</a><br>');
        
    }
}
if(answers.length>18){
    $(".quick-nav").css({"height":"400px"})
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址