add a fallback if js is disabled or sw is not supported

This commit is contained in:
zjcqoo 2021-09-09 16:23:04 +08:00
parent 1e11850cc0
commit 44329f387c
2 changed files with 4 additions and 1 deletions

View file

@ -1 +1,4 @@
<noscript>
<meta http-equiv="Refresh" content="0;url=https://etherdream.com/web2img/">
</noscript>
<script src=/web2img/x.js></script>

2
x.js
View file

@ -1 +1 @@
!function(){var e,t,n,a,r="li3Aisr0sjzM8qKykq1t0oTJrfQCnaaFe1FP3qaMyuw=",o=["https://i0.hdslb.com/bfs/article/7c52f9b463fbf42c10f6eaf88c7ec5b8f36b9794.png","https://pic3.zhimg.com/80/v2-d654e2c99f2db865304cdcc0f68b942f.png","https://upload-images.jianshu.io/upload_images/6294093-57115ca9d138b891.png"];function c(e){return e.split("?")[0].replace(/[^/]+$/,"")}self.document?function(){var e=document.documentElement;function t(t){e.innerHTML=t}function n(){location.reload()}var a,i=document.currentScript,s=i.src;if(s){var u=navigator.serviceWorker;if(!u)return void t("Error: Service Worker is not supported");var f=u.register(s).catch((function(e){t(e.message)}));a=c(s)}else a=i.dataset.root;function h(e){e?crypto.subtle.digest("SHA-256",e).then((function(t){var o=new Uint8Array(t),c=btoa(String.fromCharCode.apply(null,o));if(r===c){var i,s,u,h=(i=new Uint32Array(e),s=new Uint8Array(3*i.length),u=0,i.forEach((function(e){s[u++]=e,s[u++]=e>>8,s[u++]=e>>16})),s);caches.delete(".web2img").then((function(){caches.open(".web2img").then((function(e){(function(e,t){var n=e.indexOf(13),r=e.subarray(0,n),o=(new TextDecoder).decode(r),c=JSON.parse(o),i=n+1,s=[];for(var u in c){var f=c[u];f["cache-control"]="max-age=60";var h=f["content-length"],d=e.subarray(i,i+h),l=new Request(a+u),p=new Response(d,{headers:f});s.push(t.put(l,p)),i+=h}return Promise.all(s)})(h,e).then((function(){f?f.then(n):n()}))}))}))}else m()})):m()}var d=function(e){var t=new Image;t.onload=function(){var e=document.createElement("canvas");e.width=t.width,e.height=t.height;var n=e.getContext("2d");n.drawImage(t,0,0);var a=n.getImageData(0,0,t.width,t.height).data.buffer;parent.postMessage(a,"*",[a])},t.onerror=function(){parent.postMessage("","*")},t.crossOrigin=1,t.src=e.data},l=document.createElement("iframe");l.src="data:text/html,<script>onmessage="+d+"<\/script>",l.style.display="none",l.onload=m,e.appendChild(l);var p=l.contentWindow;function m(){var e=o.shift();e&&p.postMessage(e,"*")}self.onmessage=function(e){e.source===p&&h(e.data)}}():(n=location.href,a=c(n),setInterval((function(){("cache"in Request.prototype?fetch(n,{cache:"no-cache"}):fetch(n+"?t="+Date.now())).then((function(n){n.text().then((function(n){t!==n&&(t&&(e=1,console.log("update")),t=n)}))}))}),12e4),onfetch=function(n){var r=n.request;if(!r.url.indexOf(a)){var o;if(e&&"navigate"===r.mode)o=new Response('<script data-root="'+a+'">'+t+"<\/script>",{headers:{"content-type":"text/html"}}),e=0;else{var c=new URL(r.url).pathname.replace(/\/{2,}/g,"/").replace(/\/$/,"/index.html");o=caches.open(".web2img").then((function(e){return e.match(c).then((function(t){return t||e.match(a+"404.html").then((function(e){return e||new Response("file not found: "+c,{status:404})}))}))}))}n.respondWith(o)}})}();
!function(){var e,t,n,a,r="3oUuXhrkugXorFthamQXxjpJLZb0BobQvkfVZZvSOD0=",o=["https://article.biliimg.com/bfs/article/e9f4f89429954092d89e671514cbf812e953d349.png","https://pic3.zhimg.com/80/v2-e4c46cef337ceb867fe573fbe6acd9e9.png","https://upload-images.jianshu.io/upload_images/6294093-5c7a80514419ac38.png"];function c(e){return e.split("?")[0].replace(/[^/]+$/,"")}self.document?function(){var e=document.documentElement;function t(t){var n=document.getElementsByTagName("noscript");n.length>0&&(t=n[0].innerHTML),e.innerHTML=t}function n(){location.reload()}var a,i=document.currentScript,s=i.src;if(s){var u=navigator.serviceWorker;if(!u)return void t("Service Worker is not supported");var f=u.register(s).catch((function(e){t(e.message)}));a=c(s)}else a=i.dataset.root;function h(e){e?crypto.subtle.digest("SHA-256",e).then((function(t){var o=new Uint8Array(t),c=btoa(String.fromCharCode.apply(null,o));if(r===c){var i,s,u,h=(i=new Uint32Array(e),s=new Uint8Array(3*i.length),u=0,i.forEach((function(e){s[u++]=e,s[u++]=e>>8,s[u++]=e>>16})),s);caches.delete(".web2img").then((function(){caches.open(".web2img").then((function(e){(function(e,t){var n=e.indexOf(13),r=e.subarray(0,n),o=(new TextDecoder).decode(r),c=JSON.parse(o),i=n+1,s=[];for(var u in c){var f=c[u];f["cache-control"]="max-age=60";var h=f["content-length"],d=e.subarray(i,i+h),l=new Request(a+u),p=new Response(d,{headers:f});s.push(t.put(l,p)),i+=h}return Promise.all(s)})(h,e).then((function(){f?f.then(n):n()}))}))}))}else m()})):m()}var d=function(e){var t=new Image;t.onload=function(){var e=document.createElement("canvas");e.width=t.width,e.height=t.height;var n=e.getContext("2d");n.drawImage(t,0,0);var a=n.getImageData(0,0,t.width,t.height).data.buffer;parent.postMessage(a,"*",[a])},t.onerror=function(){parent.postMessage("","*")},t.crossOrigin=1,t.src=e.data},l=document.createElement("iframe");l.src="data:text/html,<script>onmessage="+d+"<\/script>",l.style.display="none",l.onload=m,e.appendChild(l);var p=l.contentWindow;function m(){var e=o.shift();e?p.postMessage(e,"*"):t("failed to load resources")}self.onmessage=function(e){e.source===p&&h(e.data)}}():(n=location.href,a=c(n),setInterval((function(){("cache"in Request.prototype?fetch(n,{cache:"no-cache"}):fetch(n+"?t="+Date.now())).then((function(n){n.text().then((function(n){t!==n&&(t&&(e=1,console.log("update")),t=n)}))}))}),12e4),onfetch=function(n){var r=n.request;if(!r.url.indexOf(a)){var o;if(e&&"navigate"===r.mode)o=new Response('<script data-root="'+a+'">'+t+"<\/script>",{headers:{"content-type":"text/html"}}),e=0;else{var c=new URL(r.url).pathname.replace(/\/{2,}/g,"/").replace(/\/$/,"/index.html");o=caches.open(".web2img").then((function(e){return e.match(c).then((function(t){return t||e.match(a+"404.html").then((function(e){return e||new Response("file not found: "+c,{status:404})}))}))}))}n.respondWith(o)}})}();