Skip to content

Instantly share code, notes, and snippets.

@donmccurdy
Created March 14, 2016 21:41
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 donmccurdy/9a486d015f20b053c242 to your computer and use it in GitHub Desktop.
Save donmccurdy/9a486d015f20b053c242 to your computer and use it in GitHub Desktop.
SO MANY FONT SIZES.
/**
* Count the number of distinct font sizes on the page.
*
* Tested in Chrome, no idea if this works elsewhere.
*
* @author Don McCurdy <dm@donmccurdy.com>
*
*/
var sizes = {};
for (var i = 0; i < document.styleSheets.length; i++) {
for (var j = 0; document.styleSheets[i].cssRules && j < document.styleSheets[i].cssRules.length; j++) {
if (document.styleSheets[i].cssRules[j].style) {
sizes[document.styleSheets[i].cssRules[j].style.fontSize] = true;
}
}
}
delete sizes[''];
console.info('This page has %d distinct font sizes.', sizes.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment