Infinite Craft Random Button (2025 Fixed Version)

Drop two random elements into Infinite Craft play area with one click

2025-04-09 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Infinite Craft Random Button (2025 Fixed Version)
// @namespace    http://your-namespace.example
// @version      2025.04.09
// @description  Drop two random elements into Infinite Craft play area with one click
// @author       You
// @match        https://neal.fun/infinite-craft/
// @grant        none
// @license MIT
// ==/UserScript==

(async function () {
    'use strict';

    const wait = (ms) => new Promise((r) => setTimeout(r, ms));

    // Wait for Vue app to load
    while (!document.querySelector('.container')?.__vue__) {
        await wait(100);
    }

    const app = document.querySelector('.container').__vue__;
    const main = app.$children[0] || app;

    const getItems = () => Array.from(document.querySelectorAll('.items .item'));
    const getRandomItem = () => {
        const items = getItems();
        return items[Math.floor(Math.random() * items.length)];
    };

    const getCenterCoords = (offsetY = 0) => {
        const x = window.innerWidth / 2;
        const y = window.innerHeight / 2 + offsetY;
        return [x, y];
    };

    // Create the button
    const randomButton = document.createElement('img');
    randomButton.src = 'https://api.iconify.design/ic:outline-question-mark.svg';
    randomButton.style.width = '24px';
    randomButton.style.cursor = 'pointer';
    randomButton.style.margin = '8px';

    const controls = document.querySelector('.side-controls');
    controls.insertBefore(randomButton, controls.firstChild);

    randomButton.addEventListener('click', async () => {
        const item1 = getRandomItem();
        const item2 = getRandomItem();

        const simulateDrop = async (item, offsetY) => {
            // Simulate dragging the element
            item.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
            await wait(50);

            const [x, y] = getCenterCoords(offsetY);
            document.dispatchEvent(new MouseEvent('mousemove', {
                bubbles: true,
                clientX: x,
                clientY: y
            }));
            await wait(50);

            document.dispatchEvent(new MouseEvent('mouseup', {
                bubbles: true,
                clientX: x,
                clientY: y
            }));

            await wait(100);
        };

        await simulateDrop(item1, -40);
        await simulateDrop(item2, 40);
    });
})();