Calculates CSS selector specificity (rule priority).
Argument: (string) valid CSS selector. Return value: number. (Base used: 256)
The function is sadly too long, 177 bytes. I hope you help me to golf it down to tweet size.
Anyway, I'd be happy if someone use this code in educational purposes and learn something new about CSS "dark places". Or even use this function in the wild.
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
It's just awesome.
Save 2 bytes by the way:
function(a,b){a[b='replace'](/\\.|-|[^ -~]/g,a=0)[b](/:not\b|("|').*?\1/g,'+')[b](/(#)?\w+|(::?\w+(?:\s*\(.*?\))?|\[.*?]|\.\w+)/g,function($,i,c){a+=1<<8*(i?2:!!c)});return a}