AI로 찾은 XX개 결과 숨기기 - 기본적으로 토글 활성화

누군가가 기본적으로 토글 버튼을 활성화해야 하는 경우를 위한 임시 해결책으로, 테마에 이 스크립트를 추가할 수 있습니다(저는 아래에 배치했습니다). 이 스크립트는 기본적으로 AI 검색 결과의 변경 사항을 감지한 후 AI 결과를 활성화 상태로 전환합니다. 이 코드는 가장 깔끔하지는 않을 수 있으니, @awesomerobot님이 더 우아한 방법을 알고 계실지도 모릅니다.

<script type="text/javascript">
    // 검색이 완료된 후 AI에서 가져온 검색 결과를 포함하도록 토글을 활성화하기 위한 스크립트 - 기본적으로 이 기능을 활성화하는 네이티브 옵션이 생길 때까지 삭제하지 마세요
    console.log('Script loaded. Continually looking for .semantic-search__searching and managing observer.');

    let searchObserver = null; // 관찰자 인스턴스를 저장할 변수

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

      if (searchStatusContainer) {
        // 컨테이너가 발견된 경우
        if (!searchObserver) {
            // 이미 실행 중인 관찰자가 없으면 관찰을 시작합니다
            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) {
                // 관찰 대상 컨테이너 내에서 관련 변경 사항을 확인합니다
                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) { // 토글이 현재 비활성화 상태인 경우
                        // 관련 기능 활성화를 위해 클릭 이벤트를 트리거합니다
                        currentToggleButton.click();
                        console.log('Toggle button click event triggered.');
                      } else {
                        console.log('Toggle button already enabled.');
                      }
                  } else {
                    // 컨테이너가 여전히 존재하는 동안 토글 버튼이 제거된 경우 이 상황이 발생할 수 있습니다
                    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 {
            // 컨테이너가 발견되었고, 이미 해당 컨테이너에 대해 관찰자가 실행 중인 경우
            //console.log('.semantic-search__searching found, observer already active.');
        }
      } else {
        // 컨테이너가 발견되지 않은 경우
        if (searchObserver) {
            // 이전에 관찰자가 실행 중이었다면 컨테이너가 제거된 것을 의미합니다
            console.log('.semantic-search__searching removed. Disconnecting observer.');
            searchObserver.disconnect(); // 관찰을 중단합니다
            searchObserver = null; // 관찰자 변수를 초기화합니다
        } else {
            // 컨테이너가 발견되지 않았고, 활성 관찰자도 없는 경우 (정상 상태)
            //console.log('.semantic-search__searching not found yet.');
        }
      }
    }

    // 컨테이너의 존재 여부를 주기적으로 확인하기 위해 interval을 사용합니다
    const containerCheckInterval = setInterval(observeSearchContainer, 500); // 500밀리초마다 확인
</script>