Skip to content

Instantly share code, notes, and snippets.

@iki
Created September 17, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iki/15ddbbf21b190e275390 to your computer and use it in GitHub Desktop.
Save iki/15ddbbf21b190e275390 to your computer and use it in GitHub Desktop.
snippets for dynamic color scheme
if (settings.mainColor) {
_.each(document.styleSheets, function(styleSheet) {
if (styleSheet.title === 'mainColor') {
_.each(styleSheet.cssRules || styleSheet.rules, function(rule) {
if (rule.type === 1 && rule.cssText && rule.style) {
if (rule.cssText.indexOf('BgColor') !== -1) {
console.log('style: background color ' + settings.mainColor + ' @ ' + rule.cssText, {rule: rule});
rule.style.backgroundColor = settings.mainColor;
}
if (rule.cssText.indexOf('FontColor') !== -1) {
console.log('style: foreground color ' + settings.mainColor + ' @ ' + rule.cssText, {rule: rule});
rule.style.color = settings.mainColor;
}
if (rule.style.visibility === 'hidden') {
console.log('style: unhide ' + rule.cssText, {rule: rule});
rule.style.visibility = '';
}
}
});
}
});
}
<head>
<!-- Set to preferred initial color, or to {visibility: hidden;},
so that it's only displayed after loading settings.
<style title="mainColor">
#main .icon,
.btn.btn-primary, .btn.btn-primary:hover, .btn.btn-primary:active,
.mainBgColor {background-color: #e93335;}
.mainFontColor {color: #e93335;}
</style>
-->
<style title="mainColor">
#main .icon,
.btn.btn-primary, .btn.btn-primary:hover, .btn.btn-primary:active,
.mainBgColor {visibility: hidden;}
.mainFontColor {visibility: hidden;}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment