Created
May 28, 2015 09:19
-
-
Save aheinze/a3a702d652523021165b to your computer and use it in GitHub Desktop.
replace color usage in style rules
This file contains 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
(function() { | |
var styles, style, rules, rule, error, | |
props = ['backgroundColor', 'color'], primaryColor = 'red', replaceColor: 'blue'; | |
document.body.style.visibility = 'hidden'; | |
try { | |
styles = document.styleSheets; | |
for (var i = 0, len = styles.length; i < len; i++) { | |
style = styles[i]; | |
for (var j = 0, lenj = style.cssRules.length; j < lenj; j++) { | |
rule = style.cssRules[j]; | |
if (rule.type === CSSRule.STYLE_RULE) { | |
props.forEach(function(prop) { | |
if (rule.style[prop] && rule.style[prop] == primaryColor) { | |
rule.style[prop] = replaceColor; | |
} | |
}); | |
} | |
} | |
} | |
} catch (error) {} | |
document.body.style.visibility = ''; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment