Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created December 1, 2016 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsi1964/cfafcd9da4ebfbca6b63f0e229952c20 to your computer and use it in GitHub Desktop.
Save netsi1964/cfafcd9da4ebfbca6b63f0e229952c20 to your computer and use it in GitHub Desktop.
Chrome developer toolbar util: Get CSS containing used CSS classes used below a specified selector
var allClasses = {}, css = '';
var startFrom = prompt('Where should I start?', '#application');
Array.prototype.forEach.call(document.querySelectorAll(startFrom+' *[class]'), function(element) {
Array.prototype.forEach.call(element.classList, function(className) {
if (!allClasses[className]) {
allClasses[className] = 0;
}
allClasses[className]++;
})
});
var found = 0;
for(var key in allClasses) {
css+='.'+key+' {\n/* found '+allClasses[key]+' times */\n}\n';
found++;
};
copy(css);
alert('Found '+found+' classes.\nCSS generated and copied to your clipboard')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment