123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- const CACHE_NAME = 'MeeChat_v1.2.2';
- let urlsToCache = ["//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-09f52bd0.ca822529.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-16c7788e.652db6b3.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-1d9b7d3a.2141a0c4.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-1e160aad.9d966e19.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-352466e2.33bf20c7.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-392b6146.2b7cc37a.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-3c3559fc.c581b33e.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-3d694970.cd5067d4.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-4031c6b3.16b86625.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-580cf024.3e00a85d.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-5a6c5be1.5efbb31d.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-60610c8a.1eb38ece.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6361f770.e85683b9.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-66871504.0c677439.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6c021ec0.2806d288.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6f498702.a8887c6a.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-74a922ec.4b0c5d76.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-a81e4a76.8bcff4db.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-b17cf818.1737301f.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-b401ae72.94a16efd.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-cb34f022.745242a7.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-common.3e30cf5b.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-e1cff4e2.f84fbbfb.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-vendors.7cb03c3e.css","//static.meechat.me/cdn/new.mee.chat/dist/css/h5.48da3384.css","//static.meechat.me/cdn/new.mee.chat/dist/css/mini.ada854d2.css","//static.meechat.me/cdn/new.mee.chat/dist/css/pc.beaa8f19.css","//static.meechat.me/cdn/new.mee.chat/dist/favicon.ico","//static.meechat.me/cdn/new.mee.chat/dist/fonts/element-icons.2fad952a.woff","//static.meechat.me/cdn/new.mee.chat/dist/fonts/element-icons.6f0a7632.ttf","//static.meechat.me/cdn/new.mee.chat/dist/h5.html","//static.meechat.me/cdn/new.mee.chat/dist/img/bg.261295d3.jpg","//static.meechat.me/cdn/new.mee.chat/dist/img/bg.71de928a.jpg","//static.meechat.me/cdn/new.mee.chat/dist/img/bg.eb029f3a.png","//static.meechat.me/cdn/new.mee.chat/dist/img/bg2.0b28333d.png","//static.meechat.me/cdn/new.mee.chat/dist/img/h5_bg.e9487380.png","//static.meechat.me/cdn/new.mee.chat/dist/img/h5_bg2.21b33271.png","//static.meechat.me/cdn/new.mee.chat/dist/img/h5_bg3.6f597ff4.png","//static.meechat.me/cdn/new.mee.chat/dist/img/icon-tele.0c036f6a.png","//static.meechat.me/cdn/new.mee.chat/dist/img/icon-tele.88177f4a.png","//static.meechat.me/cdn/new.mee.chat/dist/img/icons/meechat.png","//static.meechat.me/cdn/new.mee.chat/dist/img/icons/meechat_icon.png","//static.meechat.me/cdn/new.mee.chat/dist/img/icons/safari-pinned-tab.svg","//static.meechat.me/cdn/new.mee.chat/dist/img/loading.b4490fa6.gif","//static.meechat.me/cdn/new.mee.chat/dist/img/login-logo.6f40e8ff.png","//static.meechat.me/cdn/new.mee.chat/dist/img/user-ethereum-icon.fdf8b24e.png","//static.meechat.me/cdn/new.mee.chat/dist/img/user-tron-icon.92300839.png","//static.meechat.me/cdn/new.mee.chat/dist/index.html","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-09f52bd0.9c00bf68.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-16c7788e.435a1a7e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-1d9b7d3a.7a6ad702.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-1e160aad.1a7361d6.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-352466e2.fdd374fe.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-392b6146.e339a89c.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-3c3559fc.0f399dba.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-3d694970.ad0e5512.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-4031c6b3.0b1e3043.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-437e2b39.9d30634e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-580cf024.14d7734a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-5a6c5be1.44dac6b5.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-60610c8a.a47d6ec6.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6361f770.f496f1c3.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-66871504.8a1d69f1.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6c021ec0.66abd4ea.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6f498702.4911296f.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-74a922ec.75d6a583.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-a81e4a76.bbf68338.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-b17cf818.913b8d09.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-b401ae72.0dd96389.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-cb34f022.cb90cc1e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-common.d71e6f00.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-d42f0a14.fca71a2d.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-e1cff4e2.f3763875.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-vendors.a47fe035.js","//static.meechat.me/cdn/new.mee.chat/dist/js/h5.8c6f0b13.js","//static.meechat.me/cdn/new.mee.chat/dist/js/mini.1dbbc78a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/pc.4cc8c1cc.js","//static.meechat.me/cdn/new.mee.chat/dist/manifest_h5.json","//static.meechat.me/cdn/new.mee.chat/dist/manifest_pc.json","//static.meechat.me/cdn/new.mee.chat/dist/mini.html","//static.meechat.me/cdn/new.mee.chat/dist/robots.txt","//static.meechat.me/cdn/new.mee.chat/dist/sw.js"];
- // let networkFirstList = ['', 'h5.html', 'mini.html'];
- let networkFirstList = [];
- self.addEventListener('install', function (event) {
- self.skipWaiting();
- console.log('[ServiceWorker] install')
- event.waitUntil(
- caches.open(CACHE_NAME).then(function(caches){
- console.log('open cache:' + CACHE_NAME);
- let allList = urlsToCache.concat(networkFirstList)
- return caches.addAll(allList);
- })
- )
- })
- self.addEventListener('activate', function (event) {
- console.log('[ServiceWorker] activate')
- // 只保留白名单的版本
- const cacheWhitelist = [CACHE_NAME];
- event.waitUntil(
- caches.keys().then(function(cacheNames) {
- return Promise.all(
- cacheNames.map(function(cacheName) {
- console.log('遍历缓存:' + cacheName)
- if (cacheWhitelist.indexOf(cacheName) === -1) {
- console.log('删除缓存:' + cacheName)
- return caches.delete(cacheName)
- }
- })
- )
- })
- )
- })
- self.addEventListener('fetch', function (event) {
- // console.log('[ServiceWorker] Fetch', event.request.url)
- let url = event.request.url.replace('https:', '')
- if (urlsToCache.indexOf(url) !== -1) {
- return _cacheFirst(event)
- } else {
- return _networkFirst(event)
- }
- })
- function _cacheFirst(event, response) {
- event.respondWith(
- caches.match(event.request).then(function (response) {
- // Cache hit - return response
- if (response) {
- return response;
- }
- return fetch(event.request);
- })
- );
- }
- function _networkFirst(event) {
- event.respondWith(
- fetch(event.request).then((response) => {
- // console.log('[ServiceWorker] network first, request: ', event.request.url);
- return response
- }).catch (() => {
- caches.match(event.request).then(function (response) {
- // Cache hit - return response
- if (response) {
- // console.log('[ServiceWorker] cache first, From cache:', event.request.url)
- return response;
- }
- // console.log('[ServiceWorker] cache first, From network:', event.request.url)
- return fetch(event.request);
- })
- })
- );
- }
- self.addEventListener('error', function (event) {
- console.log('[ServiceWorker] error', event)
- })
- self.addEventListener('push', function (event) {
- console.log('[Service Worker] 收到通知', event);
- function decodeUnicode (str) {
- str = str.replace(/\\/g, '%')
- str = unescape(str)
- str = str.replace(/%/g, '\\')
- str = str.replace(/\\/g, '')
- return str
- }
- let data = JSON.parse(event.data.text())
- const title = decodeUnicode(data.title)
- const options = {
- body: decodeUnicode(data.content),
- icon: 'img/icons/meechat.png',
- tag: data.tag,
- data: data.data,
- }
- event.waitUntil(self.registration.showNotification(title, options))
- })
- // 点击跳转
- self.addEventListener('notificationclick', function (event) {
- console.log('[Service Worker] 点击通知', event);
- let data = event.notification.data
- let url = data && data.url || 'https://mee.chat/'
- event.notification.close()
- event.waitUntil(
- clients.openWindow(url)
- )
- })
|