All Magnet to BT

找出页面的磁力链,给出对应的种子下载地址//Find out all magnet links in current page and get their torrent download URLs. In theory, it supports many sites. you can add your favorites by //@include

  1. // ==UserScript==
  2. // @name All Magnet to BT
  3. // @version 0.1.4.4
  4. // @description 找出页面的磁力链,给出对应的种子下载地址//Find out all magnet links in current page and get their torrent download URLs. In theory, it supports many sites. you can add your favorites by //@include
  5. // @author wanghsinche @ 201509
  6. // @include https://btdigg.org/search*
  7. // @include http://btdigg.org/search*
  8. // @include http://*.jav*.*
  9. // @include https://*.jav*.*
  10. // @include http://www.torrentkitty.*/search*
  11. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
  12. // @run-at document-end
  13. // @namespace https://greasyfork.org/users/326
  14. // ==/UserScript==
  15.  
  16. function getAllMagnet(rawMagnets) {
  17. var magnetNum = rawMagnets.length;
  18. var rawString = "";
  19. var rex = new RegExp("\\w{40}", 'g'); //regular expression to match all 40 bit code
  20. if (magnetNum !== 0) { //prase all magnet herf nodes into string
  21. for (var i = 0; i < magnetNum; i++) {
  22. rawString += rawMagnets[i].toString();
  23. }
  24. }
  25. return rawString.match(rex); //return the code list
  26. }
  27.  
  28.  
  29.  
  30. function code2down1(str) {
  31. var s1, s2, btih, torrentURL;
  32. btih = str.toLocaleUpperCase();
  33. s1 = btih.substr(0, 2);
  34. s2 = btih.substr(str.length - 2);
  35. torrentURL = "http://bt.box.n0808.com/" + s1 + "/" + s2 + "/" + btih + ".torrent";
  36. return torrentURL;
  37. }
  38.  
  39. function code2down2(str) {
  40. var btih, torrentURL;
  41. btih = str.toLocaleUpperCase();
  42. torrentURL = "http://torcache.net/torrent/" + btih + ".torrent";
  43. return torrentURL;
  44. }
  45. function code2down3(str) {
  46. var btih, torrentURL;
  47. btih = str.toLocaleUpperCase();
  48. torrentURL = "http://www.torrent.org.cn/Home/torrent/download.html?hash=" + btih;
  49. return torrentURL;
  50. }
  51.  
  52. function include(Things,obj) {
  53. for (var i = Things.length - 1; i >= 0; i--) {
  54. if ($(Things[i]).attr('href')===$(obj).attr('href')){
  55. return true;
  56. }
  57. }
  58. }
  59.  
  60. function setCss(){
  61. $('head').append('<style>.color1{background-color:#FFEB3B}.color2{background-color:#F44336}.color3{background-color:#4CAF50}a.wxz-a{ background-repeat: no-repeat;background-position: center; display: inline-block;margin-left:5px;height: 20px;width: 20px;background-size: 20px;border-radius: 50%;background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAB/UlEQVRIS6WUDVEDQQyFWwVQBRQFFAetAkABRQGggFYBOKAoABRwDgAFFAWAA953s+nkMtn+wM5kus0leXn52X5vu7MvsyPJSML9W/ImeS/3tVH6GzCm+n5ZgtdMAbuTPNQMaiBk/CgZbke0tVpKzgrDjlsGQvb3OwSPphdSLLwygvwXwGJ3gDwIJXr9B4Poemyl8yDU9GAHkOcShMZTnr3gix6gnoH8pUyHpdnEmUlukgTbshkIqOwBh9kns6ZkyngyxvHMS3D07M5XYtOyASQaMO8wszPU5SMJwEIOnJ7EzhO7ASBjyYv7GJ355Jn6OH6KaslMALmS3IYM4qzDLNudVXOLf8bmGpCZJDatkW7igCnpUhInCJPVqOqesZnXmODsp4f/WZbo/QDwH9aIPaotk7HE98QIRGecYGhTiN2PhCWGZTwzKahQ25Pa+OEIG3+wJUsSsyXE7rQYPTlj7ieSdro4temhL02SZQRmxK1vgHKHITs32rTxcWciHgyYzGElkc7GY0MG8e1iZygZv5x1UxZxWhYot3mF487UnpkIkr7CGE0lceka6fzOUJrsmfEgncQ8EzPKgOLO2ORkrYjMO+XyDtSSQNYj2CwkS8lnYRxfCXpAgkxq52RMvAFOvG1+AWMMgtMnkkjPJhBzsrmHIXemjYwRm7waRu8XzEByGl4Ir08AAAAASUVORK5CYII=");vertical-align: middle;}</style>');
  62. }
  63.  
  64. function getAllTorrentsNew() {
  65. var rawnodes = $('a[href^="magnet"]').get();
  66. var nodes = [];
  67. var codeList = [];
  68. var listLen = 0;
  69. for (var i = 0; i <rawnodes.length; i++) {
  70. if(!include(nodes,rawnodes[i])){
  71. nodes.push(rawnodes[i]);
  72. }
  73. }
  74. codeList = getAllMagnet(nodes);
  75. listLen = codeList.length;
  76. setCss();
  77.  
  78. if (listLen !== 0) { //prase all magnet herf nodes into string
  79. for ( i = 0; i < listLen; i++) {
  80. $(nodes[i]).after($(nodes[i]).clone().addClass('wxz-a color3').empty().attr("target","_blank").attr("title","download torrent from torrent.org" ).attr("href", code2down3(codeList[i])));
  81. //$(nodes[i]).after($(nodes[i]).clone().addClass('wxz-a color1').empty().attr("target","_blank").attr("title","download torrent from bt.box" ).attr("href", code2down1(codeList[i])));
  82. //$(nodes[i]).after($(nodes[i]).clone().addClass('wxz-a color2').empty().attr("target","_blank").attr("title","download torrent from torcache" ).attr("href", code2down2(codeList[i])));
  83. }
  84. }
  85. $('.wxz-a').css('b','d');
  86. }
  87.  
  88.  
  89. function getAllTorrents() {
  90. var nodes = $('a[href^="magnet"]');
  91. var codeList = [];
  92. var listLen = 0;
  93. var i = 0;
  94. codeList = getAllMagnet(nodes);
  95. listLen = codeList.length;
  96. if (listLen !== 0) { //prase all magnet herf nodes into string
  97. for (i = 0; i < listLen; i++) {
  98. $(nodes[i]).after($(nodes[i]).clone().empty().html("[BT_2]").attr("target","_blank").attr("title","download torrent from torcache" ).attr("href", code2down3(codeList[i])));
  99. }
  100. }
  101. }
  102.  
  103. var i=0;
  104.  
  105.  
  106. var t=window.setInterval(function() { //wait 2 seconds to execute getAllTorrents() function
  107. if($('a[href^="magnet"]').length>0||i>20){
  108. window.clearInterval(t);
  109. getAllTorrentsNew();
  110. }else{
  111. i++;
  112. }
  113. }, 500);