Greasy Fork

Greasy Fork is available in English.

House of Usenet - 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.

当前为 2023-04-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name             House of Usenet - 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          2.2
// @grant            none
// @author           UnFairlight
// @namespace        unfairlight.hou.autothxanddownloader
// @run-at           document-end
// @match            https://house-of-usenet.com/threads/*
// ==/UserScript==

/* jshint esversion: 8 */

if (
  document.querySelector(".p-breadcrumbs [href='/categories/cine.655/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/movies.658/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/serien.721/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/animes.6844/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/dokus.5698/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/tv.7497/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/videospiele-und-software.635/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/musik.677/']") !== null ||
  document.querySelector(".p-breadcrumbs [href='/categories/digitale-medien.5779/']") !== 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 not hidden");
      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(() => {
        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-content .message-attachments a");

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

      if (isLastThank) {
        await new Promise((resolve) => {
          setTimeout(() => {
            window.close();
            resolve();
          }, getRandomDelay());
        });
      }
    } else {
      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");
    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());
  });
}