Created
November 21, 2014 14:47
-
-
Save th3hunt/dcb61309cf5df60cc902 to your computer and use it in GitHub Desktop.
Extract CSS3 rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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