Skip to content

Instantly share code, notes, and snippets.

@manufaktor
Created April 30, 2015 13:25
Show Gist options
  • Save manufaktor/2e8003bd15cfa5ceceac to your computer and use it in GitHub Desktop.
Save manufaktor/2e8003bd15cfa5ceceac to your computer and use it in GitHub Desktop.
Create a CSS properties report from the visible elements on page, so you can easily check if you're using too many font-sizes or colors.
// needs jQuery trollollooo
// example: report("fontSize")
// example: report("fontSize", false) // reports the elements which have the given properties
function gather(prop){
var reduce = function(result, item){
var $item = $(item);
var propValue = $item.css(prop);
result[propValue] = result[propValue] || [];
result[propValue].push(item);
return result;
};
return $("*:visible").toArray().reduce(reduce, {});
}
function report(prop, simple){
var result = gather(prop);
var list = $.map(result, function(value, index){
if(simple !== false){
return[index, value.length];
}
return {
count: value.length,
value: index,
elements: value
}
});
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment