Scroll unless “Load more” is active

<?php

add_action( 'wp_head', function() {
?>
<script>
(function($) {
    $(function() {
    	FWP.do_scroll = true;

    	$(document).on('click', '.facetwp-load-more', function() {
        	FWP.do_scroll = false;
    	});
    });
})(jQuery);

document.addEventListener('facetwp-loaded', function() {
    if (FWP.do_scroll) {
        window.scrollTo(0, 0);
    }
    FWP.do_scroll = true;
});
</script>

<?php
}, 100 );