Skip to content

Instantly share code, notes, and snippets.

@jcisio
Created May 15, 2019 10:44
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 jcisio/e7816ecd8275278d9eb77c4d92c71ba6 to your computer and use it in GitHub Desktop.
Save jcisio/e7816ecd8275278d9eb77c4d92c71ba6 to your computer and use it in GitHub Desktop.
JavaScript
// https://stackoverflow.com/a/12313690/417401
var
styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length;
for (var j = 0; j < totalStyleSheets; j++){
var
styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
totalRulesInStylesheet = rules.length,
totalSelectorsInStylesheet = 0;
for (var i = 0; i < totalRulesInStylesheet; i++) {
if (rules[i].selectorText){
totalSelectorsInStylesheet += rules[i].selectorText.split(',').length;
}
}
console.log("Stylesheet: "+styleSheet.href);
console.log("Total rules: "+totalRulesInStylesheet);
console.log("Total selectors: "+totalSelectorsInStylesheet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment