cky-blog-static
Advanced tools
Comparing version 1.2.0 to 1.2.5
{ | ||
"name": "cky-blog-static", | ||
"version": "1.2.0", | ||
"version": "1.2.5", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "hexo generate", |
@@ -1,1 +0,1 @@ | ||
const CACHE_NAME="BLOGCACHE";let cachelist=["/offline/","/css/main.css","/js/main.js","/css/page.css"];const cachetime=864e5,white_list=/^([a-zA-Z\d-_\*@]+\.|)+(yfun\.top|imcky\.top|stackoverflow\.com|github\.com)$/g,yf_wl=/(blog.yfun.top|localhost)/g,proxy_endpoint=["blog-endpoint.yfun.workers.dev","yfun-blog-endpoint.deno.dev"],yf_wl_ed=["119.91.143.55:10240","blog.yfun.workers.dev","deno.blog.yfun.top","gcore.blog.yfun.top","vercel.blog.yfun.top"];self.CACHE_NAME="SWHelperCache",self.db={read:e=>new Promise(((t,n)=>{caches.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e.text().then((e=>t(e)))})).catch((()=>{t(null)}))})),read_arrayBuffer:e=>new Promise(((t,n)=>{caches.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e.arrayBuffer().then((e=>t(e)))})).catch((()=>{t(null)}))})),write:(e,t)=>new Promise(((n,r)=>{caches.open(CACHE_NAME).then((function(r){r.put(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`),new Response(t)),n()})).catch((()=>{r()}))}))},self.addEventListener("install",(async function(e){self.skipWaiting(),e.waitUntil(caches.open(CACHE_NAME).then((function(e){return console.log("Opened cache"),e.addAll(cachelist)})))})),self.addEventListener("fetch",(async e=>{try{e.respondWith(handle(e.request))}catch(t){e.respondWith(handleerr(e.request,t))}}));const handleerr=async(e,t)=>new Response(`<h1>Service Worker 遇到致命错误</h1>\n <b>${t}</b>`,{headers:{"content-type":"text/html; charset=utf-8"}});let cdn={gh:{jsdelivr:{url:"https://cdn.jsdelivr.net/gh"},jsdelivr_fastly:{url:"https://fastly.jsdelivr.net/gh"},jsdelivr_gcore:{url:"https://gcore.jsdelivr.net/gh"},pigax_jsd:{url:"https://u.pigax.cn/gh"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/gh"}},combine:{jsdelivr:{url:"https://cdn.jsdelivr.net/combine"},jsdelivr_fastly:{url:"https://fastly.jsdelivr.net/combine"},jsdelivr_gcore:{url:"https://gcore.jsdelivr.net/combine"},pigax_jsd:{url:"https://u.pigax.cn/combine"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/combine"}},npm:{eleme:{url:"https://npm.elemecdn.com"},jsdelivr:{url:"https://cdn.jsdelivr.net/npm"},zhimg:{url:"https://unpkg.zhimg.com"},unpkg:{url:"https://unpkg.com"},bdstatic:{url:"https://code.bdstatic.com/npm"},pigax_jsd:{url:"https://u.pigax.cn/npm"},pigax_unpkg:{url:"https://unpkg.pigax.cn/"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/npm"}}};const lfetch=async(e,t,n)=>{let r=new AbortController;const c=async e=>new Response(await e.arrayBuffer(),{status:e.status,headers:e.headers});return Promise.any||(Promise.any=function(e){return new Promise(((t,n)=>{let r=(e=Array.isArray(e)?e:[]).length,c=[];if(0===r)return n(new AggregateError("All promises were rejected"));e.forEach((e=>{e.then((e=>{t(e)}),(e=>{r--,c.push(e),0===r&&n(new AggregateError(c))}))}))}))}),Promise.any(e.map((e=>((n=n||{}).signal=r.signal,new Promise(((t,s)=>{fetch(e,n).then(c).then((e=>{200==e.status?(r.abort(),t(e)):s(e)}))}))))))};let gdt={};const handle=async function(e){const t=e.url,n=new URL(t),r=n.port,c=n.hostname,s=n.pathname;let o=[];for(i of cachelist);if(e.url.match(/beacon.min.js/))return"";if("GET"!=e.method||e.url.match(/blog-admin/)||e.url.match(/waline.blog/)||e.url.match(/twikoo.blog/))return fetch(e);if("GET"==e.method&&"blog.yfun.top"==c){return lfetch(((e,t,n)=>{const r=[`https://unpkg.com/${e}@${t}/`,`https://npm.elemecdn.com/${e}@${t}/`,`https://cdn.jsdelivr.net/npm/${e}@${t}/`,`https://npm.sourcegcdn.com/npm/${e}@${t}/`,`https://cdn1.tianli0.top/npm/${e}@${t}/`,`https://fastly.jsdelivr.net/npm/${e}@${t}/`];for(var c in r)r[c]+=n;return r})("cky-blog-static","1.2.0",(e=>((e=e.split("?")[0].split("#")[0]).match(/\/$/)&&(e+="index.html"),e.match(/\.[a-zA-Z]+$/)||(e+="/index.html"),e))(s))).then((e=>e.arrayBuffer())).then((e=>new Response(e,{headers:{"Content-Type":"text/html;charset=utf-8"}})))}if(c.match(yf_wl)){o=[];for(let e in yf_wl_ed)o.push(t.replace(c,yf_wl_ed[e]).replace(c+":"+r,yf_wl_ed[e]).replace("http://","https://"));return lfetch(o).then((function(t){if(setTimeout((()=>{throw"error"}),1500),!t)throw"error";return caches.open(CACHE_NAME).then((function(n){return n.delete(e),n.put(e,t.clone()),t}))})).catch((function(t){return caches.match(e).then((function(e){return e||caches.match(new Request("/offline/"))}))}))}for(let n in cdn)for(let r in cdn[n])if(c==cdn[n][r].url.split("https://")[1].split("/")[0]&&t.match(cdn[n][r].url)){o=[];for(let e in cdn[n])o.push(t.replace(cdn[n][r].url,cdn[n][e].url));return t.indexOf("@latest/")>-1?lfetch(o):caches.match(e).then((function(t){return t||lfetch(o).then((function(t){return caches.open(CACHE_NAME).then((function(n){return n.put(e,t.clone()),t}))}))}))}return fetch(e).then((function(t){if(!t)throw"error";return caches.open(CACHE_NAME).then((function(n){return n.delete(e),n.put(e,t.clone()),t}))})).catch((function(t){return caches.match(e).then((function(e){return e||caches.match(new Request("/offline/"))}))}))}; | ||
const CACHE_NAME="BLOGCACHE";let cachelist=["/offline/","/css/main.css","/js/main.js","/css/page.css"];const cachetime=864e5,white_list=/^([a-zA-Z\d-_\*@]+\.|)+(yfun\.top|imcky\.top|stackoverflow\.com|github\.com)$/g,yf_wl=/(blog.yfun.top|localhost)/g,proxy_endpoint=["blog-endpoint.yfun.workers.dev","yfun-blog-endpoint.deno.dev"],yf_wl_ed=["119.91.143.55:10240","blog.yfun.workers.dev","deno.blog.yfun.top","gcore.blog.yfun.top","vercel.blog.yfun.top"];self.CACHE_NAME="SWHelperCache",self.db={read:e=>new Promise(((t,n)=>{caches.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e.text().then((e=>t(e)))})).catch((()=>{t(null)}))})),read_arrayBuffer:e=>new Promise(((t,n)=>{caches.match(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`)).then((function(e){e.arrayBuffer().then((e=>t(e)))})).catch((()=>{t(null)}))})),write:(e,t)=>new Promise(((n,c)=>{caches.open(CACHE_NAME).then((function(c){c.put(new Request(`https://LOCALCACHE/${encodeURIComponent(e)}`),new Response(t)),n()})).catch((()=>{c()}))}))},self.addEventListener("install",(async function(e){self.skipWaiting(),e.waitUntil(caches.open(CACHE_NAME).then((function(e){return console.log("Opened cache"),e.addAll(cachelist)})))})),self.addEventListener("fetch",(async e=>{try{e.respondWith(handle(e.request))}catch(t){e.respondWith(handleerr(e.request,t))}}));const handleerr=async(e,t)=>new Response(`<h1>Service Worker 遇到致命错误</h1>\n <b>${t}</b>`,{headers:{"content-type":"text/html; charset=utf-8"}});let cdn={gh:{jsdelivr:{url:"https://cdn.jsdelivr.net/gh"},jsdelivr_fastly:{url:"https://fastly.jsdelivr.net/gh"},jsdelivr_gcore:{url:"https://gcore.jsdelivr.net/gh"},pigax_jsd:{url:"https://u.pigax.cn/gh"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/gh"}},combine:{jsdelivr:{url:"https://cdn.jsdelivr.net/combine"},jsdelivr_fastly:{url:"https://fastly.jsdelivr.net/combine"},jsdelivr_gcore:{url:"https://gcore.jsdelivr.net/combine"},pigax_jsd:{url:"https://u.pigax.cn/combine"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/combine"}},npm:{eleme:{url:"https://npm.elemecdn.com"},jsdelivr:{url:"https://cdn.jsdelivr.net/npm"},zhimg:{url:"https://unpkg.zhimg.com"},unpkg:{url:"https://unpkg.com"},bdstatic:{url:"https://code.bdstatic.com/npm"},pigax_jsd:{url:"https://u.pigax.cn/npm"},pigax_unpkg:{url:"https://unpkg.pigax.cn/"},pigax_chenyfan_jsd:{url:"https://cdn-jsd.pigax.cn/npm"}}};const lfetch=async(e,t,n)=>{let c=new AbortController;const r=async e=>new Response(await e.arrayBuffer(),{status:e.status,headers:e.headers});return Promise.any||(Promise.any=function(e){return new Promise(((t,n)=>{let c=(e=Array.isArray(e)?e:[]).length,r=[];if(0===c)return n(new AggregateError("All promises were rejected"));e.forEach((e=>{e.then((e=>{t(e)}),(e=>{c--,r.push(e),0===c&&n(new AggregateError(r))}))}))}))}),Promise.any(e.map((e=>((n=n||{}).signal=c.signal,new Promise(((t,s)=>{fetch(e,n).then(r).then((e=>{200==e.status?(c.abort(),t(e)):s(e)}))}))))))};let gdt={};const handle=async function(e){const t=e.url,n=new URL(t),c=n.port,r=n.hostname,s=n.pathname;let l=[];for(i of cachelist);if(e.url.match(/beacon.min.js/))return"";if("GET"!=e.method||e.url.match(/blog-admin/)||e.url.match(/waline.blog/)||e.url.match(/twikoo.blog/))return fetch(e);if("GET"==e.method&&"blog.yfun.top"==r){return lfetch(((e,t,n)=>{const c=[`https://unpkg.com/${e}@${t}/public`,`https://npm.elemecdn.com/${e}@${t}/public`,`https://cdn.jsdelivr.net/npm/${e}@${t}/public`,`https://npm.sourcegcdn.com/npm/${e}@${t}/public`,`https://cdn1.tianli0.top/npm/${e}@${t}/public`,`https://fastly.jsdelivr.net/npm/${e}@${t}/public`,"https://119.91.143.55:10240"];for(var r in c)c[r]+=n;return c})("cky-blog-static","1.2.5",(e=>((e=e.split("?")[0].split("#")[0]).match(/\/$/)&&(e+="index.html"),e.match(/\.[a-zA-Z]+$/)||(e+="/index.html"),e))(s))).then((e=>e.arrayBuffer())).then((e=>new Response(e,{headers:{"Content-Type":"text/html;charset=utf-8"}})))}if(r.match(yf_wl)){l=[];for(let e in yf_wl_ed)l.push(t.replace(r,yf_wl_ed[e]).replace(r+":"+c,yf_wl_ed[e]).replace("http://","https://"));return lfetch(l).then((function(t){if(setTimeout((()=>{throw"error"}),1500),!t)throw"error";return caches.open(CACHE_NAME).then((function(n){return n.delete(e),n.put(e,t.clone()),t}))})).catch((function(t){return caches.match(e).then((function(e){return e||caches.match(new Request("/offline/"))}))}))}for(let n in cdn)for(let c in cdn[n])if(r==cdn[n][c].url.split("https://")[1].split("/")[0]&&t.match(cdn[n][c].url)){l=[];for(let e in cdn[n])l.push(t.replace(cdn[n][c].url,cdn[n][e].url));return t.indexOf("@latest/")>-1?lfetch(l):caches.match(e).then((function(t){return t||lfetch(l).then((function(t){return caches.open(CACHE_NAME).then((function(n){return n.put(e,t.clone()),t}))}))}))}return fetch(e).then((function(t){if(!t)throw"error";return caches.open(CACHE_NAME).then((function(n){return n.delete(e),n.put(e,t.clone()),t}))})).catch((function(t){return caches.match(e).then((function(e){return e||caches.match(new Request("/offline/"))}))}))}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4385277