Skip to content

Instantly share code, notes, and snippets.

@inyourface34456
Last active May 1, 2025 20:45
Show Gist options
  • Save inyourface34456/4e89b2f82ae79fb5ad4f6de26c0f376b to your computer and use it in GitHub Desktop.
Save inyourface34456/4e89b2f82ae79fb5ad4f6de26c0f376b to your computer and use it in GitHub Desktop.
infinate craft auto run
function simulateDragAndDrop(element, startX, startY, targetX, targetY, steps = 10) {
function triggerMouseEvent(target, eventType, clientX, clientY) {
const event = new MouseEvent(eventType, {
bubbles: true,
cancelable: true,
clientX,
clientY,
view: window,
});
target.dispatchEvent(event);
}
console.log(`Start: (${startX}, ${startY}), Target: (${targetX}, ${targetY})`);
triggerMouseEvent(element, "mousedown", startX, startY);
let currentX = startX;
let currentY = startY;
const deltaX = (targetX - startX) / steps;
const deltaY = (targetY - startY) / steps;
return new Promise((resolve) => {
function moveMouse() {
currentX += deltaX;
currentY += deltaY;
triggerMouseEvent(document, "mousemove", currentX, currentY);
if (Math.abs(currentX - targetX) < Math.abs(deltaX) && Math.abs(currentY - targetY) < Math.abs(deltaY)) {
triggerMouseEvent(document, "mouseup", targetX, targetY);
console.log("Drag-and-drop completed");
element.style.position = "absolute";
element.style.left = `${targetX}px`;
element.style.top = `${targetY}px`;
resolve();
} else {
requestAnimationFrame(moveMouse);
}
}
moveMouse();
});
}
async function test() {
console.log("Test started");
const processedPairs = new Set(JSON.parse(localStorage.getItem("processedPairs")) || []);
function saveProcessedPairs() {
localStorage.setItem("processedPairs", JSON.stringify(Array.from(processedPairs)));
}
async function clickClearButton() {
const clearBtn = document.getElementsByClassName("clear")[0];
if (clearBtn) {
clearBtn.click();
console.log("Clear button clicked.");
await new Promise((resolve) => setTimeout(resolve, 500));
} else {
console.log("No clear button found.");
}
}
async function processCombination(firstItem, secondItem, targetX, targetY) {
const firstRect = firstItem.getBoundingClientRect();
const secondRect = secondItem.getBoundingClientRect();
const firstStartX = firstRect.x + firstRect.width / 2;
const firstStartY = firstRect.y + firstRect.height / 2;
const secondStartX = secondRect.x + secondRect.width / 2;
const secondStartY = secondRect.y + secondRect.height / 2;
await simulateDragAndDrop(firstItem, firstStartX, firstStartY, targetX, targetY);
await simulateDragAndDrop(secondItem, secondStartX, secondStartY, targetX, targetY);
// this line is comented out becuse it requires yoiu to comfirm if you want to clear it
//await clickClearButton();
}
async function processItems(itemsRow) {
const items = itemsRow[0].getElementsByClassName("item");
for (let i = 0; i < items.length; i++) {
for (let j = 0; j < items.length; j++) {
if (i !== j && !processedPairs.has(`${i}-${j}`)) {
processedPairs.add(`${i}-${j}`);
saveProcessedPairs();
await processCombination(items[i], items[j], 500, 100);
}
}
}
}
const itemsRows = document.getElementsByClassName("items-inner");
console.log("Found rows:", itemsRows.length);
await processItems(itemsRows);
}
// Wrap and run
(async () => {
await test();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment