import re print("Ensuring flawless tab navigation on homepage (index.html)...") with open('/workspace/part1.js', 'r', encoding='utf-8') as f: part1_js = f.read() # Make sure switchSection function is robust and global switch_section_func = """ // ================= ROBUST SECTION TAB NAVIGATION ================= function switchSection(sectionId) { console.log('Switching to section:', sectionId); // 1. Hide all tab panes const panes = document.querySelectorAll('.tab-pane'); panes.forEach(pane => { pane.classList.remove('active'); pane.style.display = 'none'; }); // 2. Deactivate all top nav items const navItems = document.querySelectorAll('.top-nav-item a, .top-nav-item'); navItems.forEach(item => item.classList.remove('active')); // 3. Activate target pane const targetMap = { 'channels': 'tabPaneChannels', 'planning': 'tabPanePlanning', 'ga4': 'tabPaneGa4', 'b2b': 'tabPaneB2b', 'utm': 'tabPaneUtm', 'telemetry': 'tabPaneTelemetry' }; const paneId = targetMap[sectionId] || sectionId; const targetPane = document.getElementById(paneId); if (targetPane) { targetPane.classList.add('active'); targetPane.style.display = 'block'; } // 4. Activate corresponding nav link const navIdMap = { 'channels': 'navItemChannels', 'planning': 'navItemPlanning', 'ga4': 'navItemGa4', 'b2b': 'navItemB2b', 'utm': 'navItemUtm', 'telemetry': 'navItemTelemetry' }; const targetNavId = navIdMap[sectionId]; if (targetNavId) { const navEl = document.getElementById(targetNavId); if (navEl) { const link = navEl.querySelector('a') || navEl; link.classList.add('active'); } } // Trigger subtab rendering if planning if (sectionId === 'planning' && typeof renderActiveSheetTable === 'function') { renderActiveSheetTable(); } } window.switchSection = switchSection; """ # Replace or add switchSection in part1.js if 'function switchSection' in part1_js: part1_js = re.sub(r'function switchSection\(.*?\)\s*\{[\s\S]*?\}\s*window\.switchSection\s*=\s*switchSection;', switch_section_func.strip(), part1_js) else: part1_js = switch_section_func.strip() + '\n\n' + part1_js with open('/workspace/part1.js', 'w', encoding='utf-8') as f: f.write(part1_js) print("Updated part1.js with bulletproof switchSection!")