Assuming the following CSS stylesheet is used on a live website. What is the best way to parse all the colors used on the stylesheet and change the values with new ones using JavaScript?
In this scenario, I can't create CSS classes to override the colors via plain CSS, so JavaScript is the only way to go. There is no manageable way to add or edit classes. Since they are dynamic and change on each new product release. And changes should happen only on Client side. With no need to store the overrides.
The goal is to re-theme an UI, overriding the existing color with a new color palette. Each old color will be converted into a new one. i.e #FFF -> #000 rgb(33,33,33) -> rgb(66,66,66)
.my-classdas90das {
color: #000000;
}
.other-classAd21 {
background: rgba(255,255,255);
border-color: #222222;
}
.a-class438I {
box-shadow: 1px 1px 1px rgba(44, 44, 44);
}
My first attempt was to loop and access the properties via:
document.styleSheets[1].cssRules[0].style
Is there any better way to do this?