Pytems

Create & Manage Items in Infinite Craft with an Easy to use Menu!

目前为 2024-02-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Pytems
  3. // @namespace https://py9.dev/
  4. // @version 1.0.4
  5. // @description Create & Manage Items in Infinite Craft with an Easy to use Menu!
  6. // @author Py9
  7. // @match https://neal.fun/infinite-craft/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=neal.fun
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. const version = '1.0.4';
  14. let checkVersion = async () => {
  15. let response = await fetch('https://raw.githubusercontent.com/Proyo9/Infinite-Hack/main/version.txt');
  16. let text = await response.text();
  17. let latestVersion = text.trim();
  18. if (compareVersions(version, latestVersion) === -1) {
  19. let items = document.querySelectorAll('.item');
  20. items.forEach(item => {
  21. if (item.textContent.includes('Thank you for using Pytems')) {
  22. item.innerHTML = `<span data-v-adfd717a="" class="item-emoji">❗</span> Pytems Update Available (v${latestVersion})`;
  23. document.getElementById('pytems-update').style.display = 'flex';
  24. console.log('%cYour Pytems is not up to date, get the latest update from: %chttps://greasyfork.org/en/scripts/487439-pytems', 'color: red; font-weight: bold;', 'color: blue; text-decoration: underline;');
  25. }
  26. });
  27. }
  28. }
  29. function compareVersions(version1, version2) {
  30. const parts1 = version1.split('.');
  31. const parts2 = version2.split('.');
  32. for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
  33. const num1 = parseInt(parts1[i]) || 0;
  34. const num2 = parseInt(parts2[i]) || 0;
  35.  
  36. if (num1 < num2) {
  37. return -1;
  38. } else if (num1 > num2) {
  39. return 1;
  40. }
  41. }
  42. return 0;
  43. }
  44. let script = document.createElement('script');
  45. script.src = 'https://cdn.jsdelivr.net/npm/emoji-picker-element@^1/index.js';
  46. script.type = 'module';
  47. document.head.appendChild(script);
  48. let items = localStorage.getItem('infinite-craft-data')
  49. if (items === null) {
  50. items = {"elements":[{"text":"Water","emoji":"💧","discovered":false},{"text":"Fire","emoji":"🔥","discovered":false},{"text":"Wind","emoji":"🌬️","discovered":false},{"text":"Earth","emoji":"🌍","discovered":false}]}
  51. } else {
  52. items = JSON.parse(items)
  53. }
  54. localStorage.setItem('infinite-craft-data', JSON.stringify(items))
  55. let thanks = {"text":"Thank you for using Pytems","emoji":"🍉","discovered":false}
  56. if (!items.elements.some(e => e.text === thanks.text)) {
  57. items.elements.unshift(thanks)
  58. }
  59. localStorage.setItem('infinite-craft-data', JSON.stringify(items))
  60. checkVersion();
  61. let buttonContainer = document.createElement('div');
  62. buttonContainer.style.display = 'flex';
  63. buttonContainer.style.justifyContent = 'center';
  64. document.body.appendChild(buttonContainer);
  65. let createButton = document.createElement('button');
  66. createButton.textContent = 'Create Item';
  67. createButton.style.zIndex = 1000000;
  68. createButton.style.padding = '10px 20px';
  69. createButton.style.backgroundColor = '#4CAF50';
  70. createButton.style.color = 'white';
  71. createButton.style.border = 'none';
  72. createButton.style.borderRadius = '5px';
  73. createButton.style.cursor = 'pointer';
  74. createButton.style.marginTop = '10px';
  75. buttonContainer.appendChild(createButton);
  76. createButton.addEventListener('click', function() {
  77. createItemMenu.style.display = 'flex';
  78. });
  79. let deleteButton = document.createElement('button');
  80. deleteButton.textContent = 'Delete Item';
  81. deleteButton.style.zIndex = 1000000;
  82. deleteButton.style.padding = '10px 20px';
  83. deleteButton.style.backgroundColor = '#f44336';
  84. deleteButton.style.color = 'white';
  85. deleteButton.style.border = 'none';
  86. deleteButton.style.borderRadius = '5px';
  87. deleteButton.style.cursor = 'pointer';
  88. deleteButton.style.marginLeft = '10px';
  89. deleteButton.style.marginTop = '10px';
  90. buttonContainer.appendChild(deleteButton);
  91. deleteButton.addEventListener('click', function() {
  92. deleteItemMenu.style.display = 'flex';
  93. });
  94. let magicCreateButton = document.createElement('button');
  95. magicCreateButton.textContent = 'Magic Create';
  96. magicCreateButton.style.zIndex = 1000000;
  97. magicCreateButton.style.padding = '10px 20px';
  98. magicCreateButton.style.backgroundColor = '#6779d0';
  99. magicCreateButton.style.color = 'white';
  100. magicCreateButton.style.border = 'none';
  101. magicCreateButton.style.borderRadius = '5px';
  102. magicCreateButton.style.cursor = 'pointer';
  103. magicCreateButton.style.marginLeft = '10px';
  104. magicCreateButton.style.marginTop = '10px';
  105. buttonContainer.appendChild(magicCreateButton);
  106. magicCreateButton.addEventListener('click', function() {
  107. let magicCreateMenu = document.createElement('div');
  108. magicCreateMenu.style.position = 'fixed';
  109. magicCreateMenu.style.top = '15%';
  110. magicCreateMenu.style.left = '50%';
  111. magicCreateMenu.style.transform = 'translateX(-50%)';
  112. magicCreateMenu.style.zIndex = 1000000;
  113. magicCreateMenu.style.padding = '20px';
  114. magicCreateMenu.style.backgroundColor = 'white';
  115. magicCreateMenu.style.borderRadius = '5px';
  116. magicCreateMenu.style.display = 'flex';
  117. magicCreateMenu.style.flexDirection = 'column';
  118. magicCreateMenu.style.alignItems = 'center';
  119. magicCreateMenu.style.justifyContent = 'center';
  120. magicCreateMenu.style.border = '1px solid #ddd';
  121. magicCreateMenu.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)';
  122. document.body.appendChild(magicCreateMenu);
  123.  
  124. let firstElementInput = document.createElement('input');
  125. firstElementInput.style.padding = '10px';
  126. firstElementInput.style.margin = '5px';
  127. firstElementInput.style.width = '100%';
  128. firstElementInput.style.border = '1px solid #ddd';
  129. firstElementInput.style.borderRadius = '5px';
  130. firstElementInput.style.fontSize = '16px';
  131. firstElementInput.style.outline = 'none';
  132. firstElementInput.placeholder = "Element One";
  133. magicCreateMenu.appendChild(firstElementInput);
  134.  
  135. let secondElementInput = document.createElement('input');
  136. secondElementInput.style.padding = '10px';
  137. secondElementInput.style.margin = '5px';
  138. secondElementInput.style.width = '100%';
  139. secondElementInput.style.border = '1px solid #ddd';
  140. secondElementInput.style.borderRadius = '5px';
  141. secondElementInput.style.fontSize = '16px';
  142. secondElementInput.style.outline = 'none';
  143. secondElementInput.placeholder = "Element Two";
  144. magicCreateMenu.appendChild(secondElementInput);
  145.  
  146. let createButton = document.createElement('button');
  147. createButton.textContent = 'Create';
  148. createButton.style.zIndex = 1000000;
  149. createButton.style.padding = '10px 20px';
  150. createButton.style.backgroundColor = '#6779d0';
  151. createButton.style.color = 'white';
  152. createButton.style.border = 'none';
  153. createButton.style.borderRadius = '5px';
  154. createButton.style.cursor = 'pointer';
  155. createButton.style.marginTop = '10px';
  156. magicCreateMenu.appendChild(createButton);
  157.  
  158. createButton.addEventListener('click', function() {
  159. const firstElement = firstElementInput.value;
  160. const secondElement = secondElementInput.value;
  161. var text = '';
  162. fetch(`https://neal.fun/api/infinite-craft/pair?first=${firstElement}&second=${secondElement}`)
  163. .then(response => {
  164. if (!response.ok) {
  165. throw new Error('Network response was not ok');
  166. }
  167. // Return the ReadableStream directly
  168. return response.body;
  169. })
  170. .then(body => {
  171. const reader = body.getReader();
  172.  
  173. const readStream = () => {
  174. return reader.read().then(({ done, value }) => {
  175. if (done) {
  176. responseJSON = JSON.parse(text);
  177. let newItem = {"text":responseJSON.result,"emoji":responseJSON.emoji,"discovered":responseJSON.isNew};
  178. items = localStorage.getItem('infinite-craft-data')
  179. items = JSON.parse(items)
  180. items.elements.push(newItem);
  181. localStorage.setItem('infinite-craft-data', JSON.stringify(items))
  182. location.reload();
  183. return;
  184. }
  185. text += new TextDecoder().decode(value);
  186. return readStream();
  187. });
  188. };
  189.  
  190. return readStream();
  191. })
  192. .catch(error => {
  193. console.error('There was a problem with the fetch operation:', error);
  194. });
  195.  
  196. magicCreateMenu.remove();
  197. });
  198. });
  199.  
  200. let createItemMenu = document.createElement('div');
  201. createItemMenu.style.position = 'fixed';
  202. createItemMenu.style.top = '15%';
  203. createItemMenu.style.left = '50%';
  204. createItemMenu.style.transform = 'translateX(-50%)';
  205. createItemMenu.style.zIndex = 1000000;
  206. createItemMenu.style.padding = '20px';
  207. createItemMenu.style.backgroundColor = 'white';
  208. createItemMenu.style.borderRadius = '5px';
  209. createItemMenu.style.display = 'none';
  210. createItemMenu.style.flexDirection = 'column';
  211. createItemMenu.style.alignItems = 'center';
  212. createItemMenu.style.justifyContent = 'center';
  213. createItemMenu.style.border = '1px solid #ddd';
  214. createItemMenu.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)';
  215. document.body.appendChild(createItemMenu);
  216.  
  217. let createItemInput = document.createElement('input');
  218. createItemInput.style.padding = '10px';
  219. createItemInput.style.margin = '5px';
  220. createItemInput.style.width = '100%';
  221. createItemInput.style.border = '1px solid #ddd';
  222. createItemInput.style.borderRadius = '5px';
  223. createItemInput.style.fontSize = '16px';
  224. createItemInput.style.outline = 'none';
  225. createItemInput.placeholder = 'Enter the name of the item';
  226. createItemInput.value = 'New Item';
  227. createItemMenu.appendChild(createItemInput);
  228. let createItemEmoji = document.createElement('input');
  229. createItemEmoji.style.padding = '10px';
  230. createItemEmoji.style.margin = '5px';
  231. createItemEmoji.style.width = '100%';
  232. createItemEmoji.style.border = '1px solid #ddd';
  233. createItemEmoji.style.borderRadius = '5px';
  234. createItemEmoji.style.fontSize = '16px';
  235. createItemEmoji.style.outline = 'none';
  236. createItemEmoji.placeholder = 'Enter the emoji for the item';
  237. createItemEmoji.value = '📋';
  238. createItemMenu.appendChild(createItemEmoji);
  239. let pickerButton = document.createElement('button');
  240. pickerButton.textContent = 'Pick Emoji';
  241. pickerButton.style.padding = '10px 20px';
  242. pickerButton.style.backgroundColor = '#2196F3';
  243. pickerButton.style.color = 'white';
  244. pickerButton.style.border = 'none';
  245. pickerButton.style.borderRadius = '5px';
  246. pickerButton.style.cursor = 'pointer';
  247. pickerButton.style.marginBottom = '10px';
  248. createItemMenu.appendChild(pickerButton);
  249. pickerButton.addEventListener('click', function() {
  250. pickerButton.style.display = 'none';
  251. emojiPicker.style.display = 'flex';
  252. }
  253. );
  254. let emojiPicker = document.createElement('emoji-picker');
  255. emojiPicker.style.marginTop = '10px';
  256. emojiPicker.style.marginBottom = '10px';
  257. emojiPicker.style.display = 'none';
  258. emojiPicker.addEventListener('emoji-click', (event) => {
  259. createItemEmoji.value = event.detail.emoji.unicode;
  260. emojiPicker.style.display = 'none';
  261. pickerButton.style.display = 'flex';
  262. });
  263. createItemMenu.appendChild(emojiPicker);
  264. let createItemDiscoveredLabel = document.createElement('label');
  265. createItemDiscoveredLabel.textContent = 'Discovered';
  266. createItemDiscoveredLabel.style.fontSize = '16px';
  267. createItemDiscoveredLabel.style.outline = 'none';
  268. createItemMenu.appendChild(createItemDiscoveredLabel);
  269. let createItemDiscovered = document.createElement('input');
  270. createItemDiscovered.type = 'checkbox';
  271. createItemDiscovered.style.border = '1px solid #ddd';
  272. createItemDiscovered.style.borderRadius = '5px';
  273. createItemDiscovered.style.fontSize = '16px';
  274. createItemDiscovered.style.outline = 'none';
  275. createItemDiscovered.style.marginBottom = '5px';
  276. createItemMenu.appendChild(createItemDiscovered);
  277. let createItemSubmit = document.createElement('button');
  278. createItemSubmit.textContent = 'Create Item';
  279. createItemSubmit.style.padding = '10px 20px';
  280. createItemSubmit.style.backgroundColor = '#4CAF50';
  281. createItemSubmit.style.color = 'white';
  282. createItemSubmit.style.border = 'none';
  283. createItemSubmit.style.borderRadius = '5px';
  284. createItemSubmit.style.cursor = 'pointer';
  285. createItemMenu.appendChild(createItemSubmit);
  286. createItemSubmit.addEventListener('click', function() {
  287. let newItem = {"text":createItemInput.value,"emoji":createItemEmoji.value,"discovered":createItemDiscovered.checked};
  288. items = localStorage.getItem('infinite-craft-data')
  289. items = JSON.parse(items)
  290. items.elements.push(newItem);
  291. localStorage.setItem('infinite-craft-data', JSON.stringify(items))
  292. location.reload();
  293. });
  294. let deleteItemMenu = document.createElement('div');
  295. deleteItemMenu.style.position = 'fixed';
  296. deleteItemMenu.style.top = '15%';
  297. deleteItemMenu.style.left = '50%';
  298. deleteItemMenu.style.transform = 'translateX(-50%)';
  299. deleteItemMenu.style.zIndex = 1000000;
  300. deleteItemMenu.style.padding = '20px';
  301. deleteItemMenu.style.backgroundColor = 'white';
  302. deleteItemMenu.style.borderRadius = '5px';
  303. deleteItemMenu.style.display = 'none';
  304. deleteItemMenu.style.flexDirection = 'column';
  305. deleteItemMenu.style.alignItems = 'center';
  306. deleteItemMenu.style.justifyContent = 'center';
  307. deleteItemMenu.style.border = '1px solid #ddd';
  308. deleteItemMenu.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)';
  309. document.body.appendChild(deleteItemMenu);
  310.  
  311. let deleteItemInput = document.createElement('input');
  312. deleteItemInput.style.padding = '10px';
  313. deleteItemInput.style.margin = '5px';
  314. deleteItemInput.style.width = '100%';
  315. deleteItemInput.style.border = '1px solid #ddd';
  316. deleteItemInput.style.borderRadius = '5px';
  317. deleteItemInput.style.fontSize = '16px';
  318. deleteItemInput.style.outline = 'none';
  319. deleteItemInput.placeholder = 'Enter the name of the item';
  320. deleteItemMenu.appendChild(deleteItemInput);
  321. let deleteItemSubmit = document.createElement('button');
  322. deleteItemSubmit.textContent = 'Delete Item';
  323. deleteItemSubmit.style.padding = '10px 20px';
  324. deleteItemSubmit.style.backgroundColor = '#f44336';
  325. deleteItemSubmit.style.color = 'white';
  326. deleteItemSubmit.style.border = 'none';
  327. deleteItemSubmit.style.borderRadius = '5px';
  328. deleteItemSubmit.style.cursor = 'pointer';
  329. deleteItemMenu.appendChild(deleteItemSubmit);
  330. deleteItemSubmit.addEventListener('click', function() {
  331. items = localStorage.getItem('infinite-craft-data')
  332. items = JSON.parse(items)
  333. items.elements = items.elements.filter(e => e.text !== deleteItemInput.value)
  334. localStorage.setItem('infinite-craft-data', JSON.stringify(items))
  335. location.reload();
  336. });
  337.  
  338. let updateButton = document.createElement('button');
  339. updateButton.textContent = 'Update';
  340. updateButton.style.zIndex = 1000000;
  341. updateButton.style.padding = '10px 20px';
  342. updateButton.style.backgroundColor = '#2196F3';
  343. updateButton.style.color = 'white';
  344. updateButton.style.border = 'none';
  345. updateButton.style.borderRadius = '5px';
  346. updateButton.style.cursor = 'pointer';
  347. updateButton.style.marginLeft = '10px';
  348. updateButton.style.marginTop = '10px';
  349. updateButton.style.display = 'none';
  350. updateButton.id = 'pytems-update';
  351. buttonContainer.appendChild(updateButton);
  352. updateButton.addEventListener('click', function() {
  353. window.location.href = 'https://greasyfork.org/en/scripts/487439-pytems';
  354. });
  355. })();