/** * Advanced Taxonomy Reengineering - SJB Final Interceptor * Reconstructs dropdowns into organized hierarchies. */ (function() { const reengineerCategories = () => { const selectNodes = document.querySelectorAll('select[name="categories[]"]'); selectNodes.forEach(selectElement => { if (selectElement.dataset.reengineered === 'true') return; const $select = window.jQuery ? jQuery(selectElement) : null; // 1. Destroy existing SJB widget to access underlying DOM if ($select && $select.data("ech-multiselect")) { $select.multiselect('destroy'); } const optionsArray = Array.from(selectElement.options); let currentOptGroup = null; optionsArray.forEach(option => { const text = option.text; // 2. Structural Reconstruction if (text.includes('(Do NOT select this one')) { const cleanLabel = text.split(':')[0].trim(); currentOptGroup = document.createElement('optgroup'); currentOptGroup.label = cleanLabel; selectElement.insertBefore(currentOptGroup, option); option.remove(); } else if (text.includes('---')) { option.remove(); } else if (currentOptGroup && option.value !== "") { currentOptGroup.appendChild(option); } }); selectElement.dataset.reengineered = 'true'; // 3. Re-initialize Widget if ($select) { $select.multiselect({ selectedText: "# selected", noneSelectedText: "Categories", header: false, menuHeight: 'auto', buttonWidth: 'auto' }); // 4. Immediate UI Cleanup: Scrub legacy text from the generated widget headers const widget = $select.multiselect("widget"); widget.find(".ui-multiselect-optgroup a").each(function() { const $header = jQuery(this); const cleanText = $header.text().split(':')[0].replace('(Do NOT select this one', '').trim(); $header.text(cleanText); }); } }); }; // Tactical Execution after SJB scripts finish window.addEventListener('load', () => { setTimeout(reengineerCategories, 250); const observer = new MutationObserver(() => reengineerCategories()); observer.observe(document.body, { childList: true, subtree: true }); }); })();