// ==UserScript==
// @name SO links
// @namespace stackoverflow
// @description Add special links to Stackoverflow posts
// @include http://stackoverflow.com/questions/*
// ==/UserScript==
//
// Adapted from Benjamin Dumke's script.
function with_jquery(f) {
var script = document.createElement("script");
script.type = "text/javascript";
script.textContent = "(" + f.toString() + ")(jQuery)";
document.body.appendChild(script);
};
with_jquery(function ($) {
///// add privileges link to top line
var links = document.getElementById("hlinks");
$("|").addClass("lsep").appendTo(links);
$("").attr("href", "/privileges")
.attr("title", "show privileges")
.text("priv")
.appendTo(links);
///// add reputation link to score at top line
$(".reputation-score").each(function() {
if (this.parentNode.id == "hlinks-user") {
var score = this.firstChild.nodeValue;
this.removeChild(this.firstChild);
$("").attr("href", "/reputation")
.attr("title", "reputation score")
.text(score)
.appendTo(this);
}
});
///// add revision and timeline links to posts
var match = /(http:\/\/[^\/]+\/)questions\/(\d+)/.exec(location.href);
if (!match) return;
var adr = match[1];
var qid = match[2];
var list = $(".post-menu");
list.each(function() {
var menu = this;
var aid = "";
var i = 0;
for (i = 0; i < menu.childNodes.length; i++) {
var child = menu.childNodes[i];
var submatch = /\/(\d+)#\1$/.exec(child.href);
if (submatch) {
aid = submatch[1];
break;
}
submatch = /\/q\/(\d+)\/\d+$/.exec(child.href);
if (submatch) {
aid = submatch[1];
break;
}
}
if (aid != "") {
$("|").addClass("lsep").appendTo(menu);
// $("").attr("href", adr + "posts/" + aid + "/revisions")
$("").attr("href", "/posts/" + aid + "/revisions")
.attr("title", "see revisions for this post")
.text("revisions")
.appendTo(menu);
$("|").addClass("lsep").appendTo(menu);
$("").attr("href", "/posts/" + qid + "/timeline")
.attr("title", "see timeline for this post")
.text("timeline")
.appendTo(menu);
}
});
});