diff --git a/img/icon/favicon - 128.ico b/img/icon/favicon - 128.ico deleted file mode 100644 index 8eb32cc..0000000 Binary files a/img/icon/favicon - 128.ico and /dev/null differ diff --git a/img/icon/favicon - 32.ico b/img/icon/favicon - 32.ico deleted file mode 100644 index bf05bc6..0000000 Binary files a/img/icon/favicon - 32.ico and /dev/null differ diff --git a/img/icon/favicon - 64.ico b/img/icon/favicon - 64.ico deleted file mode 100644 index 91c5221..0000000 Binary files a/img/icon/favicon - 64.ico and /dev/null differ diff --git a/img/icon/favicon_128.png b/img/icon/favicon_128.png new file mode 100644 index 0000000..4cbedf7 Binary files /dev/null and b/img/icon/favicon_128.png differ diff --git a/img/icon/favicon_144.png b/img/icon/favicon_144.png new file mode 100644 index 0000000..7d54454 Binary files /dev/null and b/img/icon/favicon_144.png differ diff --git a/img/icon/favicon_32.png b/img/icon/favicon_32.png new file mode 100644 index 0000000..2583cf7 Binary files /dev/null and b/img/icon/favicon_32.png differ diff --git a/img/icon/favicon_64.png b/img/icon/favicon_64.png new file mode 100644 index 0000000..a82493a Binary files /dev/null and b/img/icon/favicon_64.png differ diff --git a/index.html b/index.html index a0dac12..18f07f2 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,14 @@ + + + + diff --git a/js/main.js b/js/main.js index 032ffb3..35fc3a1 100644 --- a/js/main.js +++ b/js/main.js @@ -107,18 +107,22 @@ $(function () { }) }) -//监听网页宽度 -// window.addEventListener('load', function () { -// if (window.innerWidth <= 512) { -// $('.wd').attr('placeholder', '搜索'); -// } else { -// $('.wd').attr('placeholder', '想要搜点什么'); -// } -// window.addEventListener('resize', function () { -// if (window.innerWidth <= 512) { -// $('.wd').attr('placeholder', '搜索'); -// } else { -// $('.wd').attr('placeholder', '想要搜点什么'); -// } -// }) -// }) \ No newline at end of file +// 检测浏览器是否支持SW +function registerServiceWorker() { + // 注册 service worker + return navigator.serviceWorker.register('./js/sw.js').then(registration => { + console.log('注册成功'); + // 返回 + return registration; + }) + .catch(err => { + console.error('注册失败', err); + }); +} +window.onload = function () { + //是否支持 + if (!('serviceWorker' in navigator)) { + return; + } + registerServiceWorker() +} \ No newline at end of file diff --git a/js/set.js b/js/set.js index 966c6f4..bcf4437 100644 --- a/js/set.js +++ b/js/set.js @@ -232,7 +232,7 @@ function setBgImgInit() { pictures[7] = './img/background8.webp'; pictures[8] = './img/background9.webp'; pictures[9] = './img/background10.webp'; - var rd = Math.floor(Math.random()*10); + var rd = Math.floor(Math.random() * 10); $('#bg').attr('src', pictures[rd]) //随机默认壁纸 break; case "2": @@ -698,20 +698,16 @@ $(document).ready(function () { }); // 快捷方式添加按钮点击 - $("#set-quick").click(function (event) { - if ($(this).attr("class") === "on") { - closeSet(); - } else { - openSet(); + $("#set-quick").click(function () { + openSet(); - // 设置内容加载 - setSeInit(); //搜索引擎设置 - setQuickInit(); //快捷方式设置 + // 设置内容加载 + setSeInit(); //搜索引擎设置 + setQuickInit(); //快捷方式设置 - //添加快捷方式 - $("#set-quick-menu").trigger('click'); - $(".set_quick_list_add").trigger('click'); - } + //添加快捷方式 + $("#set-quick-menu").trigger('click'); + $(".set_quick_list_add").trigger('click'); }); // 修改默认搜索引擎 diff --git a/js/sw.js b/js/sw.js new file mode 100644 index 0000000..b167104 --- /dev/null +++ b/js/sw.js @@ -0,0 +1,48 @@ +const CURCACHE = 'CURCACHE_test_1' +const RUNTIME = 'runtime'; +const CURCACHE_URLS = [ + './', + 'index.html' +] +self.addEventListener('install', e => { + e.waitUntil( + //存储缓存路径对应的资源 + caches.open(CURCACHE).then(cache => { + cache.addAll(CURCACHE_URLS) + }).then( + self.skipWaiting() + ) + ) +}) + +//代理请求,使用缓存,请求发送之前 +self.addEventListener('fetch', e => { + e.respondWith( + //缓存是否匹配 + caches.match(e.request).then(function (response) { + if (response != null) { + //命中缓存返回缓存,结束请求 + return response + } + //未命中缓存,正常请求 + return fetch(e.request.url) + }) + ) +}); + +//假设上个版本的key为precache_test_2 反正不等于CURCACHE +self.addEventListener('activate', e => { + e.waitUntil( + //遍历当前缓存keys + caches.keys().then(cacheNames => { + return Promise.all( + cacheNames.map(function (cacheName) { + //是否等于当前key,保留自己 + if (cacheName !== CURCACHE) { + return caches.delete(cacheName); + } + }) + ) + }).then(() => self.clients.claim()) + ) +}) \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..93e56e0 --- /dev/null +++ b/manifest.json @@ -0,0 +1,30 @@ +{ + "name": "Snavigation", + "short_name": "Snavigation", + "display": "standalone", + "start_url": "/", + "theme_color": "#efefef", + "background_color": "#333333", + "icons": [ + { + "src": "img/icon/favicon_32.png", + "sizes": "32x32", + "type": "image/png" + }, + { + "src": "img/icon/favicon_64.png", + "sizes": "64x64", + "type": "image/png" + }, + { + "src": "img/icon/favicon_128.png", + "sizes": "128x128", + "type": "image/png" + }, + { + "src": "img/icon/favicon_144.png", + "sizes": "144x144", + "type": "image/png" + } + ] + } \ No newline at end of file