fixed_magnet_for_baiducloud

fix magnet link in dmhy and popgo for baiducloud offline download

  1. // ==UserScript==
  2. // @name fixed_magnet_for_baiducloud
  3. // @namespace https://github.com/22earth
  4. // @description fix magnet link in dmhy and popgo for baiducloud offline download
  5. // @include https://share.dmhy.org/topics/view/*
  6. // @include http://share.popgo.org/program*
  7. // @include http://pan.baidu.com/disk/home
  8. // @version 0.2
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. var btsite = {
  16. init: function () {
  17. this.addSearchAnchor(this.fixMagnet());
  18. },
  19.  
  20. fixMagnet: function () {
  21. var torrentHash = null, magnetNode = null;
  22. if (window.location.href.match("popgo") && document.getElementById("si_downseed")) {
  23. torrentHash = document.getElementById("si_downseed").children[0].href.split("=")[1];
  24. magnetNode = document.getElementById("si_magnet").children[0];
  25. GM_setValue('magneturl', "magnet:?xt=urn:btih:" + torrentHash);
  26.  
  27. }
  28. if (window.location.href.match("dmhy") && document.getElementById("tabs-1")) {
  29. torrentHash = document.getElementById('tabs-1').children[0].children[1].pathname.replace(/\/(.*)\/(.*)\.torrent/, "$2");
  30. magnetNode = document.getElementById("a_magnet");
  31. GM_setValue('magneturl', "magnet:?xt=urn:btih:" + torrentHash);
  32. }
  33. console.log(GM_getValue("magneturl"));
  34. return magnetNode;
  35. },
  36.  
  37. addSearchAnchor: function (aNode) {
  38. if (aNode) {
  39. // todo: create a function to make the anchor.
  40. var frag = document.createDocumentFragment();
  41. var anchor = document.createElement("a");
  42. anchor.className = "magnet-download";
  43. anchor.textContent = "百度云";
  44. anchor.href = "http://pan.baidu.com/disk/home";
  45. anchor.target = "_blank";
  46. // add another anchor for magnet.
  47. var magnetAnchor = document.createElement("a");
  48. magnetAnchor.textContent = "磁力链接";
  49. magnetAnchor.className = "magnet-download";
  50. magnetAnchor.href = GM_getValue("magneturl");
  51. this.addStyle();
  52. frag.appendChild(anchor);
  53. frag.appendChild(magnetAnchor);
  54. aNode.parentNode.appendChild(frag);
  55. console.log("creat a anchor");
  56. }
  57. },
  58.  
  59. addStyle: function (css) {
  60. if (css) {
  61. GM_addStyle(css);
  62. }
  63. else {
  64. GM_addStyle([
  65. '.magnet-download{color: rgb(0, 180, 30) !important;margin-left: 4px;}',
  66. '.magnet-download:hover{color:red !important;}',
  67. ].join(''));
  68. }
  69. },
  70. };
  71.  
  72.  
  73. var bdcloud = {
  74. init: function () {
  75. var magneturl = GM_getValue('magneturl');
  76. console.log(magneturl);
  77. GM_setValue('magneturl', '');
  78. if (magneturl) {
  79. var scriptnode = document.createElement("script");
  80. scriptnode.innerHTML = '(' + this.addToOffline.toString() + ')(\'' + magneturl + '\');';
  81. document.body.appendChild(scriptnode);
  82. }
  83. },
  84.  
  85. addToOffline: function (magneturl) {
  86. $(".icon-btn-download").click();
  87. setTimeout(function () {
  88. $("#_disk_id_13").click();
  89. setTimeout(function () {
  90. if (!($('#share-offline-link')[0].value) && window.stop) {
  91. window.stop();
  92. $('#share-offline-link')[0].value = magneturl;
  93. }
  94. $("#_disk_id_17").click();
  95. }, 500);
  96. }, 500);
  97. },
  98. };
  99.  
  100. if (window.location.hostname.match(/dmhy|popgo/)) {
  101. btsite.init();
  102. }
  103. if (window.location.hostname.match("baidu")) {
  104. bdcloud.init();
  105. }
  106.  
  107. })();

QingJ © 2025

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