Skip to content

Instantly share code, notes, and snippets.

@aheinze
Created May 28, 2015 09:19
Show Gist options
  • Save aheinze/a3a702d652523021165b to your computer and use it in GitHub Desktop.
Save aheinze/a3a702d652523021165b to your computer and use it in GitHub Desktop.
replace color usage in style rules
(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