From f6ebdc480e5f8b5be4d446ce67e463c35f01da52 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Wed, 18 Nov 2020 19:18:08 +0000 Subject: [PATCH] Background refresh --- views/index.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/views/index.html b/views/index.html index 33f8cda..652de48 100644 --- a/views/index.html +++ b/views/index.html @@ -377,6 +377,19 @@ } }; + // Fetch updates every 5 minutes + setInterval(() => { + fetch(`/api/unread`) + .then(res => res.json()) + .then(items => { + for (let item of items) { + if (!this.items.some(i => i.ID == item.ID)) { + this.items.push(item); + } + } + }) + }, 5 * 60 * 1000); + document.addEventListener('keydown', this._keyListener.bind(this)); if (window.matchMedia('(prefers-color-scheme: dark)').matches) {