Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2013 04:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/5997591 to your computer and use it in GitHub Desktop.
Save anonymous/5997591 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Accept Rate
// @version 0.4
// @description Display a user's Stack Exchange question accept rate
// @namespace k0tFZXXD
// @author Michael Hampton
// @license GNU GPL v3 or later (http://www.gnu.org/copyleft/gpl.html)
// @include http://stackoverflow.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://stackapps.com/*
// @include http://.stackexchange.com/
// @include http://askubuntu.com/*
// @include http://meta.askubuntu.com/*
// @include http://answers.onstartups.com/*
// @include http://meta.answers.onstartups.com/*
// @include http://mathoverflow.net/*
// @include http://meta.mathoverflow.net/*
// @include http://discuss.area51.stackexchange.com/*
// @exclude http://chat./
// @require http://courses.ischool.berkeley.edu/i290-4/f09/resources/gm_jq_xhr.js
// ==/UserScript==
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($) {
// Ensure we are looking at a question
post = location.pathname.match(/questions\/(\d+)\D/i);
if (!post) return;
// Find the user ID who wrote the question
userid = $(".post-signature.owner > div > div.user-details > a")[0].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
apiurl = location.protocol + "//api.stackexchange.com/2.1/users/" + userid + "?site=" + location.host;
$.get(apiurl, function(o) {
var user = o.items[0];
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";
}
accept_rate_text = '<br class="cbt">\n<div class="accept-rate ' + userclass + '">' + user['accept_rate'] + '% accept rate</div>\n';
$(".post-signature.owner > div").append(accept_rate_text);
$('.user-info').css('height','auto');
}
return;
});
return;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment