Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a "total rep today" number in the top bar for all StackExchange sites - Only works in Chrome, only makes a request every 30 min or when your total rep changes.
// ==UserScript==
// @name SO Daily Reputation
// @namespace soRepDaily
// @description Shows reputation for the current day.
// @include http://stackoverflow.com/*
// @include http://serverfault.com/*
// @include http://superuser.com/*
// @include http://meta.stackoverflow.com/*
// @include http://*.stackexchange.com/*
// ==/UserScript==
(function(){
var ro = JSON.parse(localStorage.getItem("CurRep")),
hlu = document.getElementById("hlinks-user"),
s = document.createElement('span'), is = s.cloneNode();
s.className = 'reputation-score';
s.id = 'current-rep-top';
is.className = 'bounty-indicator-tab';
is.innerHTML = ro && ro.rep || "Fetching...";
s.appendChild(is);
hlu.insertBefore(s, hlu.childNodes[0]);
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(){
if(!$("#topbar a[href^='/users/logout']:first").length) return;
function leftPad(num) {
return (num < 10) ? '0' + num : num;
}
var today = new Date(),
UTCtoday = today.getUTCFullYear() + '-' + leftPad(today.getUTCMonth()+1) + '-' + leftPad(today.getUTCDate()),
url = ($("#topbar a[href^='/users/recent/']:first").attr('href').match(/^[^?]+/))[0] + '?StartDate=' + UTCtoday + '&EndDate=' + UTCtoday,
repNode = $('#current-rep-top'),
pageRep = $("#hlinks-user .reputation-score").text(),
ro = JSON.parse(localStorage.getItem("CurRep"));
repNode.wrapInner($('<a />', { href: url + '&tab=reputation#tab-top' }))
.attr('title', "Today's reputation so far, Ctrl+Click to force a refresh...otherwise it'll happen whenever your rep changes.")
.bind({
reload: function() {
$(this).load(url + " #tabs a[href^='/users/recent/'][href*='tab=reputation']:first" , function() {
$(this).find('a').html($(this).find('.bounty-indicator-tab').add($('<span class="bounty-indicator-tab">0</span>')).eq(0));
$("#hlinks-user").prepend(this);
localStorage.setItem("CurRep", JSON.stringify({rep: $(this).text() || "0", day: UTCtoday, pageRep: pageRep }));
});
},
click: function(e) {
if(!e.ctrlKey) return;
$(this).find('.bounty-indicator-tab').text('Fething...').end().trigger('reload');
e.preventDefault();
}
});
if(pageRep != ro.pageRep || UTCtoday != ro.day) repNode.trigger('reload');
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.