Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Eric

Eric Avatar



1,442


November 2005
<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.

:P


Last Edit: Aug 8, 2006 17:42:59 GMT by Chris

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Well damn man.... That's just kickass. :P

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
Well damn man.... That's just kickass. :P
;D

Thanks man


Last Edit: Nov 23, 2005 2:31:40 GMT by Eric

Team Studio

Team Studio Avatar

******
Administrator

120


June 2005
Just a little blonde: it adds colour to the karma number, right?

:-[

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
admin said:
Just a little blonde: it adds colour to the karma number, right?

:-[

Yes it does :D

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 :)

Eric

Eric Avatar



1,442


November 2005
peter said:
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

Nate

Nate Avatar

**
Official Member

85


July 2007
That is awesome nice job.

mayra

mayra Avatar

*
New Member

5


August 2006
were does this code go?

Sasuke

Sasuke Avatar

****
Senior Member

418


August 2005
Try global footers, if that doesnt work then try it in indiviual board footers.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
This is more open source then an actual code though, so its not set up in a editable fashion really.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
That and from what I can tell it's got a few "broken" unbreakable spaces. :P

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
derfleurer said:
That and from what I can tell it's got a few "broken" unbreakable spaces. :P


Fixed it for him. :P Gotta love PB's anti-stretch system.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
XP That's why when I bother I usually stick to one-space indenting. :P

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I just tab and say "screw you PB" :P They can try to figure out where its indented when they look at it.

newBookmarkLockedFalling