aircox/assets/src/utils.js
2023-03-13 17:47:00 +01:00

18 lines
441 B
JavaScript

/**
* Run function with provided args only if document is not hidden
*/
export function setEcoTimeout(func, ...args) {
return setTimeout((...args) => {
!document.hidden && func(...args)
}, ...args)
}
/**
* Run function at specific interval only if document is not hidden
*/
export function setEcoInterval(func, ...args) {
return setInterval((...args) => {
!document.hidden && func(...args)
}, ...args)
}