IC save API recipes

Save recipes in IC Helper when using API in console

Ajankohdalta 25.12.2024. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         IC save API recipes
// @namespace    http://tampermonkey.net/
// @version      1.2
// @license      MIT
// @description  Save recipes in IC Helper when using API in console
// @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';

    window.saveapirecipesdata = {
        ogFetch: null,
        start: function () {
            if (document.querySelector('.settings-content')) { // Wait for IC Helper
                this.infinitecraft = window.$nuxt.$root.$children[1].$children[0].$children[0];
                this.ogFetch = window.fetch;
                window.fetch = async function (...args) {
                    const response = window.saveapirecipesdata.ogFetch.apply(this, args);
                    setTimeout(async () => {
                        try{
                            if (args[0] && args[0].split("?")[0] === "https://neal.fun/api/infinite-craft/pair" && !(args[1] && args[1].signal)) {
                                const first = decodeURIComponent(args[0].split("?")[1].split("&")[0].split("=")[1]);
                                const second = decodeURIComponent(args[0].split("?")[1].split("&")[1].split("=")[1]);
                                const clonedResponse = (await response).clone();
                                const result = await clonedResponse.json();
                                await window.addElementToCrafts({
                                    text: first,
                                    emoji: "⬜",
                                }, {
                                    text: second,
                                    emoji: "⬜",
                                }, result.result);
                                console.log("It works!");
                            }
                        } catch (error) {
                            console.error("Failed to add recipe to IC Helper", error);
                        }
                    }, 0);
                    return response;
                }
            } else {
                setTimeout(this.start.bind(this), 200);
            }
        }
    };
    window.saveapirecipesdata.start();

})();