Only automatically update when page not being viewed
This commit is contained in:
parent
a21dd6b74f
commit
7613116bf3
@ -450,8 +450,19 @@
|
||||
}
|
||||
};
|
||||
|
||||
let inView = true;
|
||||
window.onfocus = window.onblur = window.onpageshow = window.onpagehide = function (e) {
|
||||
if ({focus:1, pageshow:1}[e.type]) {
|
||||
if (inView) return;
|
||||
inView = true;
|
||||
} else if (inView) {
|
||||
inView = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch updates every 5 minutes
|
||||
setInterval(() => {
|
||||
if (!inView) {
|
||||
fetch(`/api/unread`)
|
||||
.then(res => res.json())
|
||||
.then(items => {
|
||||
@ -470,7 +481,8 @@
|
||||
}
|
||||
|
||||
this.setPageTitle();
|
||||
})
|
||||
});
|
||||
}
|
||||
}, 5 * 60 * 1000);
|
||||
|
||||
document.addEventListener('keydown', this._keyListener.bind(this));
|
||||
|
Loading…
Reference in New Issue
Block a user