IC Recipe Discoveries

Adds indication if you were the first to get a recipe in infinite craft

目前為 2024-12-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         IC Recipe Discoveries
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license MIT
// @description  Adds indication if you were the first to get a recipe in infinite craft
// @icon         https://i.imgur.com/WlkWOkU.png
// @author       @activetutorial on discord
// @match        https://neal.fun/infinite-craft/
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  function waitForNuxt() {
    if (window.$nuxt && window.$nuxt.$root && window.$nuxt.$root.$children[1] && window.$nuxt.$root.$children[1].$children[0]) {
      const ogGCR = window.$nuxt.$root.$children[1].$children[0].$children[0].getCraftResponse;

      window.$nuxt.$root.$children[1].$children[0].$children[0].getCraftResponse =
        async function () {
          const firstRecipe = await testRecipe(arguments[0].text, arguments[1].text);
          var thething = ogGCR.apply(this, arguments);
          const recheck = await testRecipe(arguments[0].text, arguments[1].text); // Recheck for 'Nothing' edge case
          thething = thething.then((result) => {
            result.recipeNew =
              firstRecipe && (!recheck || result.result != "Nothing"); // true if it didn't exist before crafting, and is either not 'Nothing' or if it created the recipe to exist.
            return Promise.resolve(result);
          });
          return thething;
        };
    } else {
      setTimeout(waitForNuxt, 100);
    }
  }

  // Start checking for $nuxt initialization
  waitForNuxt();

  async function testRecipe(first, second) { // Tests if recipe exists
    try {
      [first, second] = [first, second].map((s) =>
        s.toLowerCase().replace(/(^|\s)\S/g, (match) => match.toUpperCase())
      );
      const response = await fetch(
        `https://neal.fun/api/infinite-craft/check?first=${first}&second=${second}&result=Nothing`
      );
      if (response.status === 500) return true; // Response code 500 means the recipe doesn't exist
      return false;
    } catch {
      return undefined;
    }
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址