IC Block with regex

Block Item Creation with RegEx

目前为 2024-12-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name IC Block with regex
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @license MIT
  6. // @description Block Item Creation with RegEx
  7. // @icon https://i.imgur.com/WlkWOkU.png
  8. // @author @activetutorial on discord
  9. // @match https://neal.fun/infinite-craft/
  10. // @run-at document-end
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. window.regexblockdata = {
  18. trashcan: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDI1NiAyNTYiIGlkPSJGbGF0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGQ9Ik0yMDIuODI4NjEsMTk3LjE3MTg4YTMuOTk5OTEsMy45OTk5MSwwLDEsMS01LjY1NzIyLDUuNjU2MjRMMTI4LDEzMy42NTcyMyw1OC44Mjg2MSwyMDIuODI4MTJhMy45OTk5MSwzLjk5OTkxLDAsMCwxLTUuNjU3MjItNS42NTYyNEwxMjIuMzQzLDEyOCw1My4xNzEzOSw1OC44MjgxMmEzLjk5OTkxLDMuOTk5OTEsMCwwLDEsNS42NTcyMi01LjY1NjI0TDEyOCwxMjIuMzQyNzdsNjkuMTcxMzktNjkuMTcwODlhMy45OTk5MSwzLjk5OTkxLDAsMCwxLDUuNjU3MjIsNS42NTYyNEwxMzMuNjU3LDEyOFoiLz4KPC9zdmc+",
  19. infinitecraft: null,
  20. settingsButton: null,
  21. settings: {
  22. resultRegEx: /^$/,
  23. isNew: false,
  24. isKindaNew: false
  25. },
  26. addUiOption: function () {
  27. try{
  28. this.settingsButton = document.createElement('div');
  29. this.settingsButton.classList.add('setting');
  30. this.settingsButton.textContent = 'Create Conditions';
  31. const img = document.createElement('img');
  32. img.src = this.trashcan;
  33. this.settingsButton.appendChild(img);
  34. this.settingsButton.onclick = function () {
  35. alert("Current settings:\n" + JSON.stringify(window.regexblockdata.settings));
  36. const regexInput = prompt("Please enter RegEx of results to be blocked:");
  37. if (regexInput) {
  38. try {
  39. const regexPattern = new RegExp(regexInput);
  40. window.regexblockdata.settings.resultRegEx = regexPattern;
  41. } catch (e) {
  42. alert('Invalid regex.');
  43. }
  44. }
  45. const firstYesNo = prompt("Should first discoveries also be blocked? Type in true exactly if yes.");
  46. window.regexblockdata.settings.isNew = firstYesNo.toLowerCase() === 'true';
  47. const secondYesNo = prompt("Should items YOU didnt have yet also be blocked? Type in true exactly if yes.");
  48. window.regexblockdata.settings.isKindaNew = secondYesNo.toLowerCase() === 'true';
  49. alert("Updated settings:\n" + JSON.stringify(window.regexblockdata.settings))
  50. };
  51.  
  52. document.querySelector('.settings-content').appendChild(this.settingsButton);
  53. return true;
  54. } catch {
  55. return false;
  56. }
  57. },
  58. start: function () {
  59. if (document.querySelector('.settings-content')) { // Wait for IC Helper
  60. this.infinitecraft = window.$nuxt.$root.$children[1].$children[0].$children[0];
  61. this.addUiOption();
  62. const ogGCR = this.infinitecraft.getCraftResponse
  63. this.infinitecraft.getCraftResponse = async function (first, second) {
  64. const craftResponse = await ogGCR(first, second);
  65. let shouldNothing = false;
  66. if (window.regexblockdata.settings.resultRegEx.test(craftResponse.result)){
  67. shouldNothing = true;
  68. }
  69. if (window.regexblockdata.settings.resultRegEx.test(craftResponse.result) && !window.regexblockdata.settings.isNew && !window.regexblockdata.settings.isKindaNew) {
  70. craftResponse.result = "Nothing";
  71. } else if (window.regexblockdata.settings.isNew === craftResponse.isNew) {
  72. shouldNothing = false;
  73. } else if (window.regexblockdata.settings.isKindaNew) {
  74. for (let n = 0; n < this.elements.length; n++) {
  75. if (craftResponse.result === this.elements[n].text) {
  76. shouldNothing = false;
  77. break;
  78. }
  79. }
  80. }
  81. if(shouldNothing){
  82. craftResponse.result = "Nothing";
  83. }
  84.  
  85. console.log(craftResponse);
  86. return craftResponse;
  87. }
  88. } else {
  89. setTimeout(this.start.bind(this), 200);
  90. }
  91. }
  92. };
  93. window.regexblockdata.start();
  94.  
  95. })();