动漫花园列表页增强

列表页下载种子+批量复制种子/磁链链接

  1. // ==UserScript==
  2. // @name 动漫花园列表页增强
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description 列表页下载种子+批量复制种子/磁链链接
  6. // @author 菜姬
  7. // @match *://dmhy.org/
  8. // @match *://dmhy.org/topics/list*
  9. // @match *://www.dmhy.org/
  10. // @match *://www.dmhy.org/topics/list*
  11. // @match *://share.dmhy.org/
  12. // @match *://share.dmhy.org/topics/list*
  13. // @grant GM_xmlhttpRequest
  14. // @connect dmhy.org
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. const ensureProtocol = (url) => {
  21. if (url.startsWith('//')) {
  22. const protocol = window.location.protocol;
  23. return protocol + url;
  24. }
  25. return url;
  26. };
  27.  
  28. const downloadFile = (url, filename) => {
  29. GM_xmlhttpRequest({
  30. method: "get",
  31. url: url,
  32. timeout: 5000,
  33. responseType: "arraybuffer",
  34. onload: function (r) {
  35. const blob = new Blob([r.response], { type: "application/octet-stream" });
  36. const anchor = document.createElement("a");
  37. anchor.href = URL.createObjectURL(blob);
  38. anchor.download = filename;
  39. anchor.style.display = "none";
  40. document.body.append(anchor);
  41. anchor.click();
  42. setTimeout(() => {
  43. document.body.removeChild(anchor);
  44. URL.revokeObjectURL(anchor.href);
  45. }, 0);
  46. }
  47. });
  48. };
  49.  
  50. const reflush = () => {
  51. if (!changeToTorrentLink) {
  52. document.querySelectorAll('a.arrow-magnet').forEach((item, index, arr) => {
  53. item.title = '磁力下載';
  54. item.onclick = null;
  55. });
  56. }
  57. else {
  58. document.querySelectorAll('a.arrow-magnet').forEach((item, index, arr) => {
  59. item.title = '下載種子';
  60. item.onclick = (e) => {
  61. e.preventDefault();
  62. const link = item.parentElement.previousElementSibling.querySelector("td>a");
  63. GM_xmlhttpRequest({
  64. method: "get",
  65. url: link.href,
  66. responseType: "text",
  67. onload: function (r) {
  68. const html = r.response;
  69. const match = html.match(/<a href="(.+?dl\.dmhy\.org\/[^"]+)">(.+?)<\/a>/);
  70. const url = ensureProtocol(match[1]);
  71. const filename = match[2] + ".torrent";
  72. downloadFile(url, filename);
  73. }
  74. });
  75. };
  76. });
  77. }
  78. };
  79.  
  80. let changeToTorrentLink = localStorage.changeToTorrentLink === "true";
  81.  
  82. {
  83. const row4 = document.querySelector('#topic_list > thead > tr > th:nth-child(4) > span');
  84. row4.onclick = (e) => {
  85. changeToTorrentLink = !changeToTorrentLink;
  86. localStorage.changeToTorrentLink = changeToTorrentLink;
  87. e.target.textContent = changeToTorrentLink ? "種子" : "磁鏈";
  88. reflush();
  89. };
  90. reflush();
  91. row4.textContent = changeToTorrentLink ? "種子" : "磁鏈";
  92. const row6 = document.querySelector('#topic_list > thead > tr > th:nth-child(6) > span');
  93. row6.textContent = "做種";
  94. }
  95.  
  96. {
  97. const copyAllButton = document.createElement('a');
  98. copyAllButton.href = "javascript:;";
  99. copyAllButton.textContent = "複製全部";
  100. copyAllButton.onclick = (e) => {
  101. const text = [];
  102. document.querySelectorAll('a.arrow-magnet').forEach((item, index, arr) => {
  103. if (changeToTorrentLink) {
  104. const link = item.parentElement.previousElementSibling.querySelector("td>a");
  105. GM_xmlhttpRequest({
  106. method: "get",
  107. url: link.href,
  108. timeout: 5000,
  109. responseType: "text",
  110. onload: function (r) {
  111. const html = r.response;
  112. const match = html.match(/<a href="(.+?dl\.dmhy\.org\/[^"]+)">(.+?)<\/a>/);
  113. const url = ensureProtocol(match[1]);
  114. text.push(url);
  115. }
  116. });
  117. }
  118. else {
  119. text.push(item.href);
  120. }
  121. });
  122. window.navigator.clipboard.writeText(text.join('\n')).then(() => {
  123. alert('複製成功');
  124. }, (e) => {
  125. console.error(e);
  126. })
  127. };
  128. document.querySelector('div.nav_title > div.fr').appendChild(copyAllButton);
  129. };
  130. })();

QingJ © 2025

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