Infinite Craft Element Cheat

Add "Elements" just in a press of K!

  1. // ==UserScript==
  2. // @name Infinite Craft Element Cheat
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add "Elements" just in a press of K!
  6. // @author You
  7. // @match https://neal.fun/infinite-craft/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. // Function to add element to storage
  13. function addElementToStorage(text, emoji) {
  14. // Get the existing data from localStorage
  15. const storedData = localStorage.getItem('infinite-craft-data');
  16.  
  17. // Parse the JSON data
  18. const data = storedData ? JSON.parse(storedData) : { elements: [] };
  19.  
  20. // Create a new element
  21. const newElement = {
  22. "text": text,
  23. "emoji": emoji,
  24. "discovered": false
  25. };
  26.  
  27. // Add the new element to the elements array
  28. data.elements.push(newElement);
  29.  
  30. // Stringify the updated data and save it back to localStorage
  31. localStorage.setItem('infinite-craft-data', JSON.stringify(data));
  32. };
  33.  
  34. // Function to get input from user using prompt
  35. function getInputFromUser() {
  36. // Get name from user
  37. const name = prompt('Name?');
  38.  
  39. // Get emoji from user
  40. const emoji = prompt('Emoji?');
  41.  
  42. // Add element to storage
  43. addElementToStorage(name, emoji);
  44.  
  45. // Ask user if they want to restart the page
  46. const restart = prompt('Would you like to restart the page? It will apply changes. (Y/N)');
  47.  
  48. // If user chooses to restart, reload the page
  49. if (restart.toLowerCase() === 'y') {
  50. location.reload();
  51. }
  52. };
  53.  
  54. // Add event listener to execute function when key is pressed
  55. document.addEventListener('keydown', function(event) {
  56. if (event.key === 'k' || event.key === 'K') {
  57. getInputFromUser();
  58. }
  59. });