GC - BD Challengers Checklist

BD challengers checklist for Grundo's Cafe

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GC - BD Challengers Checklist
// @namespace    https://www.grundos.cafe/
// @version      1.1.1
// @description  BD challengers checklist for Grundo's Cafe
// @author       wibreth, soupfaerie, supercow64
// @match        https://www.grundos.cafe/~B/
// @match        https://www.grundos.cafe/~b/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @license      MIT
// ==/UserScript==

const textToHTML = (text) => new DOMParser().parseFromString(text, "text/html");

/**
 * Analyse the HTML select element for a list of Challengers the user has collected.
 *
 * @param {Node} node The root node (default: document)
 * @returns {string[]} the list of Challengers as an array of basenames
 */
const getCollectedChallengers = (node = doument) => {
  const allChallengers = Array.from(
    node.querySelectorAll(`.btn-link`)
  );
  return allChallengers.map((e) => e.textContent);
};

/**
 * Returns a Promise that resolves to a listo f Challengers
 * the user has collected.
 *
 * @returns {string[]} list of collected Challengers
 */
const getCollectedChallengersAsync = () =>
  fetch("/dome/1p/select/")
    .then((res) => res.text())
    .then(textToHTML)
    .then(getCollectedChallengers);

/**
 * Analyse the list of Challengers presented on the page ~milk.
 *
 * @param {*} node Node
 * @returns {{ node: Node, src: string}[]} an array of objects with two entries,
 * where `node` is the DOM node of the list element and `src` is the name
 * of the challenger
 */
const getChallengersOnPage = (node = document) =>
  Array.from(node.querySelectorAll(".challenger")).map((e) => ({
    node: e,
    src: e.querySelector(".challengername").childNodes[0].textContent.trim()
  }));


const html = `
<h3 style="order:-3">Challengers You Are Missing</h3>
<h3 style="order:-1">Challengers You Have Unlocked</h3>
`;

function main(collectedChallengers) {
  const root = document.querySelector(".checklist");
  root.insertAdjacentHTML("beforeend", html);

  if (collectedChallengers.length <= 0) {
    console.log('in battle!');
    document.querySelector(".hidden").classList.remove('hidden');
    return;
  }
  getChallengersOnPage().forEach(({ node, src }) => {
    if (!collectedChallengers.includes(src)) {
      node.classList.add('locked');
    }
  });
}

getCollectedChallengersAsync().then(main);