function mode() { }; function loop() { document.visibilityState === 'visible' && mode(); setTimeout(loop, 10000); }; addEventListener( "DOMContentLoaded" , loop);