Last active
August 29, 2015 14:04
-
-
Save balthazar/eeae5c58ceddf4c92716 to your computer and use it in GitHub Desktop.
Append the question accept rate of a Stack user on their post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Question Accept Rate | |
// @version 0.5 | |
// @description Display a user's Stack Exchange question accept rate | |
// @namespace k0tFZXXD | |
// @author Michael Hampton | |
// modified by Balthazar Gronon | |
// @license GNU GPL v3 or later (http://www.gnu.org/copyleft/gpl.html) | |
// @include http://stackoverflow.com/* | |
// @include http://ux.stackexchange.com/* | |
// @include http://security.stackexchange.com/* | |
// @include http://softwarerecs.stackexchange.com/* | |
// @include http://discuss.area51.stackexchange.com/* | |
// @include http://stackapps.com/* | |
// @include http://serverfault.com/* | |
// @include http://superuser.com/* | |
// @include http://meta.stackoverflow.com/* | |
// @include http://meta.serverfault.com/* | |
// @include http://meta.superuser.com/* | |
// @include http://.stackexchange.com/ | |
// @include http://askubuntu.com/* | |
// @include http://meta.askubuntu.com/* | |
// @include http://mathoverflow.net/* | |
// @include http://meta.mathoverflow.net/* | |
// @exclude http://chat./ | |
// @require http://courses.ischool.berkeley.edu/i290-4/f09/resources/gm_jq_xhr.js | |
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($) { | |
function appendRate (rate) { | |
if (rate > 80) { | |
userclass = "accept-answer-link"; | |
} else if (rate > 35) { | |
userclass = "cool"; | |
} else if (rate > 20) { | |
userclass = "warm"; | |
} else if (rate > 5) { | |
userclass = "hot"; | |
} else { | |
userclass = "supernova"; | |
} | |
percent = (rate >= 0) ? '%' : ''; | |
accept_rate_text = '<br class="cbt">\n<div class="accept-rate ' + userclass + '">' + rate + percent + ' accept rate</div>\n'; | |
$(".post-signature.owner > div").append(accept_rate_text); | |
$('.user-info').css('height','auto'); | |
} | |
post = location.pathname.match(/questions\/(\d+)\D/i); | |
if (!post) return; | |
userid = $(".post-signature.owner > div > div.user-details > a")[0].href.match(/\/users\/(\d+)(?:\/|$)/)[1]; | |
if (userid < 1) return; | |
apiurl = location.protocol + "//api.stackexchange.com/2.2/users/" + userid + "?site=" + location.host; | |
$.get(apiurl, function(data) { | |
var user = data.items[0]; | |
if (!user) return ; | |
return appendRate(user.accept_rate || NaN); | |
}); | |
return ; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment