Automatically craft by inputting a lineage.
当前为
// ==UserScript==
// @name IC Auto Crafter
// @namespace http://tampermonkey.net/
// @version 1.0
// @license MIT
// @description Automatically craft by inputting a lineage.
// @icon https://i.imgur.com/WlkWOkU.png
// @author @activetutorial on discord
// @match https://neal.fun/infinite-craft/
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
(window.AT ||= {}).autocrafterdata = {
iconthing: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBVcGxvYWRlZCB0bzogU1ZHIFJlcG8sIHd3dy5zdmdyZXBvLmNvbSwgR2VuZXJhdG9yOiBTVkcgUmVwbyBNaXhlciBUb29scyAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIGZpbGw9IiMwMDAwMDAiIHZlcnNpb249IjEuMSIgaWQ9IkNhcGFfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgDQoJIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDQ1LjM2MyA0NS4zNjMiDQoJIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGc+DQoJPGc+DQoJCTxwYXRoIGQ9Ik0xLjc4OCwxNi45NDVjMC4zODgsMC4zODUsMC45MTMsMC42MDEsMS40NTksMC42MDFsMjcuNDkzLTAuMDM1djMuODMxYzAuMDAzLDAuODM2LDAuNTU2LDEuNTg2LDEuMzI5LDEuOTA0DQoJCQljMC43NzEsMC4zMTQsMS42NTgsMC4xMzUsMi4yNDYtMC40NTlsOS4wOTEtOS4xOGMxLjA2Mi0xLjA3MSwxLjA2LTIuODAxLTAuMDA5LTMuODY4bC05LjEzNy05LjEzNA0KCQkJYy0wLjU5LTAuNTkxLTEuNDc5LTAuNzY4LTIuMjUtMC40NDZjLTAuNzcsMC4zMTktMS4yNzEsMS4wNzQtMS4yNywxLjkwOEwzMC43NCw1LjlMMy4yMTksNS45MzcNCgkJCUMyLjA4LDUuOTQsMS4xNjEsNi44NjQsMS4xNjMsOC4wMDRsMC4wMTgsNy40ODNDMS4xODIsMTYuMDM0LDEuNDAxLDE2LjU2LDEuNzg4LDE2Ljk0NXoiLz4NCgkJPHBhdGggZD0iTTQyLjE0NiwyNy45MDFsLTI3LjUyMi0wLjAzNWwtMC4wMDEtMy44MzRjMC4wMDItMC44MzUtMC41LTEuNTg3LTEuMjctMS45MDdjLTAuNzcxLTAuMzIxLTEuNjYtMC4xNDYtMi4yNSwwLjQ0NQ0KCQkJbC05LjEzNiw5LjEzNWMtMS4wNjcsMS4wNjQtMS4wNzEsMi43OTYtMC4wMDksMy44NjZsOS4wOSw5LjE4MWMwLjU4OCwwLjU5NiwxLjQ3NSwwLjc3MiwyLjI0NywwLjQ1OA0KCQkJYzAuNzcyLTAuMzE2LDEuMzI2LTEuMDY2LDEuMzI5LTEuOTA0di0zLjgzbDI3LjQ5MywwLjAzNWMwLjU0NywwLDEuMDcyLTAuMjE2LDEuNDU5LTAuNjAyczAuNjA1LTAuOTEsMC42MDctMS40NTZMNDQuMiwyOS45Nw0KCQkJQzQ0LjIwMywyOC44Myw0My4yODQsMjcuOTAzLDQyLjE0NiwyNy45MDF6Ii8+DQoJPC9nPg0KPC9nPg0KPC9zdmc+",
infinitecraft: null,
autocraftButton: null,
anticheat: true,
processLineage: async function () {
const rawlineage = await this.getUserInput();
const recipes = this.parseRecipes(rawlineage); // Get the lineage
//console.log(recipes);
for (let i = 0; i < recipes.length; i++) { // Craft all recipes
const [string1, string2] = recipes[i];
const element1Exists = this.infinitecraft.elements.some(el => el.text === string1); // Anti cheat
const element2Exists = this.infinitecraft.elements.some(el => el.text === string2);
if (!this.anticheat || (element1Exists && element2Exists)) {
await this.infinitecraft.craft({text: string1}, {text: string2});
this.infinitecraft.instances.pop();
} else {
await this.showToast(`Skipping craft: You don't have one of these elements: "${string1}", "${string2}"`);
}
}
},
parseRecipes: function (lineage) {
const recipes = [];
lineage.split('\n').forEach(line => {
line = line.trim();
if (!line || !line.includes(' = ')) return;
const [ingredients, result] = line.split(' = ');
if (!ingredients || !result) return;
const ingredientList = ingredients.trim().split(' + ');
if (ingredientList.length < 2) return;
recipes.push(ingredientList.map(ingredient => ingredient.trim()));
});
return recipes;
},
getUserInput: async function () {
return new Promise((resolve) => {
let popup = window.open('', '', 'width=400,height=300');
popup.document.write('<textarea id="userInput" rows="10" cols="40" placeholder="Enter your lineage..."></textarea><br>');
popup.document.write('<button id="submitButton">Submit</button>');
popup.document.getElementById('submitButton').addEventListener('click', function() {
let userInput = popup.document.getElementById('userInput').value;
popup.close();
resolve(userInput);
});
});
},
showToast: function(message) {
const toast = document.createElement('div');
toast.textContent = message;
Object.assign(toast.style, {
position: 'fixed',
left: '50%',
transform: 'translateX(-50%)',
padding: '10px 20px',
backgroundColor: '#333',
color: '#fff',
borderRadius: '5px',
fontSize: '16px',
opacity: '0',
transition: 'opacity 0.5s ease, bottom 0.3s ease',
marginTop: '10px'
});
const existingToasts = document.querySelectorAll('.toast');
const offset = existingToasts.length * (toast.offsetHeight + 40);
toast.style.bottom = `${30 + offset}px`;
toast.classList.add('toast');
document.body.appendChild(toast);
(async () => {
await new Promise(resolve => setTimeout(resolve, 10));
toast.style.opacity = '1';
await new Promise(resolve => setTimeout(resolve, 3000));
toast.style.opacity = '0';
await new Promise(resolve => setTimeout(resolve, 500));
toast.remove();
const remainingToasts = document.querySelectorAll('.toast');
remainingToasts.forEach((t, index) => {
t.style.bottom = `${30 + index * (toast.offsetHeight + 40)}px`;
});
})();
return new Promise(resolve => setTimeout(resolve, 50)); // 0.05 delay
},
addUiOption: function () {
this.autocraftButton = document.createElement('div');
this.autocraftButton.classList.add('setting');
this.autocraftButton.textContent = 'Autocrafter';
const img = document.createElement('img');
img.src = this.iconthing;
this.autocraftButton.appendChild(img);
this.autocraftButton.onclick = function () {
window.AT.autocrafterdata.processLineage();
};
document.querySelector('.settings-content').appendChild(this.autocraftButton);
return true;
},
start: function () {
if (document.querySelector('.settings-content')) { // Wait for IC Helper
this.infinitecraft = window.$nuxt.$root.$children[1].$children[0].$children[0];
this.addUiOption();
} else {
setTimeout(this.start.bind(this), 200);
}
}
};
window.AT.autocrafterdata.start();
})();