(function (coomerCreators, kemonoCreators) {
  const coomerDomain = "coomer.su";
  const kemonoDomain = "kemono.su";
  const config = {
    creators: {
      ...coomerCreators,
      ...kemonoCreators,
    },
    domains: {
      "onlyfans.com": [coomerDomain, "onlyfans"],
      "fansly.com": [coomerDomain, "fansly"],
      "candfans.jp": [coomerDomain, "candfans"],
      "patreon.com": [kemonoDomain, "patreon"],
      "fantia.jp": [kemonoDomain, "fantia"],
      "boosty.to": [kemonoDomain, "boosty"],
      "gumroad.com": [kemonoDomain, "gumroad"],
      "subscribestar.adult": [kemonoDomain, "subscribestar"],
      "fanbox.cc": [kemonoDomain, "fanbox"],
    },
    handlers: {
      onlyfans: () => {
        console.log("[🦜] onlyfans called");
        // https://onlyfans.com/belledelphine
        let parsed = new URL(location.href);
        let id = parsed.pathname.split("/")[1];
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      fansly: () => {
        console.log("[🦜] fansly called");
        // https://fansly.com/Morgpie
        let parsed = new URL(location.href);
        let id = parsed.pathname.split("/")[1];
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.name === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], creator.id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      candfans: () => {
        console.log("[🦜] candfans called");
        // Find an image with a similar url to this
        // data-src="https://image.candfans.jp/user/154310/profile/i0YW0NNR864lVp7s7dHYhfg25rqJgeLx2ulzAEMG.png"
        let imgs = document.querySelectorAll("img[data-src]");
        let pattern =
          /https:\/\/image\.candfans\.jp\/user\/(\d+)\/profile\/.*\.\w+/i;
        let id;
        for (let i = 0; i < imgs.length; i++) {
          let img = imgs[i];
          let src = img.getAttribute("data-src");
          let match = src.match(pattern);
          if (match) {
            id = match[1];
            break;
          }
        }
        if (!id) return;
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      patreon: () => {
        console.log("[🦜] patreon called");
        let parsed = new URL(location.href);
        let id = parsed.searchParams.get("u");
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      fantia: () => {
        console.log("[🦜] fantia called");
        // https://fantia.jp/fanclubs/83679
        let parsed = new URL(location.href);
        let id = parsed.pathname.split("/")[2];
        clearInterval(looper);
        let dd = figureDomain();
        let dest = locationGen(dd[0], dd[1], id);
        if (confirm("Redirecting to " + dest)) {
          location.href = dest;
        }
      },
      boosty: () => {
        console.log("[🦜] boosty called");
        // https://boosty.to/temikmiu
        let parsed = new URL(location.href);
        let id = parsed.pathname.split("/")[1];
        clearInterval(looper);
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      gumroad: () => {
        console.log("[🦜] gumroad called");
        let id = JSON.parse(
          document.querySelector(`script[data-component-name="Profile"]`)
            .textContent
        ).creator_profile.external_id;
        clearInterval(looper);
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      subscribestar: () => {
        console.log("[🦜] subscribestar called");
        // https://subscribestar.adult/slugbox
        let parsed = new URL(location.href);
        let id = parsed.pathname.split("/")[1];
        clearInterval(looper);
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
      fanbox: () => {
        console.log("[🦜] fanbox called");
        // <script type="application/ld+json">[{"@context":"http:\/\/schema.org","@type":"CollectionPage","author":{"@type":"Person","name":"M\u3060S\u305f\u308d\u3046","url":"https:\/\/msmspc.fanbox.cc\/"},"description":"M\u3060S\u305f\u308d\u3046\u3067\u3059\u3002\u8910\u8272\u30a4\u30e9\u30b9\u30c8\u30ec\u30fc\u30bf\u30fc\u3068\u3057\u3066\u6d3b\u52d5\u3057\u3066\u304a\u308a\u307e\u3059\u3002\n\n\u3053\u3053\u3067\u306fR18 \u30e9\u30d5\u30fb\u4e0b\u66f8\u304d\u30fb\u3089\u304f\u304c\u304d\u30fb\u8584\u3044\u4fee\u6b63\u30fb\u540c\u4eba\u8a8c\u3092\u30d7\u30e9\u30f3\u5225\u306b\u898b\u3089\u308c\u307e\u3059\u3002\n\u4eca\u307e\u3067\u306b\u7121\u6148\u60b2\u306a\u4fee\u6b63\u3055\u308c\u305f\u300c\u8584\u3044\u4fee\u6b63\u753b\u50cf\u300d\u3092\u4e0a\u3052\u3066\u3044\u304d\u307e\u3059\u3002\npixiv\u898f\u5b9a\u306e\u7bc4\u56f2\u5185\u3067\u306e\u4fee\u6b63\u306a\u306e\u3067\u3054\u4e86\u627f\u304f\u3060\u3055\u3044\u307e\u3059\u3088\u3046\u304a\u9858\u3044\u81f4\u3057\u307e\u3059\u3002\n\n","headline":"M\u3060S\u305f\u308d\u3046","image":"https:\/\/pixiv.pximg.net\/c\/1200x630_90_a2_g5\/fanbox\/public\/images\/creator\/3316400\/cover\/mZXFThZDHXtQspHbtZGwBLTl.jpeg","mainEntityOfPage":"https:\/\/msmspc.fanbox.cc\/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","height":"56","url":"https:\/\/s.pximg.net\/common\/image\/fanbox\/logo_s.png","width":"411"},"name":"pixivFANBOX"}},{"@context":"http:\/\/schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","item":{"@id":"https:\/\/msmspc.fanbox.cc\/","name":"M\u3060S\u305f\u308d\u3046"},"position":1}]}]</script>
        let el = document.querySelector("script[type='application/ld+json']");
        let dat = JSON.parse(el.textContent);
        // 'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/creator/3316400/cover/mZXFThZDHXtQspHbtZGwBLTl.jpeg'
        // 3316400 = id
        let img = dat[0].image;
        let pattern =
          /https:\/\/.*\/fanbox\/public\/images\/creator\/(\d+)\/cover\/.*\.\w+/i;
        let match = img.match(pattern);
        if (!match) return;
        let id = match[1];
        let dd = figureDomain();
        let dCreators = config.creators[dd[1]];
        for (const key in dCreators) {
          if (Object.hasOwnProperty.call(dCreators, key)) {
            const creator = dCreators[key];
            if (creator.id === id) {
              clearInterval(looper);
              let dest = locationGen(dd[0], dd[1], id);
              if (confirm("Redirecting to " + dest)) {
                location.href = dest;
              }
              break;
            }
          }
        }
      },
    },
  };
  function locationGen(domain, service, id) {
    let l = `https://${domain}/${service}/user/${id}`;
    return l;
  }
  function figureDomain() {
    for (const key in config.domains) {
      if (config.domains.hasOwnProperty(key)) {
        const domain = config.domains[key];
        if (location.host.endsWith("." + key) || location.host == key) {
          return domain;
        }
      }
    }
    return null;
  }
  // coomerCreators = null; // This is to reduce memory costs
  // kemonoCreators = null; // This is to reduce memory costs
  // function fn() {
  //   const domains = {
  //     "onlyfans.com": [coomerDomain, "onlyfans"],
  //     "fansly.com": [coomerDomain, "fansly"],
  //     "candfans.jp": [coomerDomain, "candfans"],
  //     "patreon.com": [kemonoDomain, "patreon"],
  //     "fantia.jp": [kemonoDomain, "fantia"],
  //   };
  //   if (domains[location.host]) {
  //     const service = domains[location.host][1];
  //     let id = location.pathname.split("/")[2];
  //     if (service === "candfans") {
  //       // Find an image with a similar url to this
  //       // data-src="https://image.candfans.jp/user/154310/profile/i0YW0NNR864lVp7s7dHYhfg25rqJgeLx2ulzAEMG.png"
  //       let imgs = document.querySelectorAll("img[data-src]");
  //       let pattern =
  //         /https:\/\/image\.candfans\.jp\/user\/(\d+)\/profile\/.*\.\w+/i;
  //       for (let i = 0; i < imgs.length; i++) {
  //         let img = imgs[i];
  //         let src = img.getAttribute("data-src");
  //         let match = src.match(pattern);
  //         if (match) {
  //           id = match[1];
  //           break;
  //         }
  //       }
  //     } else if (service === "patreon") {
  //       // https://www.patreon.com/user?u=5564244
  //       let parsed = new URL(location.href);
  //       id = parsed.searchParams.get("u");
  //     } else if (service == "fantia") {
  //       // https://fantia.jp/fanclubs/83679
  //       let parsed = new URL(location.href);
  //       id = parsed.pathname.split("/")[2];
  //     }
  //     let dCreators = creators[domains[location.host]];
  //     for (const key in dCreators) {
  //       if (Object.hasOwnProperty.call(dCreators, key)) {
  //         const creator = dCreators[key];
  //         if (creator.id === id) {
  //           clearInterval(looper);
  //           let dest = locationGen(domains[location.host][0], service, id);
  //           if (confirm("Redirecting to " + dest)) {
  //             location.href = dest;
  //           }
  //           break;
  //         }
  //       }
  //     }
  //   }
  // }
  function fn() {
    let dd = figureDomain();
    if (dd === null) return;
    let [destDomain, service] = dd;
    config.handlers[service]();
  }
  let looper = setInterval(fn, 1000);
  fn();
})(require("./coomer.su-modded.json"), require("./kemono.su-modded.json"));
