# Hiding XX results found using AI - enable toggle by default

**URL:** https://meta.discourse.org/t/hiding-xx-results-found-using-ai-enable-toggle-by-default/385784
**Category:** Feature
**Tags:** ai, ai-search
**Created:** [October 16, 2025, 2:59am UTC](https://meta.discourse.org/t/hiding-xx-results-found-using-ai-enable-toggle-by-default/385784 "2025-10-16T02:59:45Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [October 17, 2025, 4:52am UTC](https://meta.discourse.org/t/hiding-xx-results-found-using-ai-enable-toggle-by-default/385784/7 "2025-10-17T04:52:49Z")

</div>

As a temporary solution if someone needs to enable the toggle button by default, you can add this script to your theme (I’ve put it under \<body\>) which basically looks for a change in the AI search results and then toggles the AI results to enabled. This isn’t the cleanest code, maybe @awesomerobot has a more elegant way to do this.

```plaintext
<script type="text/javascript">
    // THIS SCRIPT IS TO ENABLE THE TOGGLE TO INCLUDE SEARCH RESULTS FROM AI AFTER THE SEARCH IS COMPLETE - DELETE ONCE THERE IS A NATIVE OPTION TO ENABLE THIS BY DEFAULT
    console.log('Script loaded. Continually looking for .semantic-search__searching and managing observer.');

    let searchObserver = null; // Variable to hold the observer instance

    function observeSearchContainer() {
      const searchStatusContainer = document.querySelector('.semantic-search__searching');

      if (searchStatusContainer) {
        // If the container is found
        if (!searchObserver) {
            // If an observer is not already running, start one
            console.log('.semantic-search__searching found. Starting observation.');

            searchObserver = new MutationObserver(function(mutations) {
              //console.log('Mutation detected in .semantic-search__searching:', mutations);
              mutations.forEach(function(mutation) {
                // Check for relevant mutations within the observed container
                if (mutation.type === 'characterData') {
                  //console.log('Relevant mutation type detected. Attempting to trigger toggle button functionality. ' + mutation.type);
                  const currentToggleButton = document.querySelector('button.d-toggle-switch __checkbox.semantic-search__ results-toggle');
                  if (currentToggleButton) {
                      const isCurrentlyEnabled = currentToggleButton.getAttribute('aria-checked') === 'true';
                      if (!isCurrentlyEnabled) { // If the toggle is NOT currently enabled
                        // Trigger a click event to activate associated functionality
                        currentToggleButton.click();
                        console.log('Toggle button click event triggered.');
                      } else {
                        console.log('Toggle button already enabled.');
                      }
                  } else {
                    // This case might happen if the toggle button is removed while the container is still present
                    console.log('Toggle button not found when trying to trigger functionality.');
                  }
                }
              });
            });

            const config = { childList: true, subtree: true, characterData: true, attributes: true };
            searchObserver.observe(searchStatusContainer, config);
            console.log('MutationObserver started on .semantic-search__searching.');
        } else {
            // Container found, and observer is already running for it
            //console.log('.semantic-search__searching found, observer already active.');
        }
      } else {
        // If the container is NOT found
        if (searchObserver) {
            // If an observer was previously running, it means the container was removed
            console.log('.semantic-search__searching removed. Disconnecting observer.');
            searchObserver.disconnect(); // Stop observing
            searchObserver = null; // Reset the observer variable
        } else {
            // Container not found, and no observer is active (correct state)
            //console.log('.semantic-search__searching not found yet.');
        }
      }
    }

    // Use an interval to periodically check for the existence of the container
    const containerCheckInterval = setInterval(observeSearchContainer, 500); // Check every 500 milliseconds
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/hiding-xx-results-found-using-ai-enable-toggle-by-default/385784)._
