|
<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.
Last Edit: Aug 8, 2006 17:42:59 GMT by Chris
|
|
|
|
Well damn man.... That's just kickass.
|
|
|
|
|
Well damn man.... That's just kickass.   Thanks man
Last Edit: Nov 23, 2005 2:31:40 GMT by Eric
|
|
|
|
Just a little blonde: it adds colour to the karma number, right?
|
|
|
|
|
Just a little blonde: it adds colour to the karma number, right?  Yes it does
|
|
|
peter
Guest
|
Very impressive. I've been very impressed with you Eric over the last 5 or 6 months, you have come quite a long way with Javascript, definitely up there with me, Web, etc, probably even better then me in some areas (like the above code). Keep it up
|
|
|
|
Very impressive. I've been very impressed with you Eric over the last 5 or 6 months, you have come quite a long way with Javascript, definitely up there with me, Web, etc, probably even better then me in some areas (like the above code). Keep it up  Thanks Peter, it means a lot to hear something like that come from you.
Last Edit: Nov 24, 2005 15:35:23 GMT by Eric
|
|
|
|
That is awesome nice job.
|
|
|
|
|
Try global footers, if that doesnt work then try it in indiviual board footers.
|
|
|
|
|
This is more open source then an actual code though, so its not set up in a editable fashion really.
|
|
|
|
|
That and from what I can tell it's got a few "broken" unbreakable spaces.
|
|
|
|
That and from what I can tell it's got a few "broken" unbreakable spaces.  Fixed it for him.  Gotta love PB's anti-stretch system.
|
|
|
|
|
XP That's why when I bother I usually stick to one-space indenting.
|
|
|
|
I just tab and say "screw you PB"  They can try to figure out where its indented when they look at it.
|
|
|
|