Skip to content

Instantly share code, notes, and snippets.

@danbeam
Created June 9, 2011 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbeam/1016401 to your computer and use it in GitHub Desktop.
Save danbeam/1016401 to your computer and use it in GitHub Desktop.
Get the colors that can be optimized on the w3's CSS2.1 color page
// on http://www.w3.org/TR/CSS21/syndata.html
Array.prototype.forEach.call(document.querySelectorAll('span.colorsquare'), function(square) {
var name = square.childNodes[0].innerText,
hex = square.childNodes[1].data.trim();
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
hex = '#' + hex[1]+hex[3]+hex[5];
}
if (hex.length > name.length) {
console.log(hex, '->', name);
}
else if (name.length > hex.length) {
console.log (name, '->', hex);
}
});
// then run, awk '{printf " %-39s-> %s\n", tolower($1), tolower($3)}' < colors.css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment