下载杏坛hr种

在杏坛网站的每一行添加下载按钮,并在页面上添加一个下载所有种子的按钮

  1. // ==UserScript==
  2. // @name 下载杏坛hr种
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 在杏坛网站的每一行添加下载按钮,并在页面上添加一个下载所有种子的按钮
  6. // @author xiaobaiya
  7. // @match https://xingtan.one/myhr.php*
  8. // @grant GM_openInTab
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to add a download button to a specific row
  15. function addDownloadButton(row) {
  16. const detailsLink = row.querySelector('a[href^="details.php?id"]');
  17. if (detailsLink) {
  18. const id = detailsLink.href.split('=')[1];
  19. const downloadLink = `https://xingtan.one/download.php?id=${id}`;
  20. const downloadButton = document.createElement('input');
  21. downloadButton.type = 'button';
  22. downloadButton.value = '下载种子';
  23. downloadButton.onclick = function() { GM_openInTab(downloadLink, true); };
  24. row.querySelector('td:last-child').insertAdjacentElement('beforebegin', downloadButton);
  25. }
  26. }
  27.  
  28. // Add download buttons to all rows
  29. document.querySelectorAll('#hr-table tbody tr').forEach(row => {
  30. addDownloadButton(row);
  31. });
  32.  
  33. // Add 'Download All' button next to the reset button
  34. const resetButton = document.querySelector('input[type="reset"]');
  35. const downloadAllButton = document.createElement('input');
  36. downloadAllButton.type = 'button';
  37. downloadAllButton.value = '下载全部种子';
  38. downloadAllButton.style.marginLeft = '10px';
  39. downloadAllButton.onclick = function() {
  40. const links = Array.from(document.querySelectorAll('#hr-table a[href^="details.php?id"]')).map(link => `https://xingtan.one/download.php?id=${link.href.split('=')[1]}`);
  41. links.forEach((link, index) => {
  42. setTimeout(() => { GM_openInTab(link, true); }, 3000 * index);
  43. });
  44. };
  45. resetButton.parentNode.appendChild(downloadAllButton);
  46. })();