HDTime一键认领

一键认领

  1. // ==UserScript==
  2. // @name HDTime一键认领
  3. // @name:en HDTime torrents claim
  4. // @namespace http://hdtime.org/
  5. // @version 0.0.4
  6. // @description 一键认领
  7. // @description:en one key claim all the seeding torrents in HDTime.
  8. // @author Kesa
  9. // @match https://hdtime.org/userdetails.php?id=*
  10. // @license MIT
  11. // @grant unsafeWindow
  12. // ==/UserScript==
  13. /**
  14. * 改自大青虫一键认领, 原网址: https://greasyfork.org/zh-CN/scripts/434757-烧包一键认领
  15. */
  16. (function () {
  17. 'use strict';
  18. // Your code here...
  19. function sleep(time) {
  20. return new Promise((resolve) => setTimeout(resolve, time)).catch((e) => { console.log(e); });
  21. }
  22. window.onload = function () {
  23. var rows = document.querySelectorAll("tr");//tr表行元素,获取所有表行
  24. for (var i = 0; i < rows.length; i++) {
  25. if (rows[i].childElementCount == 2 && rows[i].cells[0].innerText == "当前做种") {//如果该表行只有两个子元素且第一个子元素的内部文本为“当前做种”
  26. var idClaim = document.getElementById("claimAllTorrents");//获取所有ID为的claimAllTorrents的元素
  27. if (idClaim == null) {//如果为空,则创建一键认领按钮
  28. const dom = document.createElement('div')
  29. dom.innerHTML = '<a id="claimAllTorrents" href="javascript:void(0);" onclick="window.manualClaimTorrents();" style="margin-left:10px;font-weight:bold;color:red" title="认领全部当前做种(运行后无法停止,强制停止可关闭页面)">一键认领</a>';
  30. rows[i].cells[1].prepend(dom)
  31. break;
  32. }
  33. }
  34. }
  35. }
  36. unsafeWindow.manualClaimTorrents = async function () {
  37. const _raw_list = Array.from(document.querySelectorAll("button[data-action='addClaim']"));
  38. const list = _raw_list.filter(el => el.style.display != 'none');//获取所有a元素
  39. console.log(list);
  40. if (list.length == 0) {
  41. alert('未检测到已做种种子或已经全部认领\n请打开当前做种列表, 若列表没有种子您无法认领!\n若您已经全部认领请无视!')
  42. return
  43. }
  44. var msg = "确定要认领全部种子吗?\n\n严正警告: \n请勿短时间内多次点击, 否则后果自负!\n请勿短时间内多次点击, 否则后果自负!\n请勿短时间内多次点击, 否则后果自负! \n点击后请等待至弹窗, 种子越多越要等捏(每个种子访问间隔500ms)";
  45. if (confirm(msg) == true) {//提示选择确认
  46. for (var i = 0; i < list.length; i++) {
  47. var maxClaim = 10000;
  48. var result = await unsafeWindow.ClassificationClaimTorrents(list, maxClaim);
  49. var total = result.total;
  50. var success = result.success;
  51. alert(`共计${total}个种子,本次成功认领${success}个。`);
  52. var idClaim = document.getElementById("claimAllTorrents");
  53. idClaim.parentNode.removeChild(idClaim);
  54. }
  55. }
  56. }
  57. unsafeWindow.ClassificationClaimTorrents = async function (element, maxClaim) {
  58. var total = 0, success = 0;
  59. for (const el of element) {
  60. if (success >= maxClaim) {
  61. alert("最多只能认领10000个种子!");
  62. break;
  63. }
  64. total += 1
  65. const claimId = el.dataset.torrent_id
  66. if (claimId > 0) {
  67. var xhr = new XMLHttpRequest();
  68. xhr.open('POST', 'https://hdtime.org/ajax.php', true);
  69. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  70. xhr.send('action=addClaim&params%5Btorrent_id%5D=' + claimId);
  71. }
  72. xhr.onload = function () {
  73. if (xhr.status == 200) {
  74. // response 就是你要的东西
  75. var response = xhr.responseText
  76. el.style.background = 'lime';
  77. el.innerText = '成功';
  78. // console.log(response)
  79. success += 1;
  80. }
  81. }
  82. await sleep(500);
  83. }
  84. return {
  85. total: total,
  86. success: success
  87. }
  88. }
  89. })();