Created
April 7, 2015 22:11
-
-
Save jeffreybiles/53308b32db5abf5db412 to your computer and use it in GitHub Desktop.
hacky way to count number of CSS rules
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 countCSSRules() { | |
var results = '', | |
log = ''; | |
if (!document.styleSheets) { | |
return; | |
} | |
var totalCount = 0 | |
for (var i = 0; i < document.styleSheets.length; i++) { | |
totalCount += countSheet(document.styleSheets[i]); | |
} | |
function countSheet(sheet) { | |
var count = 0; | |
if (sheet && sheet.cssRules) { | |
for (var j = 0, l = sheet.cssRules.length; j < l; j++) { | |
if( !sheet.cssRules[j].selectorText ) { | |
continue; | |
} | |
count += sheet.cssRules[j].selectorText.split(',').length; | |
} | |
} | |
console.log(count, sheet.href); | |
return count; | |
} | |
console.log(totalCount); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment