/** * Advanced Taxonomy Reengineering - SJB Interceptor * Optimized for AcademicCareers.com Job Alert Form */ (function() { const reengineerCategories = () => { // Target the category select by name to ignore dynamic IDs const selectNodes = document.querySelectorAll('select[name="categories[]"]'); selectNodes.forEach(selectElement => { // Prevent duplicate processing if (selectElement.dataset.reengineered === 'true') return; const $select = window.jQuery ? jQuery(selectElement) : null; // 1. Force-destroy the existing SJB Multiselect widget 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. Identify the "Header" logic if (text.includes('(Do NOT select this one')) { // Extract clean title: "FACULTY, POSTDOC, DEPARTMENT HEAD" const cleanLabel = text.split(':')[0].trim(); currentOptGroup = document.createElement('optgroup'); currentOptGroup.label = cleanLabel; selectElement.insertBefore(currentOptGroup, option); option.remove(); } // 3. Purge the legacy "---" separators else if (text.includes('---')) { option.remove(); } // 4. Group valid sub-categories else if (currentOptGroup && option.value !== "") { currentOptGroup.appendChild(option); } }); selectElement.dataset.reengineered = 'true'; // 5. Re-initialize the widget so it renders the new OptGroup hierarchy if ($select) { $select.multiselect({ selectedText: "# selected", noneSelectedText: "Categories", header: false, menuHeight: 'auto', buttonWidth: 'auto' }); } }); }; // Tactical Delay: SJB initializes its scripts at the very end of the . // We wait 200ms after load to ensure our code runs LAST. window.addEventListener('load', () => { setTimeout(reengineerCategories, 200); // Watch for dynamic form injections (modals, etc) const observer = new MutationObserver(() => reengineerCategories()); observer.observe(document.body, { childList: true, subtree: true }); }); })();