Add Elements to Infinite Craft

Automatically add elements to Infinite Craft page and prevent reloading

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Add Elements to Infinite Craft
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically add elements to Infinite Craft page and prevent reloading
// @author       GW
// @match        https://neal.fun/infinite-craft/
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your JavaScript code goes here
    const container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.left = '2.5cm';
    container.style.bottom = '2.5cm';
    container.style.display = 'flex';
    container.style.flexDirection = 'column';

    const textInput = document.createElement('input');
    textInput.type = 'text';
    textInput.placeholder = 'Enter text';
    container.appendChild(textInput);

    const emojiInput = document.createElement('input');
    emojiInput.type = 'text';
    emojiInput.placeholder = 'Enter emoji';
    container.appendChild(emojiInput);

    const switchContainer = document.createElement('div');
    switchContainer.style.display = 'flex';
    switchContainer.style.alignItems = 'center';

    const switchInput = document.createElement('input');
    switchInput.type = 'checkbox';
    switchInput.checked = false;
    switchContainer.appendChild(switchInput);

    const switchLabel = document.createElement('span');
    switchLabel.textContent = 'Discovered';
    switchContainer.appendChild(switchLabel);

    container.appendChild(switchContainer);

    const addButton = document.createElement('button');
    addButton.textContent = 'Add Element';
    addButton.onclick = function() {
        const text = textInput.value;
        const emoji = emojiInput.value;
        const discovered = switchInput.checked;

        const existingData = JSON.parse(localStorage.getItem('infinite-craft-data')) || { elements: [], darkMode: false };

        existingData.elements.push({ text, emoji, discovered });

        localStorage.setItem('infinite-craft-data', JSON.stringify(existingData));

        textInput.value = '';
        emojiInput.value = '';
        switchInput.checked = false;

        if(preventReloadSwitch.checked) {
            return false;
        } else {
            location.reload();
        }
    };
    container.appendChild(addButton);

    const preventReloadContainer = document.createElement('div');
    preventReloadContainer.style.display = 'flex';
    preventReloadContainer.style.alignItems = 'center';

    const preventReloadSwitch = document.createElement('input');
    preventReloadSwitch.type = 'checkbox';
    preventReloadSwitch.checked = false;
    preventReloadContainer.appendChild(preventReloadSwitch);

    const preventReloadLabel = document.createElement('span');
    preventReloadLabel.textContent = 'Prevent reloading';
    preventReloadLabel.style.fontSize = 'smaller';
    preventReloadLabel.style.fontWeight = 'normal'; // Not bold
    preventReloadContainer.appendChild(preventReloadLabel);

    container.appendChild(preventReloadContainer);

    textInput.addEventListener('keydown', function(event) {
        event.stopPropagation();
    });
    emojiInput.addEventListener('keydown', function(event) {
        event.stopPropagation();
    });

    document.body.appendChild(container);
})();