-
Add
CSSSelectorCounter.js
to Chrome Snippets. -
If CSS is served from external domains (i.e. CDN) open Chrome with disabled same origin policy:
open -a Google\ Chrome --args --disable-web-security
-
Run CSS Selector Counter snippet.
Last active
December 17, 2015 13:59
-
-
Save tyom/5621247 to your computer and use it in GitHub Desktop.
Count CSS selectors on current page
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() { | |
var styleSheets = document.styleSheets; | |
for (var j = 0; j < styleSheets.length; j++) { | |
if (styleSheets[j].href) { | |
var stylesheet = styleSheets[j]; | |
var rules = stylesheet.rules; | |
var totalSelectors = 0; | |
for (var i = 0; i < rules.length; i++) { | |
if (rules[i].selectorText) { | |
totalSelectors += rules[i].selectorText.split(',').length; | |
} | |
} | |
console.log('---'); | |
console.log('URL: ' + stylesheet.href); | |
console.log('Rules: ' + stylesheet.rules.length); | |
console.log('Selectors: ' + totalSelectors); | |
} | |
} | |
return "---"; | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment