Skip to content

Instantly share code, notes, and snippets.

@sapel
Created October 13, 2014 22:30
Show Gist options
  • Select an option

  • Save sapel/52155443317da9f4825a to your computer and use it in GitHub Desktop.

Select an option

Save sapel/52155443317da9f4825a to your computer and use it in GitHub Desktop.
count css rules bookmarklet
javascript:(function()%7Bfunction%20countCSSRules()%20%7Bvar%20results%20%3D%20''%2Clog%20%3D%20''%3Bif%20(!document.styleSheets)%20%7Breturn%3B%7Dfor%20(var%20i%20%3D%200%3B%20i%20%3C%20document.styleSheets.length%3B%20i%2B%2B)%20%7BcountSheet(document.styleSheets%5Bi%5D)%3B%7Dfunction%20countSheet(sheet)%20%7Bvar%20count%20%3D%200%3Bif%20(sheet%20%26%26%20sheet.cssRules)%20%7Bfor%20(var%20j%20%3D%200%2C%20l%20%3D%20sheet.cssRules.length%3B%20j%20%3C%20l%3B%20j%2B%2B)%20%7Bif%20(!sheet.cssRules%5Bj%5D.selectorText)%20%7Bif%20(sheet.cssRules%5Bj%5D.cssRules)%20%7Bfor%20(var%20m%20%3D%200%2C%20n%20%3D%20sheet.cssRules%5Bj%5D.cssRules.length%3B%20m%20%3C%20n%3B%20m%2B%2B)%20%7Bif(sheet.cssRules%5Bj%5D.cssRules%5Bm%5D.selectorText)%20%7Bcount%20%2B%3D%20sheet.cssRules%5Bj%5D.cssRules%5Bm%5D.selectorText.split('%2C').length%3B%7D%7D%7D%7Delse%20%7Bcount%20%2B%3D%20sheet.cssRules%5Bj%5D.selectorText.split('%2C').length%3B%7D%7Dlog%20%2B%3D%20'%5CnFile%3A%20'%20%2B%20(sheet.href%20%3F%20sheet.href%20%3A%20'inline%20%3Cstyle%3E%20tag')%3Blog%20%2B%3D%20'%5CnRules%3A%20'%20%2B%20sheet.cssRules.length%3Blog%20%2B%3D%20'%5CnSelectors%3A%20'%20%2B%20count%3Blog%20%2B%3D%20'%5Cn--------------------------'%3Bif%20(count%20%3E%3D%204096)%20%7Bresults%20%2B%3D%20'%5Cn********************************%5CnWARNING%3A%5Cn%20There%20are%20'%20%2B%20count%20%2B%20'%20CSS%20rules%20in%20the%20stylesheet%20'%20%2B%20sheet.href%20%2B%20'%20-%20IE%20will%20ignore%20the%20last%20'%20%2B%20(count%20-%204096)%20%2B%20'%20rules!%5Cn'%3B%7D%7D%20else%20%7Bresults%20%2B%3D%20'unable%20to%20retrieve%20cssRules%20for%20'%2Bsheet.href%2B'%2C%20likely%20a%20cross%20domain%20security%20issue%5Cn'%3B%7D%7Dconsole.log(log)%3Bconsole.log(results)%3B%7D%3BcountCSSRules()%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment