Greasy Fork 支持简体中文。

BakaBoard - AutoThxAndDownloader

Auto presses thanks and triggers the download and closes tab after download. You only have to open the entry you want to download in a new tab.

// ==UserScript==
// @name             BakaBoard - AutoThxAndDownloader
// @description      Auto presses thanks and triggers the download and closes tab after download. You only have to open the entry you want to download in a new tab.
// @version          1.2
// @grant            none
// @author           UnFairlight
// @namespace        unfairlight.bb.autothxanddownloader
// @run-at           document-end
// @match            https://bakaboard.moe/index.php?threads/*
// ==/UserScript==

/* jshint esversion: 8 */

if (
  document.querySelector(".p-breadcrumbs [href='/index.php?categories/userposts-suche.57/']") === null && (
  document.querySelector(".p-breadcrumbs [href='/index.php?forums/seasonal-animes.149/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/index.php?categories/download.42/']")) !== null
) {
  console.log("apply auto downloader");

  function loopButtons(index, thankButtons) {
    console.log("Button", thankButtons[index]);
    if (!thankButtons[index].classList.contains("has-reaction")) {
      console.log("Thank button is available");
      thankButtons[index].click();

      let postId = thankButtons[index].href.match(/\d+/)[0];
      console.log("Post ID", postId);

      let isLastThank = index + 1 >= thankButtons.length;
      console.log("Last thank", isLastThank);

      setTimeout(() => {
        triggerDownload(postId, 0, isLastThank);
      }, getRandomDelay());
    } else {
      console.log("Thank button is hidden");
    }

    index++;
    if (index < thankButtons.length) {
      setTimeout(() => {
      	console.log("setTimeout", index);
        loopButtons(index, thankButtons);
      }, getRandomDelay());
    }
  }

  async function triggerDownload(postId, retryCount, isLastThank) {
    const post = document.querySelector(`#js-post-${postId}`);
    console.log("Post", post);
    const downloadButton = post.querySelector(".message-body .bbCodeBlock--hide .bbCodeBlock-expandContent b a");

    if (downloadButton !== null) {
      console.log("Download button", downloadButton);
      downloadButton.click();

      if (isLastThank) {
        await new Promise((resolve) => {
          setTimeout(() => {
            window.close();
            resolve();
          }, getRandomDelay());
        });
      }
    } else {
    	console.log("Wait for downloadlink...", retryCount);
      retryCount++;
      if (retryCount <= 5) {
        await new Promise((resolve) => {
          setTimeout(() => {
            triggerDownload(postId, retryCount, isLastThank);
            resolve();
          }, getRandomDelay());
        });
      }
    }
  }

  function getRandomDelay() {
    return 2001 + Math.floor(Math.random() * 1500);
  }

  function initiateAutoDownload() {
    console.log("Apply auto downloader");

    const thankButtons = document.querySelectorAll(".message-footer a.reaction:not(.has-reaction)");
    console.log("Thank buttons", thankButtons);

    if (thankButtons.length > 0) {
      loopButtons(0, thankButtons);
    } else {
      console.log("No thank buttons found!");
    }
  }

  window.addEventListener("load", () => {
    console.log("Page loaded. Initiating auto download...");
    setTimeout(initiateAutoDownload, getRandomDelay());
  });
}