Post by Eric on Nov 23, 2005 2:10:18 GMT
<script type="text/javascript">
<!--
/* Add Karma Colors */
var karmaColors = new function()
{
this.karmaMin = -100; // Doesn't actually refer to the maximum
this.karmaMax = 100; // and minimun karmas on the forum
this.goodCol = '#008800';
this.badCol = '#880000';
this.normCol = '#000000';
this.getVals = function(rgbHex)
{
var rgbH = new Array();
var base = (rgbHex.length == 6)? 0:1;
rgbH[0] = parseInt(rgbHex.substring(base,base+2),16);
rgbH[1] = parseInt(rgbHex.substring(base+2,base+4),16);
rgbH[2] = parseInt(rgbHex.substring(base+4,base+6),16);
return rgbH;
}
this.d2h = function(num)
{
var hexChars = '0123456789ABCDEF';
var hex = '';
while(num != 0)
{
hex = hexChars.charAt(num % 16) + hex;
num = Math.floor(num / 16);
}
while(hex.length < 2)
hex = '0' + hex;
return hex;
}
this.getCol = function(color1, color2, karma)
{
var retCol = '#';
var goBy = (karma > 0)? this.karmaMax : this.karmaMin;
for(var c = 0; c < 3; c++)
{
retCol += this.d2h(Math.round((color1[c] - color2[c]) * (karma / goBy)) + color2[c]);
}
return retCol;
}
this.init = function()
{
var karma = 0;
var color = '';
var c = 0;
var useArr = 'good';
var colArr = [this.getVals(this.goodCol), this.getVals(this.normCol),
this.getVals(this.badCol)];
var td = document.getElementsByTagName('td');
for(var t = 0; t < td.length; t++)
{
var color = '';
if(td[t].width == "20%" && td[t].innerHTML.match(/(karma: ([\-0-9,]+))/i))
{
var textRep = RegExp.$1;
var oK = RegExp.$2;
var karma = parseInt(oK.replace(',',''));
karma = (karma > 100)? 100 : (karma < -100)? -100 : karma;
if(karma > 0)
color = this.getCol(colArr[0], colArr[1], karma);
else
color = this.getCol(colArr[2], colArr[1], karma);
td[t].innerHTML = td[t].innerHTML.replace(textRep, 'Karma: <span style="color:'
+ color + '">' + oK + '</span>');
}
}
}
}
// Initiate
karmaColors.init();
//-->
</script>
Adds a color to karma. karmaMin and karmaMax are what you want to divide by. goodCol is the color for positive karma, normCol is the color for 0 karma, and badCol is the color for negative karma. It will balance the good/badCol with the normCol so that someone who has a +1 karma won't be the same color as someone who is +100 karma.
<!--
/* Add Karma Colors */
var karmaColors = new function()
{
this.karmaMin = -100; // Doesn't actually refer to the maximum
this.karmaMax = 100; // and minimun karmas on the forum
this.goodCol = '#008800';
this.badCol = '#880000';
this.normCol = '#000000';
this.getVals = function(rgbHex)
{
var rgbH = new Array();
var base = (rgbHex.length == 6)? 0:1;
rgbH[0] = parseInt(rgbHex.substring(base,base+2),16);
rgbH[1] = parseInt(rgbHex.substring(base+2,base+4),16);
rgbH[2] = parseInt(rgbHex.substring(base+4,base+6),16);
return rgbH;
}
this.d2h = function(num)
{
var hexChars = '0123456789ABCDEF';
var hex = '';
while(num != 0)
{
hex = hexChars.charAt(num % 16) + hex;
num = Math.floor(num / 16);
}
while(hex.length < 2)
hex = '0' + hex;
return hex;
}
this.getCol = function(color1, color2, karma)
{
var retCol = '#';
var goBy = (karma > 0)? this.karmaMax : this.karmaMin;
for(var c = 0; c < 3; c++)
{
retCol += this.d2h(Math.round((color1[c] - color2[c]) * (karma / goBy)) + color2[c]);
}
return retCol;
}
this.init = function()
{
var karma = 0;
var color = '';
var c = 0;
var useArr = 'good';
var colArr = [this.getVals(this.goodCol), this.getVals(this.normCol),
this.getVals(this.badCol)];
var td = document.getElementsByTagName('td');
for(var t = 0; t < td.length; t++)
{
var color = '';
if(td[t].width == "20%" && td[t].innerHTML.match(/(karma: ([\-0-9,]+))/i))
{
var textRep = RegExp.$1;
var oK = RegExp.$2;
var karma = parseInt(oK.replace(',',''));
karma = (karma > 100)? 100 : (karma < -100)? -100 : karma;
if(karma > 0)
color = this.getCol(colArr[0], colArr[1], karma);
else
color = this.getCol(colArr[2], colArr[1], karma);
td[t].innerHTML = td[t].innerHTML.replace(textRep, 'Karma: <span style="color:'
+ color + '">' + oK + '</span>');
}
}
}
}
// Initiate
karmaColors.init();
//-->
</script>
Adds a color to karma. karmaMin and karmaMax are what you want to divide by. goodCol is the color for positive karma, normCol is the color for 0 karma, and badCol is the color for negative karma. It will balance the good/badCol with the normCol so that someone who has a +1 karma won't be the same color as someone who is +100 karma.