Automatically expand checked hierarchical checkboxes

<?php
add_action( 'facetwp_scripts', function() {
  ?>

    <script type="text/javascript">

      (function($) {
        document.addEventListener( "facetwp-loaded", function() {
          $( ".facetwp-checkbox.checked .facetwp-expand" ).trigger( "click" );
        });
      })(jQuery)
    
    </script>

  <?php
}, 100);