self.importScripts('idb-keyval.js');

var aliases = {
  index: /^https?:\/\/[^/]+\/(index.html)?$/,
};

var configs;
var updateConfig = (function () {
  var updating;
  var recheck;
  updateConfig();

  return updateConfig;

  function updateConfig() {
    if (updating) return recheck = true;
    updating = true;
    return idbKeyval.get("hookConfigs").then(onConfig);
  }

  function onConfig(newConfigs) {
    if ((configs || newConfigs) && JSON.stringify(newConfigs) !== JSON.stringify(configs)) {
      configs = newConfigs;
      console.log("Hook Configs Updated");
      console.log(configs);
    }
    updating = false;
    if (!recheck) return;
    recheck = false;
    return updateConfig();
  }
}());

self.addEventListener('install', event => {
  // Bypass the waiting lifecycle stage,
  // just in case there's an older version of this SW registration.
  event.waitUntil(self.skipWaiting());
});

self.addEventListener('activate', event => {
  // Take control of all pages under this SW's scope immediately,
  // instead of waiting for reload/navigation.
  event.waitUntil(self.clients.claim());
});

self.addEventListener('message', updateConfig);

self.addEventListener('fetch', event => {
  updateConfig();
  // If there are no custom configs (default state in production), do nothing.
  if (!configs) return;

  var url = event.request.url;
  console.log("fetch", event.request.url);

  // Look for matching configured hooks
  var keys = Object.keys(configs);
  for (var i = 0, l = keys.length; i < l; i++) {
    var key = keys[i];
    if (aliases[key] ? aliases[key].test(url) : key === url) {
      var customUrl = configs[key];
      console.warn("URL override via custom hook", url, customUrl);
      return event.respondWith(fetch(customUrl));
    }
  }

});

@@ -39,80 +39,12 @@
 var 
-aliases = %7B%0A  index: /%5Ehttps?:%5C/%5C/%5B%5E/%5D+%5C/(index.html)?$/,%0A%7D;%0A%0Avar config
+hook
 s;%0Av
@@ -321,20 +321,17 @@
 nConfig(
-newC
+c
 onfigs) 
@@ -339,17 +339,16 @@
 %0A    if 
-(
 (configs
@@ -355,107 +355,174 @@
  %7C%7C 
-newConfigs) && JSON.stringify(newConfigs) !== JSON.stringify(configs)) %7B%0A      configs = newConfigs
+hooks) %7B%0A      hooks = %5B%5D;%0A      for (var key in configs) %7B%0A        hooks.push(new RegExp(key), configs%5Bkey%5D);%0A      %7D%0A      if (hooks.length === 0) hooks = undefined
 ;%0A  
@@ -1299,22 +1299,20 @@
 %0A  if (!
-config
+hook
 s) retur
@@ -1434,43 +1434,8 @@
 oks%0A
-  var keys = Object.keys(configs);%0A
   fo
@@ -1452,19 +1452,20 @@
  0, l = 
-key
+hook
 s.length
@@ -1478,18 +1478,21 @@
 l; i
-++
+ += 2
 ) %7B%0A    
 var 
@@ -1491,124 +1491,91 @@
     
-var key = keys%5Bi%5D;%0A    if (aliases%5Bkey%5D ? aliases%5Bkey%5D.test(url) : key === url) %7B%0A      var customUrl = configs%5Bkey%5D
+if (hooks%5Bi%5D.test(url)) %7B%0A      var customUrl = url.replace(hooks%5Bi%5D, hooks%5Bi + 1%5D)
 ;%0A  

Use more generic url hooks