IC Delete with regex

Delete Items with RegEx

Verze ze dne 24. 12. 2024. Zobrazit nejnovější verzi.

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

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 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         IC Delete with regex
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @description  Delete Items with RegEx
// @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.regexdeletedata = {
        infinitecraft: null,
        deleteButton: null,
        trashcan: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBVcGxvYWRlZCB0bzogU1ZHIFJlcG8sIHd3dy5zdmdyZXBvLmNvbSwgR2VuZXJhdG9yOiBTVkcgUmVwbyBNaXhlciBUb29scyAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIGZpbGw9IiMwMDAwMDAiIHZlcnNpb249IjEuMSIgaWQ9IkNhcGFfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgDQoJIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDQ5MC42NDYgNDkwLjY0NiINCgkgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8Zz4NCgkJPHBhdGggZD0iTTM5OS4xNzksNjcuMjg1bC03NC43OTQsMC4wMzNMMzI0LjM1NiwwTDE2Ni4yMTQsMC4wNjZsMC4wMjksNjcuMzE4bC03NC44MDIsMC4wMzNsMC4wMjUsNjIuOTE0aDMwNy43MzlMMzk5LjE3OSw2Ny4yODV6DQoJCQkgTTE5OC4yOCwzMi4xMWw5NC4wMy0wLjA0MWwwLjAxNywzNS4yNjJsLTk0LjAzLDAuMDQxTDE5OC4yOCwzMi4xMXoiLz4NCgkJPHBhdGggZD0iTTkxLjQ2NSw0OTAuNjQ2aDMwNy43MzlWMTQ2LjM1OUg5MS40NjVWNDkwLjY0NnogTTMxNy40NjEsMTkzLjM3MmgxNi4wMjh2MjUwLjI1OWgtMTYuMDI4VjE5My4zNzJMMzE3LjQ2MSwxOTMuMzcyeg0KCQkJIE0yMzcuMzIxLDE5My4zNzJoMTYuMDI4djI1MC4yNTloLTE2LjAyOFYxOTMuMzcyTDIzNy4zMjEsMTkzLjM3MnogTTE1Ny4xOCwxOTMuMzcyaDE2LjAyOHYyNTAuMjU5SDE1Ny4xOFYxOTMuMzcyeiIvPg0KCTwvZz4NCjwvZz4NCjwvc3ZnPg==",
        addUiOption: function () {
            try{
                this.deleteButton = document.createElement('div');
                this.deleteButton.classList.add('setting');
                this.deleteButton.textContent = 'Delete with RegEx';
                const img = document.createElement('img');
                img.src = this.trashcan;
                this.deleteButton.appendChild(img);
                this.deleteButton.onclick = function () {
                    const regexInput = prompt("Make sure you have a backup and then enter a RegEx to delete:");
                    if (regexInput) {
                        try {
                            const regexPattern = new RegExp(regexInput);
                            for (let n = window.regexdeletedata.infinitecraft.elements.length - 1; n >= 0; n--) {
                                const element = window.regexdeletedata.infinitecraft.elements[n];
                                if (element.text && regexPattern.test(element.text)) {
                                    window.regexdeletedata.infinitecraft.elements.splice(n, 1);
                                }
                            }
                            window.regexdeletedata.infinitecraft.saveItems();
                        } catch (e) {
                            alert('Invalid regex or an error occurred.');
                        }
                    }
                };

                document.querySelector('.settings-content').appendChild(this.deleteButton);
                return true;
            } catch {
                return false;
            }
        },
        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.regexdeletedata.start();

})();