var interval = setInterval(function() {
if(document.visibilityState !== "visible") {
return;
}
time--;
.........
}, 1000);