pen-to-squareHide Menu Items by Location

  (function () {
    // List of location IDs where the menu items should be hidden
    const hiddenMenuLocationIds = [
      'CY3NuKb45jDC4NkqpHV3',
      'Sr99nTAsuyDCbfQCL1JQ',
      '1yOGYfoijdDCBjR2YTJ5',
      'L7bCRcMLEmDCtNi77ZQQ',
    ];
    
    // CSS selectors for menu items and elements to hide per location
    const menuSelectorsToHide = [
      '#sb_ai-employee-promo',
      'a[href*="ai-agents"]',
      '#sb_ai-agents',
      '.sidebar-v2-menu-item[href*="/ai-agents"]',
      '[id="sb_AI Agents"]',
      '#sb_location-mobile-app', 
      '#chat-connect',
      '#fb-connect',
      '#launchpad-chatwidget-connect',
      '#whatsapp-connect',
      '#launchpad-stripe-connect',
      '#invite-user',
      '#sb_reporting',
      '#tb_reputations-requests',
      '#tb_quiz-builder',
      '#tb_online-listings',
      '#sb_memberships',
      '#sb_app-marketplace',
      '#reputation-yext-overview-card',
      '#sb_objects',
      '#sb_agency-dashboard',
      '#sb_whatsapp',
      '#sb_ai_agent_settings',
      '#sb_Opportunities-Pipelines',
      '#sb_undefined',
      '#sb_conversations_providers',
      '#sb_brand-boards',
      '#tb_manual-actions',
      '#pendo-base',
      '#pendo-g-5XkyCm3qauAbDY5lupfi7SwX1wA',
      '#sb_business-settings-v2',
      '#sb_labs',
      '#sb_url-redirects',
      '#sb_manage-scoring',
      '#sb_reputation-management'
    ];

    function hideMenuItemsForLocation() {
      const locationId = app?.__vue__?.currentLocationId;
      
      // ADD DEBUG LOGGING
      console.log('=== MENU HIDING DEBUG ===');
      console.log('Current location ID:', locationId);
      console.log('Hidden location IDs:', hiddenMenuLocationIds);
      console.log('Should hide?', hiddenMenuLocationIds.includes(locationId));
      
      // Check if locationId exists
      if (!locationId) {
        console.log('No location ID found - not hiding anything');
        return;
      }
      
      // Only hide if this location is in the hidden list
      if (hiddenMenuLocationIds.includes(locationId)) {
        console.log('HIDING elements for location:', locationId);
        menuSelectorsToHide.forEach((selector) => {
          const elements = document.querySelectorAll(selector);
          console.log(`Hiding ${elements.length} elements for selector: ${selector}`);
          elements.forEach((el) => {
            el.style.display = 'none';
          });
        });
      } else {
        console.log('NOT hiding - location not in hidden list:', locationId);
        // IMPORTANT: Unhide elements if they were previously hidden
        menuSelectorsToHide.forEach((selector) => {
          const elements = document.querySelectorAll(selector);
          elements.forEach((el) => {
            // Only unhide if we previously hid it
            if (el.style.display === 'none') {
              console.log('Unhiding element:', selector);
              el.style.display = '';
            }
          });
        });
      }
    }

    function mutationCallback(mutationsList, observer) {
      for (const mutation of mutationsList) {
        if (mutation.type === 'childList') {
          hideMenuItemsForLocation();
        }
      }
    }

    const observer = new MutationObserver(mutationCallback);
    const config = { childList: true, subtree: true };
    observer.observe(document.body, config);
    hideMenuItemsForLocation(); // Initial run
  })();

Last updated

Was this helpful?