/
sc_coder
/
MentalCheckList
Обзор
Документация
Войти
/
sc_coder
/
MentalCheckList
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
sw.js
82 строки
2 KB
ScCoder
Показывать картинку кота по проценту результата теста
14 июл 2026, 09:50
14 июл 2026, 09:50
0483506
Код
Авторство
О чём код?
/** * Service worker: кэширует оболочку приложения для офлайн-работы. */ var CACHE_NAME = 'mental-checklist-v2'; var APP_SHELL = [ './', './index.html', './app.js', './logic.js', './storage.js', './manifest.json', './icons/icon.svg', './icons/cats/cat-1.jpg', './icons/cats/cat-2.jpg', './icons/cats/cat-3.jpg', './icons/cats/cat-4.jpg', './icons/cats/cat-5.jpg', './icons/cats/cat-6.jpg', './icons/cats/cat-7.jpg', './icons/cats/cat-8.jpg', './icons/cats/cat-9.jpg', './icons/cats/cat-10.jpg' ]; self.addEventListener('install', function (event) { event.waitUntil( caches.open(CACHE_NAME).then(function (cache) { return cache.addAll(APP_SHELL); }) ); self.skipWaiting(); }); self.addEventListener('activate', function (event) { event.waitUntil( caches.keys().then(function (keys) { return Promise.all( keys .filter(function (key) { return key !== CACHE_NAME; }) .map(function (key) { return caches.delete(key); }) ); }) ); self.clients.claim(); }); self.addEventListener('notificationclick', function (event) { event.notification.close(); event.waitUntil( self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (clientList) { for (var i = 0; i < clientList.length; i++) { if ('focus' in clientList[i]) return clientList[i].focus(); } if (self.clients.openWindow) return self.clients.openWindow('./index.html'); }) ); }); self.addEventListener('fetch', function (event) { if (event.request.method !== 'GET') return; event.respondWith( caches.match(event.request).then(function (cached) { if (cached) return cached; return fetch(event.request) .then(function (response) { if (response.ok) { var responseClone = response.clone(); caches.open(CACHE_NAME).then(function (cache) { cache.put(event.request, responseClone); }); } return response; }) .catch(function () { if (event.request.mode === 'navigate') { return caches.match('./index.html'); } }); }) ); });