Skip to content

Instantly share code, notes, and snippets.

@harthur
Created March 12, 2010 04:29
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 harthur/330033 to your computer and use it in GitHub Desktop.
Save harthur/330033 to your computer and use it in GitHub Desktop.
function allStyleSheets(doc) {
var stylesheets = [];
for(var i = 0; i < doc.styleSheets.length; i++)
stylesheets = stylesheets.concat(getStyleSheets(doc.styleSheets[i]));
return stylesheets;
}
function getStyleSheets(stylesheet) {
if(!stylesheet)
return []; // Firefox protects against @import statement loops
var stylesheets = [stylesheet];
var rules = stylesheet.cssRules;
for(var i = 0; i < rules.length; i++) {
if(rules[i].type == CSSRule.IMPORT_RULE)
stylesheets = stylesheets.concat(getStyleSheets(rules[i].styleSheet));
}
return stylesheets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment