In hex you use three or six digits to define a color. By replacing all six-digit colors with the closest color which can be expressed with three digits, we save 3 bytes each! Hooray!
http://www.w3.org/TR/CSS2/syndata.html#value-def-color
The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros.
Examples:
'00ff00' -> '0f0'
'34cf9d' -> '3c9'
filtering: x % 16 == x & 15 - if you ever want to take modulo of a potence of 2, remember it.
Nice one with the replace, even shorter by reusing function:
function a(b,c){return++c?('0x'+b>>4).toString(16):b.replace(/../g,a)}