IC Recipe Discoveries

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();