IC Recipe Discoveries

Adds indication if you were the first to get a recipe in Infinite Craft

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         IC Recipe Discoveries
// @namespace    http://tampermonkey.net/
// @version      1.6.1
// @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';

    (window.AT ||= {}).recipediscoverydata = {
        infinitecraft: null,
        testRecipe: async function (first, second) {
            try {
                [first, second] = [first, second].map((s) =>
                    s.toLowerCase().replace(/(^|\s)\S/g, (match) => match.toUpperCase()) // Neal Case
                );
                const response = await fetch(
                    `https://neal.fun/api/infinite-craft/check?first=${first}&second=${second}&result=Nothing` // Request to do the thing
                );
                if (response.status === 500) return true; //  true if recipe doesn't exist
                return false; // false if anything else
            } catch {
                return undefined; // undefined if error
            }
        },
        start: function () {
            if (document.querySelector(".container").__vue__) { // Wait for Nuxt
                this.infinitecraft = document.querySelector(".container").__vue__;
                const ogGCR = this.infinitecraft.getCraftResponse;
                this.infinitecraft.getCraftResponse = async function () { // Patch getCraftReesponse
                    const firstRecipe = await window.AT.recipediscoverydata.testRecipe(arguments[0].text, arguments[1].text); // Check before /pair request
                    const response = await ogGCR.apply(this, arguments); // Do the original request
                    let recheck = false;
                    if (response.result === 'Nothing') {
                        recheck = await window.AT.recipediscoverydata.testRecipe(arguments[0].text, arguments[1].text); // Recheck for 'Nothing'
                    }
                    response.recipeNew = firstRecipe && !recheck; // Assign values
                    response.actuallyNothing = !(recheck === false);
                    // console.log(response); // Log it
                    return response; // And preserve original
                };
            } else {
                setTimeout(this.start.bind(this), 200);
            }
        }
    };
    window.AT.recipediscoverydata.start();
})();