/** * Taxonomy Reengineering - Tactical Version * Handles dynamic content loading and ensures structural integrity of . */ (function() { const transformTaxonomy = () => { // Broaden selectors to catch modals and custom field containers const selectNodes = document.querySelectorAll('select[name*="ategory"], select.job-alert-categories, .form-control[name*="ategory"]'); selectNodes.forEach(selectElement => { // Prevent double-processing if the script runs multiple times if (selectElement.dataset.reengineered === 'true') return; const optionsArray = Array.from(selectElement.options); let currentOptGroup = null; optionsArray.forEach(option => { const text = option.text; // Identify the "Header" indicator if (text.includes('(Do NOT select this one')) { const cleanLabel = text.replace(/\(Do NOT select.*?\)/gi, '').trim(); currentOptGroup = document.createElement('optgroup'); currentOptGroup.label = cleanLabel; // Place the group where the "Header" option used to be selectElement.insertBefore(currentOptGroup, option); option.remove(); } // Move valid sub-options into the active group else if (currentOptGroup && option.value !== "") { currentOptGroup.appendChild(option); } }); selectElement.dataset.reengineered = 'true'; }); }; // Tactical Execution: Run on load + Mutation Observer for modals const observer = new MutationObserver((mutations) => { mutations.forEach(() => transformTaxonomy()); }); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', transformTaxonomy); } else { transformTaxonomy(); } // Observe the body for appearing modals or dynamic category loads observer.observe(document.body, { childList: true, subtree: true }); })();