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-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name House of Usenet - AutoThxAndDownloader
  3. // @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.
  4. // @version 2.3
  5. // @grant none
  6. // @author UnFairlight
  7. // @namespace unfairlight.hou.autothxanddownloader
  8. // @run-at document-end
  9. // @match https://house-of-usenet.com/threads/*
  10. // ==/UserScript==
  11.  
  12. /* jshint esversion: 8 */
  13.  
  14. if (
  15. document.querySelector(".p-breadcrumbs [href='/categories/cine.655/']") !== null ||
  16. document.querySelector(".p-breadcrumbs [href='/categories/movies.658/']") !== null ||
  17. document.querySelector(".p-breadcrumbs [href='/categories/serien.721/']") !== null ||
  18. document.querySelector(".p-breadcrumbs [href='/categories/animes.6844/']") !== null ||
  19. document.querySelector(".p-breadcrumbs [href='/categories/dokus.5698/']") !== null ||
  20. document.querySelector(".p-breadcrumbs [href='/categories/tv.7497/']") !== null ||
  21. document.querySelector(".p-breadcrumbs [href='/categories/videospiele-und-software.635/']") !== null ||
  22. document.querySelector(".p-breadcrumbs [href='/categories/musik.677/']") !== null ||
  23. document.querySelector(".p-breadcrumbs [href='/categories/digitale-medien.5779/']") !== null
  24. ) {
  25. console.log("apply auto downloader");
  26.  
  27. function loopButtons(index, thankButtons) {
  28. console.log("Button", thankButtons[index]);
  29. if (!thankButtons[index].classList.contains("has-reaction")) {
  30. console.log("Thank button is not hidden");
  31. thankButtons[index].click();
  32.  
  33. let postId = thankButtons[index].href.match(/\d+/)[0];
  34. console.log("Post ID", postId);
  35.  
  36. let isLastThank = index + 1 >= thankButtons.length;
  37. console.log("Last thank", isLastThank);
  38.  
  39. setTimeout(() => {
  40. triggerDownload(postId, 0, isLastThank);
  41. }, getRandomDelay());
  42. } else {
  43. console.log("Thank button is hidden");
  44. }
  45.  
  46. index++;
  47. if (index < thankButtons.length) {
  48. setTimeout(() => {
  49. loopButtons(index, thankButtons);
  50. }, getRandomDelay());
  51. }
  52. }
  53.  
  54. async function triggerDownload(postId, retryCount, isLastThank) {
  55. const post = document.querySelector(`#js-post-${postId}`);
  56. console.log("Post", post);
  57. const downloadButton = post.querySelector(".message-content .message-attachments a");
  58.  
  59. if (downloadButton !== null) {
  60. console.log("Download button", downloadButton);
  61. downloadButton.click();
  62.  
  63. if (isLastThank) {
  64. await new Promise((resolve) => {
  65. setTimeout(() => {
  66. window.close();
  67. resolve();
  68. }, getRandomDelay());
  69. });
  70. }
  71. } else {
  72. retryCount++;
  73. if (retryCount <= 5) {
  74. await new Promise((resolve) => {
  75. setTimeout(() => {
  76. triggerDownload(postId, retryCount, isLastThank);
  77. resolve();
  78. }, getRandomDelay());
  79. });
  80. }
  81. }
  82. }
  83.  
  84. function getRandomDelay() {
  85. return 2001 + Math.floor(Math.random() * 1500);
  86. }
  87.  
  88. function initiateAutoDownload() {
  89. console.log("Apply auto downloader");
  90.  
  91. const thankButtons = document.querySelectorAll(".message-footer a.reaction:not(.has-reaction)");
  92. console.log("Thank buttons", thankButtons);
  93.  
  94. if (thankButtons.length > 0) {
  95. loopButtons(0, thankButtons);
  96. } else {
  97. console.log("No thank buttons found!");
  98. }
  99. }
  100.  
  101. window.addEventListener("load", () => {
  102. console.log("Page loaded. Initiating auto download...");
  103. setTimeout(initiateAutoDownload, getRandomDelay());
  104. });
  105. }
  106.