// ==UserScript== // @name SO Question rep reduction estimator // @namespace http://www.shog9.com/greasemonkey/scripts // @author Joshua Heyer // @version 2.0 // @include http://stackoverflow.com/users/* // @include http://meta.stackoverflow.com/users/* // @include http://serverfault.com/users/* // @include http://superuser.com/users/* // ==/UserScript== var script = document.createElement("script"); script.type = "text/javascript"; script.textContent = "(" + fakeRecalc.toString() + ")()"; document.body.appendChild(script); function fakeRecalc() { var initialRep = Number($(".summaryinfo>.summarycount").text().replace(/,/g, '')); $("") .appendTo(".summaryinfo:first") .click(DoRecalc); function DoRecalc() { $(".summaryinfo>.summarycount") .css({color: "yellow"}); $(".summaryinfo:first") .append("
Ignores mitigating factors such as the daily rep cap: actual rep following the official recalc may be greater..."); var userID = /^\/users\/(\d+)/.exec(window.location.pathname)[1]; var joinDate = isoDateStringToDate($(".user-details>tbody>tr:eq(1)>td:eq(1)>span").attr("title")); // round back to start of day (in UTC) joinDate = new Date(joinDate.valueOf() - joinDate.valueOf()%(24*60*60*1000)); LoadNext(joinDate); function LoadNext(start) { var next = new Date(start); next.setUTCDate(next.getUTCDate()+90); $.getJSON("/users/rep-graph/"+userID+'/'+start.valueOf()+'/'+(next-1).valueOf()+'/', function(data) { AccumulateRep(data); if ( next < (new Date()) ) LoadNext(next); else $(".summaryinfo>.summarycount") .css("color", "green") .append("
Difference: " + ((totalGain + totalLoss)-initialRep)); } ); } var totalGain = 0; var totalLoss = 0; function AccumulateRep(repData) { var newRepGain = 0; var newRepLoss = 0; repData.forEach(function(post) { var gain = post.IsQ ? post.Gain / 2 : post.Gain; newRepGain += gain; newRepLoss += post.Loss; }); totalGain += newRepGain; totalLoss += newRepLoss; $(".summaryinfo>.summarycount").html( (totalGain + totalLoss) + "
+" + totalGain + ", " + totalLoss + "
"); } } // cribbed from: http://stackoverflow.com/questions/436374/how-can-i-convert-datetime-microformat-to-local-time-in-javascript/436562#436562 function isoDateStringToDate(datestr) { if (! this.re) { // The date in YYYY-MM-DD or YYYYMMDD format var datere = "(\\d{4})-?(\\d{2})-?(\\d{2})"; // The time in HH:MM:SS[.uuuu] or HHMMSS[.uuuu] format var timere = "(\\d{2}):?(\\d{2}):?(\\d{2}(?:\\.\\d+)?)"; // The timezone as Z or in +HH[:MM] or -HH[:MM] format var tzre = "(Z|(?:\\+|-)\\d{2}(?:\\:\\d{2})?)?"; this.re = new RegExp("^" + datere + "[ T]" + timere + tzre + "$"); } var matches = this.re.exec(datestr); if (! matches) return null; var year = matches[1]; var month = matches[2] - 1; var day = matches[3]; var hour = matches[4]; var minute = matches[5]; var second = Math.floor(matches[6]); var ms = matches[6] - second; var tz = matches[7]; var ms = 0; var offset = 0; if (tz && tz != "Z") { var tzmatches = tz.match(/^(\+|-)(\d{2})(\:(\d{2}))$/); if (tzmatches) { offset = Number(tzmatches[2]) * 60 + Number(tzmatches[4]); if (tzmatches[1] == "-") offset = -offset; } } offset *= 60 * 1000; var dateval = Date.UTC(year, month, day, hour, minute, second, ms) - offset; return new Date(dateval); } }