IB Lineage Verifyer

Adds option to verify lineages in IB

当前为 2025-01-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IB Lineage Verifyer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @license MIT
  6. // @description Adds option to verify lineages in IB
  7. // @icon https://i.imgur.com/WlkWOkU.png
  8. // @author @activetutorial on discord
  9. // @match https://infinibrowser.wiki/item/*
  10. // @run-at document-end
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. (window.AT ||= {}).lineagefverify = {
  18. lineage: null,
  19. getLineage: async function() {
  20. const itemID = location.href.split("item/")[1];
  21. const custom = document.getElementById("item_footer")?.textContent == "This is an unverified user-submitted element";
  22. const baseURL = (custom ? "https://infinibrowser.wiki/api/recipe/custom?id=" : "https://infinibrowser.wiki/api/recipe?id=");
  23. const response = await fetch(baseURL + itemID);
  24. this.lineage = (await response.json()).steps;
  25. },
  26. createElements: function() { // Create the button
  27. document.querySelector("h3").insertAdjacentHTML
  28. ('afterend',
  29. '<div style="margin-top:1rem"><button id="verify-recipe" class="btn">Verify Recipe</button></div>'
  30. );
  31. this.verifyButton = document.getElementById("verify-recipe");
  32. },
  33. getUncrafted: async function() {
  34. const uncrafted = new Set();
  35. this.lineage.forEach((step, i) => {
  36. const partLineage = this.lineage.slice(0, i); // Slice lineage to avoid circular recipes
  37. // Verify if ingredients have been crafted
  38. const ingredientAValid = !partLineage.every(partStep => !(
  39. step.a.id.toLowerCase() === partStep.result.id.toLowerCase()
  40. ));
  41. const ingredientBValid = !partLineage.every(partStep => !(
  42. step.b.id.toLowerCase() === partStep.result.id.toLowerCase()
  43. ));
  44.  
  45. if (!ingredientAValid) uncrafted.add(step.a.id);
  46. if (!ingredientBValid) uncrafted.add(step.b.id);
  47. });
  48. return [...uncrafted];
  49. },
  50. check: async function (first, second, result, mainneal=false) {
  51. // Either proxy or neals server
  52. const baseURL = (mainneal ? "https://neal.fun/api/infinite-craft/pair?ref=app&" : "https://infiniteback.active-tutorial-video.workers.dev/?");
  53. const response = await fetch(`${baseURL}first=${encodeURIComponent(first)}&second=${encodeURIComponent(second)}`);
  54. const data = await response?.json()
  55. return data?.result?.toLowerCase() === result?.toLowerCase(); // Return if its true
  56. },
  57. verifyLineage: async function() {
  58. let uncrafted = await this.getUncrafted();
  59. const incorrectCrafts = [];
  60. const allowedUncrafted = ["Water", "Fire", "Earth", "Wind"]; // Allowed missing items
  61. uncrafted = uncrafted.filter(item => !allowedUncrafted.includes(item)); // Subtract allowed items
  62. console.log(uncrafted);
  63. alert("Uncrafted items: " + uncrafted);
  64. this.lineage.forEach(async step => {
  65. await this.check(step.a.id, step.b.id, step.result.id, false) ||
  66. await this.check(step.a.id, step.b.id, step.result.id, true) ||
  67. incorrectCrafts.push(step); // If false both times, craft is incorrect
  68. });
  69. console.log(incorrectCrafts);
  70. alert("Incorrect lineage steps: " + JSON.stringify(incorrectCrafts));
  71.  
  72. incorrectCrafts.length || uncrafted.length ||
  73. alert("Lineage fully valid!");
  74. },
  75. start: function () {
  76. if (document.querySelector('.ibuttons')) { // Wait for IB to load
  77. this.createElements();
  78. // Button event listener
  79. this.verifyButton.addEventListener("click", this.verifyLineage.bind(this));
  80. // Get current lineage
  81. this.getLineage();
  82.  
  83. } else {
  84. setTimeout(this.start.bind(this), 200);
  85. }
  86. }
  87. };
  88.  
  89. window.AT.lineagefverify.start();
  90. })();