您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Combine two random discovered items in Infinite Craft by simulating drag & drop (safe approach)
// ==UserScript== // @name Infinite Craft Random Button (Simulates Drag & Drop) // @namespace none // @version 2024-04-09 // @description Combine two random discovered items in Infinite Craft by simulating drag & drop (safe approach) // @author Gonso // @match https://neal.fun/infinite-craft/ // @grant none // @license MIT // ==/UserScript== (function () { 'use strict'; function waitForElement(selector, callback) { const interval = setInterval(() => { const el = document.querySelector(selector); if (el) { clearInterval(interval); callback(el); } }, 200); } function getDiscoveredItems() { return Array.from(document.querySelectorAll('.items .item')); } function simulateDragAndDrop(item, x, y) { const rect = item.getBoundingClientRect(); const startX = rect.left + rect.width / 2; const startY = rect.top + rect.height / 2; item.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: startX, clientY: startY })); document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: x, clientY: y })); document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, clientX: x, clientY: y })); } function getCenter(offsetY = 0) { return [ Math.floor(window.innerWidth / 2), Math.floor(window.innerHeight / 2) + offsetY ]; } waitForElement('.side-controls', (controls) => { const btn = document.createElement('img'); btn.src = 'https://api.iconify.design/ic:outline-question-mark.svg'; btn.style.width = '23px'; btn.style.cursor = 'pointer'; btn.style.margin = '6px'; btn.title = 'Random Combine'; controls.insertBefore(btn, controls.firstChild); btn.addEventListener('click', () => { const items = getDiscoveredItems(); if (items.length < 2) { alert('You need at least 2 items!'); return; } const shuffled = items.sort(() => Math.random() - 0.5); const [item1, item2] = shuffled; const [centerX, centerY] = getCenter(); // Simulate drag & drop simulateDragAndDrop(item1, centerX, centerY - 30); setTimeout(() => { simulateDragAndDrop(item2, centerX, centerY + 30); }, 200); }); console.log('[Tampermonkey] Random combine button added!'); }); })();