123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const CACHE_NAME = 'MeeChat_v1.3.4';
- let urlsToCache = ["//static.meechat.me/cdn/mee.chat/dist/css/chunk-008bd727.e64410a5.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-0cf37cea.34867b3d.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-161d73df.38b6ce34.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-17f20f02.0b938788.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-1b3ce148.ca822529.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-23212ac5.7b7b6769.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-3ab2e3e3.621d2337.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-3ae6835b.601b91da.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-484a20ba.6c4d2f2f.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-4be0e358.e275999c.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-5471e84e.d1be43b3.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-55ee6bb8.f31f92a7.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-579c6ae2.3f24ef81.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-5b86aac9.a00b706f.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-5c065784.1e2497e0.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-635cf4b6.feb38348.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-652c94c5.9dccaae5.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-6cae8a9b.a8887c6a.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-7a5b2df4.1bca5361.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-b5c34688.af0499b2.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-ba45f5e6.4ad04c39.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-cd485218.2e47c6af.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-common.810cb2af.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-d4f7b56a.eb6f0950.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-dcb2943e.fd3b7528.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-eab6c874.835e2cbb.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-eb681962.3e9566c1.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-fbfb9796.8e1bb200.css","//static.meechat.me/cdn/mee.chat/dist/css/chunk-vendors.98357f41.css","//static.meechat.me/cdn/mee.chat/dist/css/h5.906f4d0f.css","//static.meechat.me/cdn/mee.chat/dist/css/mini.4f843c54.css","//static.meechat.me/cdn/mee.chat/dist/css/pc.17bab69a.css","//static.meechat.me/cdn/mee.chat/dist/favicon.ico","//static.meechat.me/cdn/mee.chat/dist/fonts/element-icons.535877f5.woff","//static.meechat.me/cdn/mee.chat/dist/fonts/element-icons.732389de.ttf","/h5.html","//static.meechat.me/cdn/mee.chat/dist/img/bg.261295d3.jpg","//static.meechat.me/cdn/mee.chat/dist/img/bg.71de928a.jpg","//static.meechat.me/cdn/mee.chat/dist/img/bg.eb029f3a.png","//static.meechat.me/cdn/mee.chat/dist/img/bg2.0b28333d.png","//static.meechat.me/cdn/mee.chat/dist/img/h5_bg.e9487380.png","//static.meechat.me/cdn/mee.chat/dist/img/h5_bg2.21b33271.png","//static.meechat.me/cdn/mee.chat/dist/img/h5_bg3.6f597ff4.png","//static.meechat.me/cdn/mee.chat/dist/img/icon-eth.f49c5cf6.png","//static.meechat.me/cdn/mee.chat/dist/img/icon-meetone.f0168873.png","//static.meechat.me/cdn/mee.chat/dist/img/icon-tele.0c036f6a.png","//static.meechat.me/cdn/mee.chat/dist/img/icon-tele.88177f4a.png","//static.meechat.me/cdn/mee.chat/dist/img/icons/meechat.png","//static.meechat.me/cdn/mee.chat/dist/img/icons/meechat_icon.png","//static.meechat.me/cdn/mee.chat/dist/img/icons/safari-pinned-tab.svg","//static.meechat.me/cdn/mee.chat/dist/img/loading.b4490fa6.gif","//static.meechat.me/cdn/mee.chat/dist/img/login-logo.6f40e8ff.png","//static.meechat.me/cdn/mee.chat/dist/img/meetone-icon.f0168873.jpg","//static.meechat.me/cdn/mee.chat/dist/img/user-ethereum-icon.fdf8b24e.png","//static.meechat.me/cdn/mee.chat/dist/img/user-tron-icon.92300839.png","/index.html","//static.meechat.me/cdn/mee.chat/dist/js/chunk-008bd727.ecaeba85.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-0cf37cea.4ef0ae20.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-161d73df.6ec55b00.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-17f20f02.436a45b6.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-1b3ce148.f35849cc.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-23212ac5.6001b569.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-335f5c5d.ce393556.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-3ab2e3e3.88db71c9.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-3ae6835b.8a2bec32.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-484a20ba.3701ea56.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-4be0e358.e0f9f9ba.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-5471e84e.562382f2.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-55ee6bb8.c0240591.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-579c6ae2.fd5c2e72.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-5b86aac9.aa39519a.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-5c065784.eb5e1941.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-635cf4b6.42b24b50.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-652c94c5.bf9005ca.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-6cae8a9b.cc8468cf.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-7a5b2df4.cbef94b1.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-b5c34688.4b1e9120.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-ba45f5e6.7e5010bd.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-cd485218.b55bcca6.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-common.81672b78.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-d4f7b56a.98532fd0.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-dcb2943e.74d8cafb.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-eab6c874.d4e5a5e4.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-eb681962.ed5b7649.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-fbfb9796.92201770.js","//static.meechat.me/cdn/mee.chat/dist/js/chunk-vendors.1963f991.js","//static.meechat.me/cdn/mee.chat/dist/js/h5.c7a90943.js","//static.meechat.me/cdn/mee.chat/dist/js/mini.aaa48e52.js","//static.meechat.me/cdn/mee.chat/dist/js/pc.eaa283b1.js","/manifest_h5.json","/manifest_pc.json","/mini.html","/pc.html","//static.meechat.me/cdn/mee.chat/dist/robots.txt","//static.meechat.me/cdn/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(location.origin, '')
- url = url.replace('https:', '')
- let pos = url.indexOf('#')
- if (pos > 0) {
- url = url.substr(0, pos)
- }
- if (urlsToCache.indexOf(url) !== -1) {
- return _cacheFirst(event)
- } else {
- return _networkFirst(event)
- }
- })
- function _cacheFirst(event) {
- 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)
- )
- })
|