123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const CACHE_NAME = 'MeeChat_v1.3.3';
- let urlsToCache = ["//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-074cda02.71019e7c.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-0a2f1101.a926c3e5.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-0a63248c.d6883bf2.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-1a710e5c.6c4d2f2f.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-1e6a2ebb.35199dcf.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-20f2b187.3f1792fa.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-2e7e4d8a.1657fb5f.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-3028e170.7b7b6769.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-38822a98.601b91da.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-42e7d288.90421a20.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-451c71fa.ab91c1a1.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-5aae9c76.ca822529.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6e987cd2.9dccaae5.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6f498702.a8887c6a.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-70ed3fb8.1e2497e0.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-72b48984.43d8db4c.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-79914fca.2512f81b.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-7bbde94a.eb6f0950.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-7d4da030.e64410a5.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-90cf752e.94ab0962.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-a7081a9a.ecdaf94d.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-acbed89a.9d1d67ea.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-c173b1d8.41b3f531.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-common.a39d5ac5.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-d3efe52c.feb38348.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-e59b4412.ac7535b9.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-f0006e14.70577f6e.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-vendors.cb2042b6.css","//static.meechat.me/cdn/new.mee.chat/dist/css/h5.906f4d0f.css","//static.meechat.me/cdn/new.mee.chat/dist/css/mini.6b1598b2.css","//static.meechat.me/cdn/new.mee.chat/dist/css/pc.654ee091.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","/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-meetone.f0168873.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/meetone-icon.f0168873.jpg","//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","/index.html","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-074cda02.ca1f7e12.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-0a2f1101.5159ac5f.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-0a63248c.9bacc565.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-1a710e5c.ceded4fd.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-1e6a2ebb.4fce0ef8.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-20f2b187.2d8a8193.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-2781551f.e15f59ab.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-2e7e4d8a.e65c24bc.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-3028e170.7d2a6a48.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-335f5c5d.f952e588.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-38822a98.79456dd0.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-42e7d288.3254b60a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-451c71fa.5bae3ed4.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-5aae9c76.b6bb866e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6e987cd2.85f6b536.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6f498702.d5b08b1e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-70ed3fb8.254bd166.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-72b48984.3c34b4e0.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-79914fca.2ce513c7.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-7bbde94a.6c1ca0ed.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-7d4da030.1fc39434.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-90cf752e.d626be18.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-a7081a9a.9f34ac64.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-acbed89a.d83faa22.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-c173b1d8.602dbbc8.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-common.9ab8a535.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-d3efe52c.cc5d6c4d.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-e59b4412.e236ce4a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-f0006e14.c5701570.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-vendors.67faea15.js","//static.meechat.me/cdn/new.mee.chat/dist/js/h5.db51f21a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/mini.dbaa3f75.js","//static.meechat.me/cdn/new.mee.chat/dist/js/pc.41a8c581.js","/manifest_h5.json","/manifest_pc.json","/mini.html","/pc.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(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)
- )
- })
|