Some cross-jurisdictional pages must use Springshare (LibAnswers) chat instead of the default Ocelot (MaxAI) chat.
However, the Ocelot widget is loaded globally in the base AEM template, which is inherited by all pages.
Because of this inheritance, child templates cannot prevent Ocelot from loading. They can only override or hide it after the page renders.
This script handles that override.
The script:
-Loads the Springshare chat widget
-Finds any Ocelot (.MaxAI) elements
-Hides them
-Continues watching the page and hides them again if they appear later
This is visual suppression only.
Ocelot downloads Yes Ocelot JavaScript runs Yes Network requests occur Yes Ocelot visible to users No (hidden)The widget is still loaded and executed — it is simply not displayed.
-Template inheritance:
--Base template (loads Ocelot globally) └── Section template └── Subsection template └── This page (needs Springshare instead)
-Since Ocelot is injected at the base template level, lower templates:
--cannot remove the script
--cannot stop it from loading
--cannot disable execution
--They can only hide it after render.
-Load Springshare <script src="https://ucba.libanswers.com/load_chat.php?hash=..."></script>Adds the LibAnswers chat widget.
Hide Ocelot Elements function hideElements() { var chatTools = document.querySelectorAll(".MaxAI"); chatTools.forEach(function(chatTool) { chatTool.style.display = "none"; }); }
Targets Ocelot containers and hides them using display: none.
Handle Dynamically Injected Widgets var observer = new MutationObserver(function() { hideElements(); });
Some chat widgets load asynchronously.
A MutationObserver watches the DOM and re-hides Ocelot if it is added later.
This script:
-loads Springshare
-hides/hooks any .MaxAI (Ocelot) elements
-continuously suppresses them as the DOM changes
-It ensures only Springshare is visible on these pages while the inherited Ocelot widget remains hidden.