public
anonymous / acceptrate.user.js
Created

  • Download Gist
acceptrate.user.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
// ==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;
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.