mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
PWA: Warning and cache visible entries
This commit is contained in:
parent
925ea2c082
commit
c50edd735a
4 changed files with 41 additions and 3 deletions
|
@ -3,8 +3,6 @@
|
|||
const OFFLINE_VERSION = 2;
|
||||
const CACHE_NAME = "offline";
|
||||
|
||||
console.log(USE_CACHE);
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
|
@ -64,3 +62,37 @@ self.addEventListener("fetch", (event) => {
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener("load", async (event) => {
|
||||
if (
|
||||
navigator.onLine === true &&
|
||||
event.target.location.pathname === "/unread" &&
|
||||
USE_CACHE
|
||||
) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
|
||||
for (let article of document.getElementsByTagName("article")) {
|
||||
const as = article.getElementsByTagName("a");
|
||||
if (as.length > 0) {
|
||||
const a = as[0];
|
||||
const href = a.href;
|
||||
cache
|
||||
.add(
|
||||
new Request(href, {
|
||||
headers: new Headers({
|
||||
"Client-Type": "service-worker",
|
||||
}),
|
||||
}),
|
||||
)
|
||||
.then(() => {
|
||||
article;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener("DOMContentLoaded", function () {
|
||||
const offlineFlag = document.getElementById("offline-flag");
|
||||
offlineFlag.classList.toggle("hidden", navigator.onLine);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue