Skip to content

Commit

Permalink
wpa test
Browse files Browse the repository at this point in the history
  • Loading branch information
底层用户 committed Mar 22, 2022
1 parent 52431d9 commit 2513963
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 28 deletions.
Binary file removed img/icon/favicon - 128.ico
Binary file not shown.
Binary file removed img/icon/favicon - 32.ico
Binary file not shown.
Binary file removed img/icon/favicon - 64.ico
Binary file not shown.
Binary file added img/icon/favicon_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon/favicon_144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon/favicon_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icon/favicon_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<script type="text/javascript"
src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/izitoast/1.4.0/js/iziToast.min.js">
</script>
<!-- PWA -->
<link rel="manifest" href="manifest.json">
<!-- IE Out -->
<script>
if ( /*@cc_on!@*/ false || (!!window.MSInputMethodContext && !!document.documentMode)) window.location.href =
"https://www.imsyy.top/upgrade-your-browser/index.html?referrer=" + encodeURIComponent(window.location
.href);
</script>
</head>

<body>
Expand Down
34 changes: 19 additions & 15 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '想要搜点什么');
// }
// })
// })
// 检测浏览器是否支持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()
}
22 changes: 9 additions & 13 deletions js/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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');
});

// 修改默认搜索引擎
Expand Down
48 changes: 48 additions & 0 deletions js/sw.js
Original file line number Diff line number Diff line change
@@ -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())
)
})
30 changes: 30 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit 2513963

Please sign in to comment.