function levelExp(level) {
return Math.round(15 + 15*Math.pow(level,2));
}
var rArr = [
1, // gr>orng
60, // orng>grn
120, // grn>bl
600, // bl>wht
1200, // wht>gld
1200 //gld
];
var cArr = [
[130, 130, 130, // gr top
80, 80, 80], // gr bot
[130, 91, 30, // orng top
80, 51, 24], // orng bot
[91, 130, 30, // grn top
51, 80, 24], // grn bot
[73, 93, 240, // bl top
30,48,145], // bl bot
[220, 220, 220, // wht top
130, 130, 130], // wht bot
[208, 172, 0, // gld top
128, 112, 19] // gld bot
];
function getFBarC(rep) {
var i = 0;
while (rep>rArr[i]) {
if (typeof rArr[i+1] !== 'undefined') {
i++;
} else {
break;
}
}
return "linear-gradient(rgb(" +
cArr[i][0]+","+
cArr[i][1]+","+
cArr[i][2]+")40%, rgb("+
cArr[i][3]+","+
cArr[i][4]+","+
cArr[i][5]+")57%)";
};
var round = function (n) {
n=n.toString();
var str="";
var c="";
while (n.length>0) {
c=n.substring(0,1);
if (c===".") {
return parseInt(str);
} else {
str=str+c;
}
n=n.substring(1,n.length);
}
if (str.length===0) {
return 0;
}
return parseInt(str);
};
var getLevel = function (rep) {
var i = 0;
while (rep >= levelExp(i)) {
i++;
}
return i;
};
function execute() {
var pushC=-1;
jQuery.fn.push = function () {
pushC++;
$(this).append("<div id=\"element"+pushC+"\"></div>");
return $("#element"+pushC);
};
jQuery.fn.pushFront = function () {
pushC++;
$(this).prepend("<div id=\"element"+pushC+"\"></div>");
return $("#element"+pushC);
};
jQuery.fn.createExpBar = function(user, rep) {
var plus = $(this).find(".inlineAddRepButton");
if (typeof plus.html() == 'undefined') plus = undefined;
else plus = plus.clone(true, true);
$(this).children().each(function(){$(this).remove();});
this.css({
"display": "inherit",
"width": "97px",
"margin": "27px auto"
});
var level = getLevel(rep);
var nextLevel = levelExp(level);
var toNextRatio;
if (level == 0) {
toNextRatio = rep/nextLevel;
} else {
var thisLevel = levelExp(level-1);
toNextRatio = (rep-thisLevel)/(nextLevel-thisLevel);
}
// console.log(user + ": rep:" + rep + "; nextLevel: " + nextLevel + "; thisLevel: " + thisLevel + "; ratio: " + toNextRatio);
$(this).prepend("<br>");
var plusC = $(this).pushFront();
plusC.css({
"width": "100%","height": "15px",
"border": "1px solid #000",
"margin-top": "-17px",
"text-align": "left",
"margin-bottom": "-55px"});
$(this).attr('title',user+' has '+rep+' reputation points, '+round(nextLevel-rep)+' to next level.');
if (typeof plus != 'undefined') {
plus.appendTo(plusC);
plus.removeClass('inlineAddRepButton');
plus.css({
"cursor": "pointer",
"line-height": "0.9",
"margin-left": "4px",
"text-decoration": "none",
"color": "white",
"font-family": "Arial Black",
"font-size": "16px",
"text-shadow": "1px 1px #000, -1px -1px #000, -1px 1px #000, 1px -1px #000"
});
}
var txt = $(this).pushFront();
txt.css({
"width": "100%","height": "15px",
"border": "1px solid #000",
"margin-top": "-17px",
"color": "white",
"font-family": "Arial Black",
"font-size": "10.5px",
"text-shadow": "1px 1px #000, -1px -1px #000, -1px 1px #000, 1px -1px #000"
});
txt.append("Level "+(level + 1));
var bar = $(this).pushFront();
bar.css({
"background": getFBarC(rep),
"width": (toNextRatio*100)+"%",
"height": "15px",
"border": "1px solid #000",
"margin-top": "-17px"});
var barBg = $(this).pushFront();
barBg.css({
"background-color": "#0f0c0c",
"width": "100%","height": "15px",
"border": "1px solid #000",
"margin-top": "-17px"});
};
var gemValues = [
0,
10,
50,
150,
600,
1800
];
$(".ReputationGems").each(function(){
var i;
$(this).mouseover();
var tt = $(".xenTooltip").last();
var txt = tt.text();
tt.remove();
for (i = 0;;i++) {
var charcode = txt.charCodeAt(i);
if (!(charcode > 47 && charcode < 58) &&
!(charcode > 64 && charcode < 91) &&
!(charcode > 96 && charcode < 123)) {
break;
}
}
var user = txt.substr(0, i);
i = txt.search(" received") + 10;
var rep = 0;
for(;;i++) {
var charcode = txt.charCodeAt(i);
if (charcode == 44) continue;
if (!(charcode > 47 && charcode < 58)) break;
rep = rep*10 + (charcode - 48);
}
$(this).createExpBar(user, rep);
});
}
function defer(method) {
if (window.jQuery) {
method();
} else {
setTimeout(function() {defer(method)}, 20);
}
}
defer(execute);