Add Elements to Infinite Craft

Automatically add elements to Infinite Craft page and prevent reloading

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
})();