Infinite Craft FastChet

Adds a menu on the top left corner for fast cheats

目前為 2024-05-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Infinite Craft FastChet
// @namespace   whydoilike.neocities.org/hi
// @match       https://neal.fun/infinite-craft/*
// @grant       none
// @version     2.4
// @author      Will
// @description Adds a menu on the top left corner for fast cheats
// @run-at      document-idle
// ==/UserScript==

console.log("Script loaded");

function createButton(id, text, top, onClick) {
    let button = document.createElement('button');
    button.id = id;
    button.innerHTML = text;
    button.style.padding = '8px';
    button.style.borderRadius = '5px';
    button.style.backgroundColor = '#2e2f4d';
    button.style.color = '#a814fe';
    button.style.border = '2px solid #070614';
    button.style.cursor = 'pointer';
    button.style.fontSize = '12px'; // Smaller font size
    button.style.fontFamily = 'Fira Sans, sans-serif';
    button.style.position = 'absolute';
    button.style.top = top;
    button.style.left = '10px';
    button.style.zIndex = '10000';
    button.addEventListener('click', onClick);
    return button;
}

function addItems(items) {
    let initial = localStorage.getItem("infinite-craft-data");
    let array = JSON.parse(initial).elements;

    items.forEach(item => {
        // Check if the item already exists
        if (!array.some(i => i.text === item.text && i.emoji === item.emoji)) {
            array.push(item);
        }
    });

    let updatedData = {
        elements: array
    };

    localStorage.setItem("infinite-craft-data", JSON.stringify(updatedData));
    window.location.reload();
}

function generateRandomElement() {
    return new Promise((resolve, reject) => {
        let emoji = String.fromCodePoint(Math.floor(Math.random() * (128567 - 128512 + 1)) + 128512); // Random emoji
        fetch('https://random-word-api.herokuapp.com/word')
            .then(response => response.json())
            .then(data => {
                let text = data[0];
                let discovered = Math.random() < 0.5; // 50/50 chance for true or false
                resolve({
                    text: text,
                    emoji: emoji,
                    discovered: discovered
                });
            })
            .catch(error => reject('Error fetching random word:', error));
    });
}

let container = document.querySelector('.container');

if (!container) {
    console.error('Container not found');
    return;
}
console.log("Container found:", container);

let saveBtn = createButton('saveBtn', 'Add Item', '50px', function() {
    console.log("Button clicked");
    let doesExists = localStorage.getItem("infinite-craft-data");
    let replace = '{"elements":[{"text":"Water","emoji":"💧","discovered":false},{"text":"Fire","emoji":"🔥","discovered":false},{"text":"Wind","emoji":"🌬️","discovered":false},{"text":"Earth","emoji":"🌍","discovered":false}]}';

    if (doesExists == null) {
        localStorage.setItem("infinite-craft-data", replace);
    }

    let initial = localStorage.getItem("infinite-craft-data");
    let array = JSON.parse(initial).elements;
    let text = prompt("Item name.");

    if (!text) {
        return;
    }

    let emoji = prompt("Emoji. Press Windows+.");

    if (!emoji) {
        return;
    }

    let discovered = confirm("First Discovery? (OK for True, Cancel for False)");
    let ItemsToAdd = {
        text: text,
        emoji: emoji,
        discovered: discovered
    };

    array.push(ItemsToAdd);
    let newItem = {
        elements: array
    };

    array = JSON.stringify(newItem);
    localStorage.setItem("infinite-craft-data", array);
    window.location.reload();
    console.log("DONE");
});

let ssaveBtn = createButton('ssaveBtn', 'Starter Pack', '100px', function() {
    console.log("Button clicked");
    const confirmAction = confirm("Are you sure you want to do this? It will reset your progress!");
    if (!confirmAction) {
        return;
    }
    localStorage.removeItem("infinite-craft-data");
    let doesExists = localStorage.getItem("infinite-craft-data");
    let replace = '{"elements":[]}';

    if (doesExists == null) {
        localStorage.setItem("infinite-craft-data", replace);
    }

    let initial = localStorage.getItem("infinite-craft-data");
    let array = JSON.parse(initial).elements;
let starterItems = [
    { text: "Water", emoji: "💧", discovered: false },
    { text: "Fire", emoji: "🔥", discovered: false },
    { text: "Wind", emoji: "🌬️", discovered: false },
    { text: "Earth", emoji: "🌍", discovered: false },
    { text: "Obama", emoji: "🐻", discovered: false },
    { text: "Trump", emoji: "💩", discovered: false },
    { text: "Infinite Craft", emoji: "🌌", discovered: false },
    { text: "Anime Hitler", emoji: "👹", discovered: false },
    { text: "Uniwar", emoji: "👾", discovered: true },
    { text: "Gay", emoji: "🏳️‍🌈", discovered: false },
    { text: "Future", emoji: "🔮", discovered: false },
    { text: "Time", emoji: "📜", discovered: false },
    { text: "Past", emoji: "📜", discovered: false },
    { text: "Sex", emoji: "🍆", discovered: false },
    { text: "Google", emoji: "🔍", discovered: false },
    { text: "Infinity", emoji: "♾️", discovered: false },
    { text: "YouTube", emoji: "📺", discovered: false }
];

    addItems(starterItems);
});

let randomBtn = createButton('randomBtn', 'Random Element', '150px', function() {
    console.log("Random Element button clicked");
    let numElements = prompt("How many random elements do you want?");
    if (numElements) {
        numElements = parseInt(numElements);
        if (!isNaN(numElements) && numElements > 0) {
            let promises = [];
            for (let i = 0; i < numElements; i++) {
                promises.push(generateRandomElement());
            }

            Promise.all(promises).then(generatedElements => {
                let elementsText = generatedElements.map(el => `Text: ${el.text}, Emoji: ${el.emoji}, Discovered: ${el.discovered}`).join('\n');
                let confirmAddition = confirm(`Generated elements:\n\n${elementsText}\n\nDo you want to add these elements?`);

                if (confirmAddition) {
                    addItems(generatedElements);
                } else {
                    console.log("User declined to add generated elements.");
                }
            }).catch(error => console.error(error));
        } else {
            console.error("Invalid input. Please enter a valid number.");
        }
    } else {
        console.log("No input provided.");
    }
});

let copyBtn = createButton('copyBtn', 'Copy JSON', '200px', function() {
    console.log("Copy JSON button clicked");
    let data = localStorage.getItem("infinite-craft-data");
    navigator.clipboard.writeText(data).then(() => {
        console.log("Data copied to clipboard");
        alert("Data copied to clipboard");
    }).catch(err => {
        console.error('Error copying data to clipboard', err);
    });
});

let pasteBtn = createButton('pasteBtn', 'Paste JSON', '250px', function() {
    console.log("Paste JSON button clicked");
    let jsonData = prompt("Paste your JSON data here:");
    if (jsonData) {
        try {
            let parsedData = JSON.parse(jsonData);
            localStorage.setItem("infinite-craft-data", JSON.stringify(parsedData));
            window.location.reload();
            console.log("Data pasted and updated");
        } catch (error) {
            console.error("Invalid JSON data", error);
            alert("Invalid JSON data");
        }
    }
});

container.appendChild(saveBtn);
container.appendChild(ssaveBtn);
container.appendChild(randomBtn);
container.appendChild(copyBtn);
container.appendChild(pasteBtn);
console.log("Buttons added to container");