Skip to content

Instantly share code, notes, and snippets.

@wortwart
Last active August 24, 2020 10:02
Show Gist options
  • Save wortwart/0eb7fc68cf3a70a6c0467337e99b2adc to your computer and use it in GitHub Desktop.
Save wortwart/0eb7fc68cf3a70a6c0467337e99b2adc to your computer and use it in GitHub Desktop.
[document, ...Array.from(document.querySelectorAll('iframe'), frame => frame.contentDocument)]
.flatMap(doc => Array.from(doc.styleSheets))
.flatMap(sheet => Array.from(sheet.cssRules))
.flatMap(rule => {
if (!rule) return [];
if (rule.type === 1) return rule;
if (rule.type === 4 || rule.type === 12) return Array.from(rule.cssRules);
return [];
}).length;
// Counts CSS rules in document, excluding @import, nested frames, CSS in JS, and inline CSS
// not working in Firefox console due to restrictions with document.styleSheets
// shamelessly lifted from https://twitter.com/sir_pepe/status/1296821191219478534
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment