Created
December 1, 2016 10:56
-
-
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
This file contains hidden or 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
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