Add Elements to Infinite Craft

Automatically add elements to Infinite Craft page and prevent reloading

  1. // ==UserScript==
  2. // @name Add Elements to Infinite Craft
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Automatically add elements to Infinite Craft page and prevent reloading
  6. // @author GW
  7. // @match https://neal.fun/infinite-craft/
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your JavaScript code goes here
  16. const container = document.createElement('div');
  17. container.style.position = 'fixed';
  18. container.style.left = '2.5cm';
  19. container.style.bottom = '2.5cm';
  20. container.style.display = 'flex';
  21. container.style.flexDirection = 'column';
  22.  
  23. const textInput = document.createElement('input');
  24. textInput.type = 'text';
  25. textInput.placeholder = 'Enter text';
  26. container.appendChild(textInput);
  27.  
  28. const emojiInput = document.createElement('input');
  29. emojiInput.type = 'text';
  30. emojiInput.placeholder = 'Enter emoji';
  31. container.appendChild(emojiInput);
  32.  
  33. const switchContainer = document.createElement('div');
  34. switchContainer.style.display = 'flex';
  35. switchContainer.style.alignItems = 'center';
  36.  
  37. const switchInput = document.createElement('input');
  38. switchInput.type = 'checkbox';
  39. switchInput.checked = false;
  40. switchContainer.appendChild(switchInput);
  41.  
  42. const switchLabel = document.createElement('span');
  43. switchLabel.textContent = 'Discovered';
  44. switchContainer.appendChild(switchLabel);
  45.  
  46. container.appendChild(switchContainer);
  47.  
  48. const addButton = document.createElement('button');
  49. addButton.textContent = 'Add Element';
  50. addButton.onclick = function() {
  51. const text = textInput.value;
  52. const emoji = emojiInput.value;
  53. const discovered = switchInput.checked;
  54.  
  55. const existingData = JSON.parse(localStorage.getItem('infinite-craft-data')) || { elements: [], darkMode: false };
  56.  
  57. existingData.elements.push({ text, emoji, discovered });
  58.  
  59. localStorage.setItem('infinite-craft-data', JSON.stringify(existingData));
  60.  
  61. textInput.value = '';
  62. emojiInput.value = '';
  63. switchInput.checked = false;
  64.  
  65. if(preventReloadSwitch.checked) {
  66. return false;
  67. } else {
  68. location.reload();
  69. }
  70. };
  71. container.appendChild(addButton);
  72.  
  73. const preventReloadContainer = document.createElement('div');
  74. preventReloadContainer.style.display = 'flex';
  75. preventReloadContainer.style.alignItems = 'center';
  76.  
  77. const preventReloadSwitch = document.createElement('input');
  78. preventReloadSwitch.type = 'checkbox';
  79. preventReloadSwitch.checked = false;
  80. preventReloadContainer.appendChild(preventReloadSwitch);
  81.  
  82. const preventReloadLabel = document.createElement('span');
  83. preventReloadLabel.textContent = 'Prevent reloading';
  84. preventReloadLabel.style.fontSize = 'smaller';
  85. preventReloadLabel.style.fontWeight = 'normal'; // Not bold
  86. preventReloadContainer.appendChild(preventReloadLabel);
  87.  
  88. container.appendChild(preventReloadContainer);
  89.  
  90. textInput.addEventListener('keydown', function(event) {
  91. event.stopPropagation();
  92. });
  93. emojiInput.addEventListener('keydown', function(event) {
  94. event.stopPropagation();
  95. });
  96.  
  97. document.body.appendChild(container);
  98. })();