Block Item Creation with RegEx
当前为
// ==UserScript==
// @name IC Block with regex
// @namespace http://tampermonkey.net/
// @version 1.0
// @license MIT
// @description Block Item Creation 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.regexblockdata = {
trashcan: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDI1NiAyNTYiIGlkPSJGbGF0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGQ9Ik0yMDIuODI4NjEsMTk3LjE3MTg4YTMuOTk5OTEsMy45OTk5MSwwLDEsMS01LjY1NzIyLDUuNjU2MjRMMTI4LDEzMy42NTcyMyw1OC44Mjg2MSwyMDIuODI4MTJhMy45OTk5MSwzLjk5OTkxLDAsMCwxLTUuNjU3MjItNS42NTYyNEwxMjIuMzQzLDEyOCw1My4xNzEzOSw1OC44MjgxMmEzLjk5OTkxLDMuOTk5OTEsMCwwLDEsNS42NTcyMi01LjY1NjI0TDEyOCwxMjIuMzQyNzdsNjkuMTcxMzktNjkuMTcwODlhMy45OTk5MSwzLjk5OTkxLDAsMCwxLDUuNjU3MjIsNS42NTYyNEwxMzMuNjU3LDEyOFoiLz4KPC9zdmc+",
infinitecraft: null,
settingsButton: null,
settings: {
resultRegEx: /^$/,
isNew: false,
isKindaNew: false
},
addUiOption: function () {
try{
this.settingsButton = document.createElement('div');
this.settingsButton.classList.add('setting');
this.settingsButton.textContent = 'Create Conditions';
const img = document.createElement('img');
img.src = this.trashcan;
this.settingsButton.appendChild(img);
this.settingsButton.onclick = function () {
alert("Current settings:\n" + JSON.stringify(window.regexblockdata.settings));
const regexInput = prompt("Please enter RegEx of results to be blocked:");
if (regexInput) {
try {
const regexPattern = new RegExp(regexInput);
window.regexblockdata.settings.resultRegEx = regexPattern;
} catch (e) {
alert('Invalid regex.');
}
}
const firstYesNo = prompt("Should first discoveries also be blocked? Type in true exactly if yes.");
window.regexblockdata.settings.isNew = firstYesNo.toLowerCase() === 'true';
const secondYesNo = prompt("Should items YOU didnt have yet also be blocked? Type in true exactly if yes.");
window.regexblockdata.settings.isKindaNew = secondYesNo.toLowerCase() === 'true';
alert("Updated settings:\n" + JSON.stringify(window.regexblockdata.settings))
};
document.querySelector('.settings-content').appendChild(this.settingsButton);
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();
const ogGCR = this.infinitecraft.getCraftResponse
this.infinitecraft.getCraftResponse = async function (first, second) {
const craftResponse = await ogGCR(first, second);
let shouldNothing = false;
if (window.regexblockdata.settings.resultRegEx.test(craftResponse.result)){
shouldNothing = true;
}
if (window.regexblockdata.settings.resultRegEx.test(craftResponse.result) && !window.regexblockdata.settings.isNew && !window.regexblockdata.settings.isKindaNew) {
craftResponse.result = "Nothing";
} else if (window.regexblockdata.settings.isNew === craftResponse.isNew) {
shouldNothing = false;
} else if (window.regexblockdata.settings.isKindaNew) {
for (let n = 0; n < this.elements.length; n++) {
if (craftResponse.result === this.elements[n].text) {
shouldNothing = false;
break;
}
}
}
if(shouldNothing){
craftResponse.result = "Nothing";
}
console.log(craftResponse);
return craftResponse;
}
} else {
setTimeout(this.start.bind(this), 200);
}
}
};
window.regexblockdata.start();
})();