123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const CACHE_NAME = 'MeeChat_v1.3.2';
- let urlsToCache = ["//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-063fcdb8.7be96541.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-09f52bd0.ca822529.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-13ce04b3.c32784d3.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-1a0d9872.38acc50c.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-3028e170.7b7b6769.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-352466e2.33bf20c7.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-4031c6b3.7da7025b.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-406bac5b.09a98095.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-5edd596e.b281c6c1.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-60cf0727.8aef334d.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-6361f770.e85683b9.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-70ed3fb8.1e2497e0.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-81a02e6e.3f6e1708.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-9c4fb57e.64cec1de.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-af4b672c.7675f3ca.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-b17cf818.1737301f.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-common.54d70dac.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-e1f20b62.85f54eab.css","//static.meechat.me/cdn/new.mee.chat/dist/css/chunk-vendors.3c668f4e.css","//static.meechat.me/cdn/new.mee.chat/dist/css/h5.2b5c3223.css","//static.meechat.me/cdn/new.mee.chat/dist/css/mini.0dd5dfbc.css","//static.meechat.me/cdn/new.mee.chat/dist/css/pc.f971b1c8.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/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-063fcdb8.798b1a6d.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-09f52bd0.d2e9708e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-13ce04b3.70600354.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-1a0d9872.538ddd15.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-3028e170.3eb28481.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-352466e2.138e2076.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-4031c6b3.ad6d0512.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-406bac5b.42fd3a0b.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-437e2b39.45c774a4.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-580cf024.6d91d8a1.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-5a6c5be1.8f254aeb.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-5edd596e.2e2447ac.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-60cf0727.4ed4f03c.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6361f770.ca83e7db.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6c021ec0.bf9abc4d.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-6f498702.49ae0a3c.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-70ed3fb8.2dec353d.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-81a02e6e.9036a0ab.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-9c4fb57e.048ea10e.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-af4b672c.d53fdfff.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-b17cf818.d6fe0076.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-common.313e9482.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-d42f0a14.7902d069.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-e1f20b62.d4fd79e3.js","//static.meechat.me/cdn/new.mee.chat/dist/js/chunk-vendors.8a48f48a.js","//static.meechat.me/cdn/new.mee.chat/dist/js/h5.c2e8b53b.js","//static.meechat.me/cdn/new.mee.chat/dist/js/mini.17d215b8.js","//static.meechat.me/cdn/new.mee.chat/dist/js/pc.d3d61ab8.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)
- )
- })
|