1/* eslint-disable eqeqeq */ 2/* eslint-disable consistent-return */ 3/* eslint-disable comma-dangle */ 4/* eslint-disable prefer-template */ 5/* eslint-disable vars-on-top */ 6/* eslint-disable block-spacing */ 7/* eslint-disable space-before-function-paren */ 8/* eslint-disable func-names */ 9/* eslint-disable prefer-arrow-callback */ 10/* eslint-disable no-restricted-globals */ 11/* eslint-disable quotes */ 12/* eslint no-var: off */ 13/* eslint no-console: off */ 14/* global fetch self caches */ 15var hostReplacer = {} 16function checkReplacer() { 17 return fetch(self.location.origin.replace("//app.", "//api.") + "/api/host/replacer") 18 .then(function(res) {return res.json()}) 19 .then(function(r) {hostReplacer = r.data || {}}) 20 .catch(function(error) {console.error(error)}) 21} 22setInterval(checkReplacer, 60000) 23 24function replaceHost(host) { 25 var arr = host.split(":") 26 for (var key in hostReplacer) { 27 if (key == arr[0]) return hostReplacer[key] + (arr[1] ? ":" + arr[1] : "") 28 } 29 return host 30} 31 32function fetchWithCache(event, _fetch) { 33 event.respondWith( 34 caches.match(event.request, {ignoreSearch: true}).then(function(result) { 35 if (result && result.ok) return result 36 return _fetch.then(function(resp) { 37 if (resp.status == 200) { 38 return caches.open("resource-cache").then(function(cache) { 39 cache.put(event.request, resp.clone()) 40 return resp 41 }) 42 } 43 return resp 44 }) 45 }) 46 ) 47} 48 49self.addEventListener("fetch", function(event) { 50 var url = new URL(event.request.url) 51 var host = replaceHost(url.host) 52 if (host != url.host && event.request.method == "GET") {
53 fetchWithCache(event, fetch(url.protocol + "//" + host + url.pathname + url.search)) 54 } 55}) 56 57self.addEventListener("install", function(event) { 58 if (!this.createImageBitmap) { 59 return event.waitUntil(self.skipWaiting()) 60 } 61 event.waitUntil(checkReplacer().then(function() {self.skipWaiting()})) 62})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.