小丑牌 Balatro 卡牌定位工具

The Soul 的搜索增强版,帮助快速定位目标牌和位置。内置 蓝图、头脑、可乐的搜索,其他自行调用函数找到 `window.findCardInAnte(底注, 英文牌名)`

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

// ==UserScript==
// @name         小丑牌 Balatro 卡牌定位工具
// @namespace    balatro-soul-util
// @version      0.0.3
// @description  The Soul 的搜索增强版,帮助快速定位目标牌和位置。内置 蓝图、头脑、可乐的搜索,其他自行调用函数找到 `window.findCardInAnte(底注, 英文牌名)`
// @author       liam61
// @match        mathisfun0.github.io/The-Soul/
// @license MIT

// ==/UserScript==

(function (global) {
  const findCardInAnte = (ante, targets, orderType = 'card') => {
    const findIndexOfCard = (ante, target) => {
      const anteEl = document.querySelector('#scrollingContainer').children[ante - 1];
      if (!anteEl) return [];

      const cardListEl = anteEl.querySelector('.scrollable');

      const arr = [...cardListEl.children].reduce((arr, card, index) => {
        const el = card.querySelector('div');

        if (el.textContent.includes(target)) {
          arr.push({ card: target, index });
        }
        return arr;
      }, []);

      return arr;
    };

    const print = (targetCardList) => {
      const msgArr = targetCardList.map(({ card, index }) => {
        const realIndex = index + 1;
        const order = realIndex % 3;

        return `[ante ${ante}] ${card}   \tindex: ${realIndex}, round: ${Math.ceil(realIndex / 3)}, order: ${
          order != 0 ? order : 3
        }`;
      });

      if (targetCardList.length) {
        console.log(msgArr.join('\n'));
        console.log('\n');
      }
    };

    const targetLists = (Array.isArray(targets) ? targets : [targets]).map((target) => findIndexOfCard(ante, target));

    if (orderType === 'card') {
      targetLists.sort((list1, list2) => list1[0]?.index - list2[0]?.index).forEach(print);
    } else if (orderType === 'order') {
      const orderedList = targetLists
        .reduce((arr, item) => {
          arr.push(...item);
          return arr;
        }, [])
        .sort((item1, item2) => item1.index - item2.index);

      print(orderedList);
    }
  };

  global.findCardInAnte = findCardInAnte;
  global.findPresetCard = () => {
    return Array.from({ length: 40 }, (_, i) => i + 1).map((ante) =>
      findCardInAnte(
        ante,
        ['Blueprint', 'Brainstorm', 'Diet Cola', 'Showman', 'The Idol', 'Sock and'],
        'order'
      )
    );
  };

  global.findPresetCard();
})(window);