Lurker News
Paste the following into the console of any HN page - for annotated avatars on all HN comments. (self contained code)

  for(u of document.querySelectorAll('.hnuser'))for(u.prepend(c=document.createElement('canvas')),x=c.getContext('2d'),c.width=18,c.height=14,s=u.innerText,r=1,i=28+s.length;i--;i<28?r>>>29>X*X/3+Y/2&&x.fillRect(6+2*X,2*Y,2,2)&x.fillRect(6-2*X,2*Y,2,2):r+=s.charCodeAt(i-28,x.fillStyle='#'+(r>>8&0xFFFFFF).toString(16)))r^=r<<13,r^=r>>>17,r^=r<<5,X=i&3,Y=i>>2

Comments (493) 108 threads

Earlier comments
ZoomZoomZoom#
Wouldn't it be nice to generate the colour in HSL and/or clamp/normalise the luminosity so it's always darker than the background and prevent "invisible" avatars, such as the one generated for @lexicality?
Pr0ject217#
This is really cool!

I've coded in JS for years, and I don't understand how these bit-shifting operations become pixel avatars, or what the magic numbers represent and why they were chosen.
I would like to understand how the author thinks. :)

hutzlibu#
I like it!

Btw. if you have browser extension installed, that add custom scripts to websites, like greasemonkey or tampermonkey - you can have those nice avatars all the time. (without opening up the console)

Load more comments