I still don't understand why my initial solution wasn't working well. After messing around a lot it was like it was timing out and not finishing. Some page loads more would be replaced than others. Any way... Andrey and Thomas suggested interfacing with document.styleSheets (cssRules/rules) and that sent me in the right direction. I struggled with a few cross browser hiccups and ultimately got it working the way I wanted with the following...
<script>
var ssllj = jQuery.noConflict(true);
function ssytb_color_change(sheet) {
var rules = [];
var colors = [
["rgb(0, 0, 128)", "rgb(0, 0, 60)"], /* Change blue (#000080) to navy blue (#00003C) (rgb format) */
["rgb(221, 0, 0)", "rgb(148, 148, 148)"], /* Change red (#DD0000) to gray (#949494) (rgb format)*/
["#000080", "#00003C"], /* Change blue (#000080) to navy blue (#00003C) */
["#dd0000", "#949494"] /* Change red (#DD0000) to gray (#949494) */
];
/* Get the rules from the sheet */
if (document.styleSheets[sheet].cssRules) {
rules = document.styleSheets[sheet].cssRules;
}
else if (document.styleSheets[sheet].rules) {
rules = document.styleSheets[sheet].rules;
}
else {
return;
}
/* Iterate over all the rules in the sheet */
for (var rule in rules) {
/* Make sure its a style rule */
if (rules[rule].type == CSSRule.STYLE_RULE) {
/* Iterate over the colors we need to replace */
for (var color in colors) {
/* Check if the color appears in the rule */
if (rules[rule].cssText.lastIndexOf(colors[color][0]) > 0) {
/* Replace background-color if necessary */
if (rules[rule].style.backgroundColor == colors[color][0]) {
rules[rule].style.backgroundColor = colors[color][1];
}
/* Replace color if necessary */
if (rules[rule].style.color == colors[color][0]) {
rules[rule].style.color = colors[color][1];
}
/* Replace border-bottom-color if necessary */
if (rules[rule].style.borderBottomColor == colors[color][0]) {
rules[rule].style.borderBottomColor = colors[color][1];
}
/* Replace border-top-color if necessary */
if (rules[rule].style.borderTopColor == colors[color][0]) {
rules[rule].style.borderTopColor = colors[color][1];
}
/* Replace border-left-color if necessary */
if (rules[rule].style.borderLeftColor == colors[color][0]) {
rules[rule].style.borderLeftColor = colors[color][1];
}
/* Replace border-right-color if necessary */
if (rules[rule].style.borderRightColor == colors[color][0]) {
rules[rule].style.borderRightColor = colors[color][1];
}
// /* Replace box-shadow-color if necessary */
if (rules[rule].style.boxShadow.indexOf(colors[color][0]) >=0) {
rules[rule].style.boxShadow = rules[rule].style.boxShadow.replace(colors[color][0], colors[color][1]);
}
}
}
}
}
}
ssllj(document).ready(function () {
ssytb_color_change(1);
ssytb_color_change(2);
ssytb_color_change(3);
ssytb_color_change(4);
});
</script>
BUT....
This was taking 10 seconds to execute in IE. Only a little over a second in Chrome, but still visible. I manipulated the function in various ways from the form its presented in above, but couldn't get it to take much less than 10 seconds.
So I gave up.
But then had a thought to implement a function that spits out the CSS that needed modification, which I place onto the pages via the platforms Code page element. The idea here is that I will just have to execute this every once in a while to make sure it stays current with whatever the SportsEngine development staff changes.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
var ssllj = jQuery.noConflict(true);
ssllj(document).ready(function () {
var output = "";
output = output + ssytb_get_css(1);
output = output + ssytb_get_css(2);
output = output + ssytb_get_css(3);
output = output + ssytb_get_css(4);
ssllj('.ssytb_css').text(output);
});
function ssytb_get_css(sheet) {
var output = "";
var modifiedCssText = "";
var rules = [];
var colors = [
["rgb(0, 0, 128)", "rgb(0, 0, 60)"], /* Change blue (#000080) to navy blue (#00003C) (rgb format) */
["rgb(221, 0, 0)", "rgb(148, 148, 148)"], /* Change red (#DD0000) to gray (#949494) (rgb format)*/
["#000080", "#00003C"], /* Change blue (#000080) to navy blue (#00003C) */
["#dd0000", "#949494"] /* Change red (#DD0000) to gray (#949494) */
];
/* Get the rules from the sheet */
if (document.styleSheets[sheet].cssRules) {
rules = document.styleSheets[sheet].cssRules;
}
else if (document.styleSheets[sheet].rules) {
rules = document.styleSheets[sheet].rules;
}
/* Iterate over all the rules in the sheet */
for (var rule in rules) {
/* Check for a style rule */
if (rules[rule].type == CSSRule.STYLE_RULE) {
/* Iterate over the colors we need to replace */
for (var color in colors) {
/* Check if the color appears in the rule */
if (rules[rule].cssText.indexOf(colors[color][0]) > 0) {
/* If it has content then remove it (a lot of these are font awesome characters and dont print well) */
rules[rule].style.removeProperty("content");
/* Replace all of the colors that may appear */
modifiedCssText = rules[rule].cssText;
for (color in colors) {
modifiedCssText = modifiedCssText.split(colors[color][0]).join(colors[color][1]);
}
/* Add modified rule to our output */
output = output + " " + modifiedCssText;
break;
}
}
}
}
return output;
}
</script>