下载未做种的种子

在用户认领种子详情处添加下载未做种种子按钮

  1. // ==UserScript==
  2. // @name 下载未做种的种子
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description 在用户认领种子详情处添加下载未做种种子按钮
  6. // @author You
  7. // @match http*://*/claim.php?uid=*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 等待页面加载完成
  16. window.addEventListener('load', function() {
  17. // 获取所有tr元素
  18. const trElements = document.querySelectorAll('tr');
  19. trElements.forEach(tr => {
  20. // 获取tr中的第一个td元素
  21. const firstTd = tr.querySelector('td:first-child');
  22. if (!firstTd) return;
  23. // 获取td中的第一个子元素
  24. const firstChild = firstTd.firstElementChild;
  25. if (!firstChild) return;
  26. // 检查文本内容是否包含"用户认领种子详情"
  27. if (firstChild.textContent.includes('用户认领种子详情')) {
  28. // 创建按钮
  29. const button = document.createElement('button');
  30. button.textContent = '下载未做种的种子';
  31. button.style.marginLeft = '10px';
  32. button.style.padding = '5px 10px';
  33. button.style.backgroundColor = '#4CAF50';
  34. button.style.color = 'white';
  35. button.style.border = 'none';
  36. button.style.borderRadius = '4px';
  37. button.style.cursor = 'pointer';
  38. // 添加点击事件
  39. button.addEventListener('click', function() {
  40. const idArray = [];
  41. // 遍历所有tr元素
  42. document.querySelectorAll('tr').forEach(tr => {
  43. // 获取第8个td元素
  44. const td8 = tr.querySelector('td:nth-child(8)');
  45. if (!td8 || td8.textContent.trim() !== '0:00') return;
  46. // 获取第3个td中的a标签
  47. const td3 = tr.querySelector('td:nth-child(3)');
  48. if (!td3) return;
  49. const aTag = td3.querySelector('a[href*="details.php?id="]');
  50. if (!aTag) return;
  51. // 从href中提取ID
  52. const match = aTag.href.match(/id=(\d+)/);
  53. if (match && match[1]) {
  54. idArray.push(match[1]);
  55. }
  56. });
  57. console.log('找到的ID数组:', idArray);
  58. if (idArray.length === 0) {
  59. alert('没有找到未做种的种子');
  60. return;
  61. }
  62. alert(`开始下载 ${idArray.length} 个种子文件...`);
  63. // 获取当前页面host
  64. const host = window.location.host;
  65. // 下载每个种子文件
  66. idArray.forEach((id, index) => {
  67. const url = `https://${host}/download.php?id=${id}`;
  68. const filename = `torrent_${id}.torrent`;
  69. console.log(`尝试下载URL: ${url}`);
  70. const xhr = new XMLHttpRequest();
  71. xhr.open('GET', url, true);
  72. xhr.responseType = 'blob';
  73. xhr.setRequestHeader('Cache-Control', 'no-cache');
  74. xhr.onload = function() {
  75. if (this.status === 200) {
  76. const blob = this.response;
  77. const a = document.createElement('a');
  78. const objectUrl = URL.createObjectURL(blob);
  79. a.href = objectUrl;
  80. a.download = filename;
  81. document.body.appendChild(a);
  82. a.click();
  83. setTimeout(() => {
  84. document.body.removeChild(a);
  85. URL.revokeObjectURL(objectUrl);
  86. console.log(`成功下载: ${filename}`);
  87. if (index === idArray.length - 1) {
  88. alert('所有种子文件下载完成!');
  89. }
  90. }, 100);
  91. } else {
  92. console.error(`下载失败: ${filename}`, {
  93. status: this.status,
  94. statusText: this.statusText,
  95. url: url
  96. });
  97. alert(`下载失败: ${filename}\n状态码: ${this.status}`);
  98. }
  99. };
  100. xhr.onerror = function() {
  101. console.error(`下载失败: ${filename}`, {
  102. status: this.status,
  103. statusText: this.statusText,
  104. url: url
  105. });
  106. alert(`下载失败: ${filename}\n请检查控制台查看详情`);
  107. };
  108. xhr.send();
  109. // 添加延迟避免请求过于频繁
  110. if (index < idArray.length - 1) {
  111. setTimeout(() => {}, index * 1000);
  112. }
  113. });
  114. });
  115. // 将按钮添加到子元素末尾
  116. firstChild.appendChild(button);
  117. }
  118. });
  119. });
  120. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址