<?php
add_filter( 'wp_enqueue_scripts', 'my_inactivity_refresh' );

function my_inactivity_refresh() {
	$requests = user_has_snipes_in_category('requests');	
	if (is_user_logged_in() && $requests > 0 ) {
		?>			
			<script>
			// START JAVASCRIPT
				document.addEventListener("DOMContentLoaded", function(event) {

					var time = new Date().getTime();
					jQuery(document.body).bind("mousemove keypress", function () {
						//console.log('reset');
						time = new Date().getTime();
					});

					let refresh = setInterval(function() {
						if (new Date().getTime() - time >= 300000) {
							clearTimeout(refresh);
							window.location.reload(true);
						}
					}, 1000);

				});
			// END JAVASCRIPT
			</script>				
		<?php	
	}
}