Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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