Last active
December 31, 2015 11:59
-
-
Save AshKyd/7983057 to your computer and use it in GitHub Desktop.
Find all the colours in a page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rgbStrToHex(str){ | |
function rgbToHex(r,g,b){ | |
var bin = r << 16 | g << 8 | b; | |
return '#'+(function(h){ | |
return new Array(7-h.length).join("0")+h | |
})(bin.toString(16).toUpperCase()) | |
} | |
if(!str){ | |
return; | |
} | |
var octets = str.match(/(\d+),\s*(\d+),\s*(\d+)/); | |
if(!octets){ | |
return; | |
} | |
return rgbToHex(octets[1],octets[2],octets[3]); | |
} | |
var colors = {}; | |
function addColorStr(color){ | |
if(color){ | |
colors[color] = rgbStrToHex(color); | |
} | |
} | |
$('*').each(function(i,$i){ | |
$i = $($i); | |
addColorStr($i.css('color')); | |
addColorStr($i.css('background-color')); | |
addColorStr($i.css('border-top-color')); | |
addColorStr($i.css('border-right-color')); | |
addColorStr($i.css('border-left-color')); | |
addColorStr($i.css('border-bottom-color')); | |
}); | |
var count = 0; | |
for(var color in colors){ | |
console.log("%c "+color+' - '+colors[color],'color:'+colors[color]+';text-shadow:1px 1px 1px rgba(0,0,0,.1);'); | |
count++; | |
} | |
console.log('Found',count,'unique colours in this page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment