Infinite Craft Random Button (Simulates Drag & Drop)

Combine two random discovered items in Infinite Craft by simulating drag & drop (safe approach)

当前为 2025-04-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Infinite Craft Random Button (Simulates Drag & Drop)
  3. // @namespace none
  4. // @version 2024-04-09
  5. // @description Combine two random discovered items in Infinite Craft by simulating drag & drop (safe approach)
  6. // @author Gonso
  7. // @match https://neal.fun/infinite-craft/
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. function waitForElement(selector, callback) {
  16. const interval = setInterval(() => {
  17. const el = document.querySelector(selector);
  18. if (el) {
  19. clearInterval(interval);
  20. callback(el);
  21. }
  22. }, 200);
  23. }
  24.  
  25. function getDiscoveredItems() {
  26. return Array.from(document.querySelectorAll('.items .item'));
  27. }
  28.  
  29. function simulateDragAndDrop(item, x, y) {
  30. const rect = item.getBoundingClientRect();
  31.  
  32. const startX = rect.left + rect.width / 2;
  33. const startY = rect.top + rect.height / 2;
  34.  
  35. item.dispatchEvent(new MouseEvent('mousedown', {
  36. bubbles: true,
  37. clientX: startX,
  38. clientY: startY
  39. }));
  40.  
  41. document.dispatchEvent(new MouseEvent('mousemove', {
  42. bubbles: true,
  43. clientX: x,
  44. clientY: y
  45. }));
  46.  
  47. document.dispatchEvent(new MouseEvent('mouseup', {
  48. bubbles: true,
  49. clientX: x,
  50. clientY: y
  51. }));
  52. }
  53.  
  54. function getCenter(offsetY = 0) {
  55. return [
  56. Math.floor(window.innerWidth / 2),
  57. Math.floor(window.innerHeight / 2) + offsetY
  58. ];
  59. }
  60.  
  61. waitForElement('.side-controls', (controls) => {
  62. const btn = document.createElement('img');
  63. btn.src = 'https://api.iconify.design/ic:outline-question-mark.svg';
  64. btn.style.width = '23px';
  65. btn.style.cursor = 'pointer';
  66. btn.style.margin = '6px';
  67. btn.title = 'Random Combine';
  68.  
  69. controls.insertBefore(btn, controls.firstChild);
  70.  
  71. btn.addEventListener('click', () => {
  72. const items = getDiscoveredItems();
  73. if (items.length < 2) {
  74. alert('You need at least 2 items!');
  75. return;
  76. }
  77.  
  78. const shuffled = items.sort(() => Math.random() - 0.5);
  79. const [item1, item2] = shuffled;
  80.  
  81. const [centerX, centerY] = getCenter();
  82.  
  83. // Simulate drag & drop
  84. simulateDragAndDrop(item1, centerX, centerY - 30);
  85. setTimeout(() => {
  86. simulateDragAndDrop(item2, centerX, centerY + 30);
  87. }, 200);
  88. });
  89.  
  90. console.log('[Tampermonkey] Random combine button added!');
  91. });
  92. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址