-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceworker.min.js
1 lines (1 loc) · 10.3 KB
/
serviceworker.min.js
1
const appDomain="sainternet",appProto="https://",appTld=".xyz",appVersion="2.1.2",basePath=`https://${appDomain}.xyz`,resourcePath=`${basePath}/resources`,cssPath=`${resourcePath}/stylesheets`,fontawesomePath=`${resourcePath}/fontawesome-free-6.4.0-web`,googlePath=`${resourcePath}/google`,iconPath=`${resourcePath}/icons`,imgPath=`${resourcePath}/images`,jsPath=`${resourcePath}/javascript`,cacheName=`${appDomain}_v${appVersion}`,cssUrls=[`${fontawesomePath}/css/brands.min.css`,`${fontawesomePath}/css/fontawesome.min.css`,`${googlePath}/css/materialicons.min.css`,`${googlePath}/css/roboto.min.css`,`${googlePath}/css/robotomono.min.css`,`${cssPath}/button_home.min.css`,`${cssPath}/datetime.min.css`,`${cssPath}/img.min.css`,`${cssPath}/material.amber-red.min.css`,`${cssPath}/material.blue_grey-red.min.css`,`${cssPath}/material.blue-red.min.css`,`${cssPath}/material.brown-red.min.css`,`${cssPath}/material.cyan-red.min.css`,`${cssPath}/material.deep_orange-red.min.css`,`${cssPath}/material.deep_purple-red.min.css`,`${cssPath}/material.green-red.min.css`,`${cssPath}/material.grey-red.min.css`,`${cssPath}/material.indigo-red.min.css`,`${cssPath}/material.light_blue-red.min.css`,`${cssPath}/material.light_green-red.min.css`,`${cssPath}/material.lime-red.min.css`,`${cssPath}/material.orange-red.min.css`,`${cssPath}/material.pink-red.min.css`,`${cssPath}/material.red-blue.min.css`,`${cssPath}/material.teal-red.min.css`,`${cssPath}/material.yellow-red.min.css`,`${cssPath}/mono.min.css`,`${cssPath}/party-time.min.css`,`${cssPath}/ribbons.min.css`,`${cssPath}/sainternet.min.css`,`${cssPath}/shadow-boxing.min.css`,`${cssPath}/table.min.css`,],fontUrls=[`${fontawesomePath}/webfonts/fa-brands-400.woff2`,`${googlePath}/webfonts/materialicons/v140/Material-Icons.woff2`,`${googlePath}/webfonts/robotomono/v22/RobotoMono-BoldItalic.woff2`,`${googlePath}/webfonts/robotomono/v22/RobotoMono-Bold.woff2`,`${googlePath}/webfonts/robotomono/v22/RobotoMono-Italic.woff2`,`${googlePath}/webfonts/robotomono/v22/RobotoMono-Regular.woff2`,`${googlePath}/webfonts/roboto/v30/Roboto-Black.woff2`,`${googlePath}/webfonts/roboto/v30/Roboto-Bold.woff2`,`${googlePath}/webfonts/roboto/v30/Roboto-Italic.woff2`,`${googlePath}/webfonts/roboto/v30/Roboto-Medium.woff2`,`${googlePath}/webfonts/roboto/v30/Roboto-Regular.woff2`,],htmlUrls=[`${basePath}/265.html`,`${basePath}/404.html`,`${basePath}/archive.html`,`${basePath}/connecttosainternet.html`,`${basePath}/debug.html`,`${basePath}/devdiary.html`,`${basePath}/dns.html`,`${basePath}/frequentlyaskedquestions.html`,`${basePath}/index.html`,`${basePath}/newsandupdates.html`,`${basePath}/pokedexoverdns.html`,`${basePath}/portsandprotocols.html`,`${basePath}/projects.html`,`${basePath}/reportaproblem.html`,`${basePath}/technologies.html`,`${basePath}/testsainternet.html`,],imageUrls=[`${imgPath}/pihole_percent-day.webp`,`${imgPath}/pihole_percent-week.webp`,`${imgPath}/pihole_percent-month.webp`,`${imgPath}/pihole_percent-year.webp`,`${imgPath}/farquaad.webp`,`${imgPath}/luxio.webp`,`${imgPath}/luxio-shiny.webp`,`${imgPath}/terminal.webp`,`${imgPath}/willow.webp`,`${imgPath}/wurmple.webp`,`${imgPath}/wurmple-shiny.webp`,],iconUrls=[`${basePath}/favicon.ico`,`${iconPath}/favicon/favicon.ico`,`${iconPath}/favicon/favicon-16x16.png`,`${iconPath}/favicon/favicon-24x24.png`,`${iconPath}/favicon/favicon-32x32.png`,`${iconPath}/android-chrome-48x48.png`,`${iconPath}/favicon/favicon-64x64.png`,`${iconPath}/android-chrome-72x72.png`,`${iconPath}/android-chrome-96x96.png`,`${iconPath}/android-chrome-128x128.png`,`${iconPath}/android-chrome-192x192.png`,`${iconPath}/android-chrome-384x384.png`,`${iconPath}/android-chrome-512x512.png`,`${iconPath}/apple-touch-icon-180x180.png`,`${iconPath}/browserconfig.xml`,`${iconPath}/mstile-144x144.png`,`${iconPath}/mstile-150x150.png`,`${iconPath}/safari-pinned-tab.svg`,],jsUrls=[`${jsPath}/console_wrapper.min.js`,`${jsPath}/debug.min.js`,`${jsPath}/load_fonts.min.js`,`${jsPath}/load_mono_fonts.min.js`,`${jsPath}/material.min.js`,`${jsPath}/random_url.min.js`,`${jsPath}/tag_manager.min.js`,`${jsPath}/toggle_drawer.min.js`,`${basePath}/sainternet.min.js`,`${basePath}/serviceworker.min.js`,],screenshotUrls=[`${resourcePath}/screenshots/landscape/debug.webp`,`${resourcePath}/screenshots/landscape/filtereddns.webp`,`${resourcePath}/screenshots/landscape/home.webp`,`${resourcePath}/screenshots/landscape/newsandupdates.webp`,`${resourcePath}/screenshots/landscape/pokedexoverdns.webp`,`${resourcePath}/screenshots/landscape/popularprojects.webp`,`${resourcePath}/screenshots/portrait/debug.webp`,`${resourcePath}/screenshots/portrait/filtereddns.webp`,`${resourcePath}/screenshots/portrait/home.webp`,`${resourcePath}/screenshots/portrait/newsandupdates.webp`,`${resourcePath}/screenshots/portrait/pokedexoverdns.webp`,`${resourcePath}/screenshots/portrait/popularprojects.webp`,],cacheCritical=[...htmlUrls,...cssUrls,...jsUrls,],cacheOnInstall=[...htmlUrls,...iconUrls,...imageUrls,...cssUrls,...jsUrls,...fontUrls,...screenshotUrls,],originDomains=[basePath,];function consoleWrapper(e,o="log",r=!1){r&&(e=`${new Date().toLocaleString()} - ${e}`),self.CONSOLE_LOGGING&&"object"==typeof console&&"function"==typeof console[o]&&console[o](e)}function consoleWrapperSimple(e,o="log"){"object"==typeof console&&"function"==typeof console[o]&&console[o](e)}function fetchCacheUrlArray(e,o){return consoleWrapper(`[Service Worker] Opening ${e}`),caches.open(e).then(r=>Promise.all(o.map(o=>fetch(o).then(e=>{if(e.ok)return r.put(o,e.clone()),consoleWrapper(`[Service Worker] Cached ${o}: ${e.status}`),e;consoleWrapper(`[Service Worker] Failed to cache ${o}: ${e.status}`,"error")}).catch(o=>{consoleWrapper(`[Service Worker] Fetch failed for cache: ${e}`,"error")}))))}function sleepFor(e){e||(e=50*Math.floor(49*Math.random())+100);let o=Date.now();for(;Date.now()<o+e;);}self.addEventListener("activate",function(e){consoleWrapper(`[Service Worker] Event: activate ${appDomain}`);try{self.clients&&clients.claim&&(consoleWrapper("[Service Worker] Claiming available clients"),clients.claim()),e.waitUntil(caches.keys().then(function(e){let o=e.filter(function(e){return e.indexOf(appDomain)});return o.push(cacheName),Promise.all(e.map(function(r,t){if(-1===o.indexOf(r))return console.log(`[Service Worker] Deleting orphaned cache: ${e[t]}`),caches.delete(e[t])}))}))}catch(o){consoleWrapper(`[Service Worker] Error during activate event: ${o}`,"error")}}),self.addEventListener("install",function(e){consoleWrapper(`[Service Worker] Event: install ${appDomain}`);try{e.waitUntil(fetchCacheUrlArray(cacheName,cacheOnInstall).then(function(){return consoleWrapper("[Service Worker] Finished caching critical assets"),self.skipWaiting()}).catch(function(e){consoleWrapper(`[Service Worker] Error during cache fetch: ${e}`,"error")}))}catch(o){consoleWrapper(`[Service Worker] Error during install event: ${o}`,"error")}}),self.addEventListener("fetch",function(e){try{if("GET"!==e.request.method){consoleWrapper(`[Service Worker] Not handling request ${e.request.url} with method ${e.request.method}`);return}let o=new URL(e.request.url);cacheCritical.includes(o.pathname)&&originDomains.some(e=>o.origin.startsWith(e))?e.respondWith(fetch(e.request).then(function(o){if(!o||200!==o.status||"basic"!==o.type)return consoleWrapper(`[Service Worker] Response not eligible for caching: ${e.request.url}`),o;if(originDomains.some(e=>new URL(o.url).origin.startsWith(e))){let r=o.clone();caches.open(cacheName).then(function(o){consoleWrapper(`[Service Worker] Adding response to cache: ${e.request.url}`),o.put(e.request,r)})}return consoleWrapper(`[Service Worker] Returning response from network: ${e.request.url}`),o}).catch(function(o){return consoleWrapper(`[Service Worker] Network fetch failed, falling back to cache for: ${e.request.url}`),caches.match(e.request).then(function(o){return o?consoleWrapper(`[Service Worker] Returning response from cache: ${e.request.url}`):consoleWrapper(`[Service Worker] No response available in cache for: ${e.request.url}`),o})})):e.respondWith(caches.match(e.request).then(function(o){return o?(consoleWrapper(`[Service Worker] Returning response from cache: ${e.request.url}`),o):(consoleWrapper(`[Service Worker] No response available in cache for: ${e.request.url}`),fetch(e.request))}).then(function(o){if(!o||200!==o.status||"basic"!==o.type)return consoleWrapper(`[Service Worker] Response not eligible for caching: ${e.request.url}`),o;let r=o.clone();return caches.open(cacheName).then(function(o){consoleWrapper(`[Service Worker] Adding response to cache: ${e.request.url}`),o.put(e.request,r)}),consoleWrapper(`[Service Worker] Returning response from network: ${e.request.url}`),o}).catch(function(o){consoleWrapper(`[Service Worker] Fetch failed for: ${e.request.url}`)}))}catch(r){consoleWrapper(`[Service Worker] Error during fetch event: ${r}`,"error")}}),self.addEventListener("message",function(e){if("console_logging"===e.data.type){let o=e.data.value;self.CONSOLE_LOGGING=o,consoleWrapper(`[Service Worker] CONSOLE_LOGGING: ${o}`)}else if("info"===e.data)consoleWrapperSimple(`[Service Worker] Name: ${appDomain}`),consoleWrapperSimple(`[Service Worker] Version: ${appVersion}`),consoleWrapperSimple(`[Service Worker] Cache Name: ${cacheName}`),consoleWrapperSimple(`[Service Worker] Base Path: ${basePath}`);else if("ping"===e.data){let r=["My caches are too strong for you, Debug.","You can't handle my caches. They're too strong for you.","My caches would kill you, Debug. You cannot handle my caches.","My strongest caches would kill you, Debug. You can't handle my strongest caches. You'd better go to a seller that sells weaker caches.","You don't know what you ask, Debug. My strongest caches will kill a dragon, let alone a man. You need a seller that sells weaker caches, because my caches are too strong.","You can't handle my strongest caches! No one can! My strongest caches aren't fit for a beast let alone a man.","I can't give you my strongest caches because my strongest caches are only for the strongest beings and you are of the weakest.","That's what you'd better do.","Good. You're not welcome here! My caches are only for the strongest and you're clearly are not of the strongest you're clearly the weakest.","Why respect HTML... when my caches can do anything that you can.",],t=Math.floor(Math.random()*r.length),a=r[t];sleepFor(),consoleWrapperSimple(`[Service Worker] ${a}`)}}),consoleWrapper("[Service Worker] Loaded");