Skip to content

Instantly share code, notes, and snippets.

@th3hunt
Created November 21, 2014 14:47
Show Gist options
  • Save th3hunt/dcb61309cf5df60cc902 to your computer and use it in GitHub Desktop.
Save th3hunt/dcb61309cf5df60cc902 to your computer and use it in GitHub Desktop.
Extract CSS3 rules
var styleSheets = document.styleSheets
, len = styleSheets.length
, keyframeRules = [];
function extractKeyframes(styleSheet) {
var rules = styleSheet.rules;
rules.forEach = Array.prototype.forEach;
rules.forEach(function (rule) {
if (rule.type === CSSRule.KEYFRAMES_RULE || rule.type === CSSRule.KEYFRAME_RULE) {
keyframeRules.push(rule);
}
});
}
function keyframesRuleToJSON(rule) {
return {
name: rule.name,
text: rule.cssText
};
}
for (var i = 0; i < len; i++) {
extractKeyframes(styleSheets[i]);
}
console.log("Found %s keyframe rules:", keyframeRules.length);
console.log(keyframeRules.map(keyframesRuleToJSON));
debugger;
// copy(keyframeRules.map(keyframesRuleToJSON));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment