Infinite Craft

Save and Load Script for Infinite Craft

  1. // ==UserScript==
  2. // @name Infinite Craft
  3. // @namespace http://tampermonkey.net/
  4. // @version 01
  5. // @license GNU GPLv3
  6. // @description Save and Load Script for Infinite Craft
  7. // @author Shadowdanc
  8. // @match https://neal.fun/infinite-craft/
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function download_txt() {
  14. let currentData = localStorage.getItem('infinite-craft-data');
  15. let hiddenElement = document.createElement('a');
  16.  
  17. hiddenElement.href = 'data:attachment/text,' + encodeURI(currentData);
  18. hiddenElement.target = '_blank';
  19. hiddenElement.download = 'InfiniteCraftSaveData.txt';
  20. hiddenElement.click();
  21. }
  22.  
  23. function addDownloadButton() {
  24. let button = document.createElement('button');
  25. button.innerHTML = 'Save Game Data';
  26. button.classList.add('downloadSaveButton');
  27. document.getElementsByClassName('side-controls')[0].appendChild(button);
  28.  
  29. document.getElementsByClassName('downloadSaveButton')[0].addEventListener('click', download_txt);
  30. }
  31.  
  32. function askYesNoQuestion(question) {
  33. let answer = prompt(question + " (yes or no)");
  34. if (answer.toLowerCase() === "yes") {
  35. return true;
  36. } else if (answer.toLowerCase() === "no") {
  37. return false;
  38. } else {
  39. // If the user enters an invalid response, prompt again
  40. alert("Please enter 'yes' or 'no'");
  41. return askYesNoQuestion(question);
  42. }
  43. }
  44.  
  45. function addLoadButton() {
  46.  
  47. let input = document.createElement('input');
  48. input.classList.add('LoadSaveButton');
  49. input.type = 'file';
  50. input.innerHTML = 'Load Game Data';
  51. input.accept = 'text/plain';
  52.  
  53. document.getElementsByClassName('side-controls')[0].appendChild(input);
  54. document.getElementsByClassName('LoadSaveButton')[0].addEventListener('change', function (event) {
  55. let input = event.target;
  56. let reader = new FileReader();
  57. reader.onload = function() {
  58. let text = reader.result;
  59. if (askYesNoQuestion("This will overrite you'r current save data: Continue?")) {
  60. localStorage.setItem('infinite-craft-data', text);
  61. }
  62. };
  63. reader.readAsText(input.files[0]);
  64. });
  65. }
  66.  
  67. (function() {
  68. 'use strict';
  69.  
  70. setTimeout(function(){
  71. addDownloadButton();
  72. addLoadButton();
  73. }, 500);
  74.  
  75. })();

QingJ © 2025

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