(function () {
const PORTLET_SELECTOR = "#js-portlet-_tbip_pqs_importconditions_INSTANCE_xadj_";
const OLD_REGEX = /Ministry of Agriculture,?\s*Land and Fisheries/g;
const NEW_TEXT = "Ministry of Agriculture and Fisheries";
// Replace in text nodes only (preserves links, <strong>, etc.)
function replaceInTextNodes(root) {
if (!root) return false;
let replaced = false;
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
let node;
while ((node = walker.nextNode())) {
if (node.nodeValue && OLD_REGEX.test(node.nodeValue)) {
node.nodeValue = node.nodeValue.replace(OLD_REGEX, NEW_TEXT);
replaced = true;
}
}
return replaced;
}
// Try immediate replacement (in case React already rendered)
const portlet = document.querySelector(PORTLET_SELECTOR);
if (replaceInTextNodes(portlet || document.body)) {
// done
return;
}
// Otherwise watch for the portlet / content to appear or update
const observer = new MutationObserver((mutations, obs) => {
// check if portlet exists now
const p = document.querySelector(PORTLET_SELECTOR);
// try to replace within the portlet if present, else try the whole body (safe)
const didReplace = replaceInTextNodes(p || document.body);
if (didReplace) {
// Stop observing after successful replacement
obs.disconnect();
}
// (optional) keep watching if not replaced yet
});
observer.observe(document.body, { childList: true, subtree: true });
// Safety: stop observing after 15 seconds if nothing happened
setTimeout(() => observer.disconnect(), 15000);
})();