-
-
Save miken32/1903bb2d9242ce01a70b48ae8f4abade to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Accept Rate | |
// @version 0.5 | |
// @description Display a user's Stack Exchange question accept rate | |
// @namespace k0tFZXXD | |
// @author Michael Hampton, Michael Newton | |
// @license GNU GPL v3 or later (http://www.gnu.org/copyleft/gpl.html) | |
// @include https://stackoverflow.com/* | |
// @include https://serverfault.com/* | |
// @include https://superuser.com/* | |
// @include https://meta.stackoverflow.com/* | |
// @include https://meta.serverfault.com/* | |
// @include https://meta.superuser.com/* | |
// @include https://stackapps.com/* | |
// @include https://.stackexchange.com/ | |
// @include https://askubuntu.com/* | |
// @include https://meta.askubuntu.com/* | |
// @include https://answers.onstartups.com/* | |
// @include https://meta.answers.onstartups.com/* | |
// @include https://mathoverflow.net/* | |
// @include https://meta.mathoverflow.net/* | |
// @include https://discuss.area51.stackexchange.com/* | |
// @exclude https://chat./ | |
// ==/UserScript== | |
function with_jquery(f) { | |
var script = document.createElement("script"); | |
script.textContent = "(" + f.toString() + ")(jQuery)"; | |
document.body.appendChild(script); | |
}; | |
with_jquery(function($) { | |
// Ensure we are looking at a question | |
if (!$("body").hasClass("question-page")) return; | |
// Find the user ID who wrote the question | |
var userid = $(".post-signature.owner > div > div.user-details > a").attr("href").match(/\/users\/(\d+)(?:\/|$)/)[1]; | |
// Many SE users have negative IDs; none of them are interesting to us | |
if (userid < 1) return; | |
// Get user's info from the SE API | |
var apiurl = location.protocol + "//api.stackexchange.com/2.1/users/" + userid + "?site=" + location.host; | |
$.get(apiurl, function(o) { | |
var user = o.items[0], userclass; | |
if (!user) return; | |
if ('accept_rate' in user) { | |
// TODO: These percentages might not be exactly as | |
// they used to be. Try to verify them later. | |
if (user['accept_rate'] > 80) { | |
userclass = "accept-answer-link"; | |
} else if (user['accept_rate'] > 35) { | |
userclass = "cool"; | |
} else if (user['accept_rate'] > 20) { | |
userclass = "warm"; | |
} else if (user['accept_rate'] > 5) { | |
userclass = "hot"; | |
} else { | |
userclass = "supernova"; | |
} | |
$(".post-signature.owner > div").append($("<br>").addClass("cbt")); | |
$(".post-signature.owner > div").append($("<div>").addClass("accept-rate " + userclass).text(user.accept_rate + "% accept rate")); | |
} | |
return; | |
}); | |
return; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment