, CACHE_MAX_ENTRIES = 500
, FILES_TO_PRECACHE = ["/imgflip_white_96.png", "/imgflip-icon-transparent-192.svg", "/offline", "/imgflip-icon-padded-192.svg"];
self.addEventListener("install", function(a) {
self.skipWaiting && self.skipWaiting();
a.waitUntil(caches.open(CACHE_NAME).then(function(b) {
return b.addAll(FILES_TO_PRECACHE)
}))
});
self.addEventListener("activate", function(a) {
var b = [CACHE_NAME];
a.waitUntil(caches.keys().then(function(c) {
return Promise.all(c.map(function(d) {
if (-1 === b.indexOf(d))
return caches["delete"](d)
}))
}))
});
self.addEventListener("fetch", function(a) {
if ("POST" !== a.request.method && a.request.url.match(/^https:\/\/([a-z]+\.)?imgflip\.com(\/|$)/)) {
if ("function" === typeof URL) {
var b = new URL(a.request.url);
if (b.pathname && -1 !== FILES_TO_PRECACHE.indexOf(b.pathname) && "." === b.pathname.substr(-4, 1)) {
a.respondWith(caches.match(a.request).then(function(c) {
return c ? c : fetchAndCache(a.request)
}));
return
}
}
a.request.url.match(/\.(js|css|png|gif|jpg|ico|svg|mp4|webm)/) || a.respondWith(fetchAndCache(a.request)["catch"](function() {
return caches.match(a.request).then(function(c) {
if (c)
return c;
if ("navigate" === a.request.mode)
return caches.open(CACHE_NAME).then(function(d) {
return d.match("offline")
})
})
}))
}
});
function fetchAndCache(a) {
return fetch(a).then(function(b) {
if (!b || 200 !== b.status || "basic" !== b.type)
return b;
var c = b.clone();
caches.open(CACHE_NAME).then(function(d) {
d.put(a, c)
});
return b
})
}
self.addEventListener("message", function(a) {
"cache_clear_old_entries" === a.data && caches.open(CACHE_NAME).then(function(b) {
b.keys().then(function(c) {
var d = c.length - CACHE_MAX_ENTRIES;
if (!(1 > d))
for (var e = 0; e < d; e++) {
var f = new URL(c[e].url);
-1 === FILES_TO_PRECACHE.indexOf(f.pathname) && b["delete"](c[e])
}
})
})
});
self.addEventListener("notificationclick", function(a) {
"memechat" === a