一键离线下载

一键自动将磁链、bt种子或其他下载资源离线下载至网盘

当前为 2016-10-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Easy offline
  3. // @name:zh-CN 一键离线下载
  4. // @name:zh-TW 一鍵離綫下載
  5. // @description Be easy to find out all magnet links and torrents and video links in current page, and stream them from cloud storage automatically.
  6. // @description:zh-CN 一键自动将磁链、bt种子或其他下载资源离线下载至网盘
  7. // @description:zh-TW 一鍵自動將磁鏈、bt種子或其他下載資源離綫下載至網槃
  8. // @namespace http://tampermonkey.net/
  9. // @version 1.0.19
  10. // @author Hoothin
  11. // @mail rixixi@gmail.com
  12. // @include http*://pan.baidu.com/*
  13. // @include http://115.com/*
  14. // @include https://www.furk.net/*
  15. // @include https://www.seedr.cc/*
  16. // @include http*://*/*
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
  20. // @supportURL http://www.hoothin.com
  21. // @license MIT License
  22. // @compatible chrome
  23. // @compatible firefox
  24. // ==/UserScript==
  25.  
  26. var enableUrl = 'a[href^="magnet"],[href^="ed2k://|file"],[href$=".torrent"],[href$=".mp4"],[href$=".rar"],[href$=".7z"],[href$=".zip"],[href$=".rmvb"],[href$=".mkv"],[href$=".avi"],[href$=".iso"]';
  27. var disableUrl=[".torrentkitty.","bt.box.n0808.com"];
  28. var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  29. var i18n={};
  30. switch (lang){
  31. case "zh-CN":
  32. i18n={
  33. yyw:"115网盘",
  34. baidu:"百度网盘",
  35. furk:"Furk网盘",
  36. seedr:"Seedr网盘"
  37. };
  38. break;
  39. default:
  40. i18n={
  41. yyw:"115",
  42. baidu:"BaiduPan",
  43. furk:"Furk",
  44. seedr:"Seedr"
  45. };
  46. break;
  47. }
  48. function include(Things,obj) {
  49. for (var i = Things.length - 1; i >= 0; i--) {
  50. if ($(Things[i]).attr('href')===$(obj).attr('href')){
  51. return true;
  52. }
  53. }
  54. }
  55.  
  56. function setCss(){
  57. $('head').append('<style>a.whx-a{ display:inline-block;margin-left:5px;background-size:20px;border-radius:50%;vertical-align:middle;transition:margin-top 0.5s ease;outline:none!important;padding:0px!important;height:25px!important;width:25px!important;background-position:center!important;background-repeat:no-repeat!important;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYM5vMOA/ENGegK2olI6G1b97Z0sXENA+jAAAAKFJREFUKM+FklkSxCAIRHFfss3K/Y86iQSDVqzpH7FfgQpCVfAmGx+gl9JI0qrxrcNLzooEbKUG4EKWdkCiDRV0N0RTrZ5wvdgTTgp4SzCAHxAPZkAM5GOJWuuT7FE5OVPOBFLTYb3Oc2YB5uJ8+G6pgkTGt74ntcCJHiwFLHw10Tdc93jlGXGvSRtsHNpuPs+/o1ODfxAtSL0f7HPC+L/9AF60G3QxO1UaAAAAAElFTkSuQmCC")!important;}</style>');
  58. }
  59.  
  60. function getAllEnableUrl() {
  61. var rawnodes = $(enableUrl).get();
  62. var nodes = [];
  63. var i,x;
  64. var curNode;
  65. var parentDiv=$("<div style='display:none;position:fixed;z-index:99999;overflow:visible;'></div>");
  66. var offUrl;
  67. var offNodes=[];
  68. for(x = 0; x < 4; x++){
  69. var offNode=$("<a></a>");
  70. offNode.addClass('whx-a').css("position","absolute").css("margin-top","0px").css("margin-left","0px");
  71. offNode.attr("target","_blank").click(function (event) {GM_setValue("url",getRightMagnetUrl(offUrl));});
  72. switch(x){
  73. case 0:
  74. offNode.css("background-color","#e1e1e1").attr("title",i18n.baidu ).attr("href", "http://pan.baidu.com/disk/home");
  75. break;
  76. case 1:
  77. offNode.css("background-color","#F44336").attr("title",i18n.seedr ).attr("href", "https://www.seedr.cc/files");
  78. break;
  79. case 2:
  80. offNode.css("background-color","#3BEBFF").attr("title",i18n.furk ).attr("href", "https://www.furk.net/users/files/add");
  81. break;
  82. case 3:
  83. offNode.css("background-color","#5e5eff").attr("title",i18n.yyw ).attr("href", "http://115.com/?tab=offline&mode=wangpan");
  84. break;
  85. }
  86. offNodes.push(offNode);
  87. parentDiv.prepend(offNode);
  88. }
  89. $("body").append(parentDiv);
  90. parentDiv.mouseleave(function(e){
  91. parentDiv.css("display","none");
  92. for(var node of offNodes){
  93. node.css("margin-top","0px");
  94. }
  95. });
  96.  
  97. if(rawnodes.length > 0){
  98. for (i = 0; i < rawnodes.length; i++) {
  99. var disable = false;
  100. curNode = rawnodes[i];
  101. for(var j = 0; j < disableUrl.length; j++){
  102. var temp = disableUrl[j];
  103. if($(curNode)[0].href.indexOf(temp)!=-1){
  104. disable = true;
  105. break;
  106. }
  107. }
  108. if(disable)continue;
  109. if(!include(nodes,curNode)){
  110. nodes.push(curNode);
  111. }
  112. }
  113. }
  114.  
  115. if(nodes.length > 0){
  116. var codeList = [];
  117. var listLen = 0;
  118. listLen = nodes.length;
  119. setCss();
  120. if (listLen !== 0) {
  121. for (i = 0; i < listLen; i++) {
  122. curNode = nodes[i];
  123. let clone=$("<a></a>").attr("style",curNode.getAttribute("style")).attr("href",curNode.getAttribute("href")).addClass('whx-a').css("background-color","#e1e1e1");
  124. clone.mouseover(function(e){
  125. offUrl=clone.attr("href");
  126. parentDiv.css("display","block");
  127. var basePos=clone.offset();
  128. parentDiv.offset({top:basePos.top,left:basePos.left});
  129. for(var x=0;x<4;x++){
  130. offNodes[x].css("margin-top",-x*25+"px");
  131. }
  132. });
  133. $(curNode).after(clone);
  134. }
  135. }
  136. }
  137. }
  138.  
  139. function getRightMagnetUrl(url){
  140. var newUrl = url;
  141. if(/^magnet/.test(url)){
  142. newUrl=newUrl.split("&")[0].substring(20);
  143. if(newUrl.length==32){
  144. newUrl="magnet:?xt=urn:btih:" + base32ToHex(newUrl);
  145. }else{
  146. newUrl=url;
  147. }
  148. }
  149. return newUrl;
  150. }
  151.  
  152. var b32 = {'a':'00000','b':'00001','c':'00010','d':'00011','e':'00100','f':'00101','g':'00110','h':'00111','i':'01000','j':'01001','k':'01010','l':'01011','m':'01100','n':'01101','o':'01110','p':'01111','q':'10000','r':'10001','s':'10010','t':'10011','u':'10100','v':'10101','w':'10110','x':'10111','y':'11000','z':'11001','2':'11010','3':'11011','4':'11100','5':'11101','6':'11110','7':'11111'};
  153. var b16 = {'0000':'0','0001':'1','0010':'2','0011':'3','0100':'4','0101':'5','0110':'6','0111':'7','1000':'8','1001':'9','1010':'a','1011':'b','1100':'c','1101':'d','1110':'e','1111':'f'};
  154. function base32ToHex(str){
  155. if(str.length % 8 !== 0){
  156. return null;
  157. }
  158. str = str.toLowerCase();
  159. var bin = "", returnStr = "", i;
  160. for(i = 0;i < str.length;i++){
  161. bin += b32[str.substring(i,i+1)];
  162. }
  163. for(i = 0;i < bin.length;i+=4){
  164. returnStr += b16[bin.substring(i,i+4)];
  165. }
  166. return returnStr;
  167. }
  168.  
  169. var i=0;
  170. var t=window.setInterval(function() {
  171. var curlink;
  172. if (location.href.indexOf("furk.net/users/files/add") != -1){
  173. window.clearInterval(t);
  174. curlink = GM_getValue('url');
  175. if(curlink){
  176. setTimeout(function() {
  177. $('#url').val(curlink);
  178. GM_setValue('url', '');
  179. $(":submit[value='Add download']").click();
  180. }, 500);
  181. }
  182. }else if(location.href.indexOf("seedr.cc/files") != -1){
  183. if($('#upload-button').css("display") != "none"){
  184. window.clearInterval(t);
  185. curlink = GM_getValue('url');
  186. if(curlink){
  187. setTimeout(function() {
  188. $(':text[name="torrent"]').val(curlink);
  189. GM_setValue('url', '');
  190. $('#upload-button').click();
  191. }, 500);
  192. }
  193. }
  194. }else if(location.href.indexOf("pan.baidu.com/disk/home") != -1){
  195. window.clearInterval(t);
  196. curlink = GM_getValue('url');
  197. if(curlink){
  198. document.querySelector('.g-button[data-button-id=b13]').click();
  199. var bsi = setInterval(function() {
  200. var newTaskBtn = document.querySelector('#_disk_id_2');
  201. if(newTaskBtn){
  202. clearInterval(bsi);
  203. newTaskBtn.click();
  204. var bsl = setInterval(function() {
  205. var offLink=document.querySelector('#share-offline-link');
  206. if(offLink){
  207. clearInterval(bsl);
  208. offLink.value = curlink;
  209. document.querySelectorAll('#newoffline-dialog>.dialog-footer>.g-button')[1].click();
  210. setTimeout(function(){
  211. var btList=document.querySelector('#offlinebtlist-dialog');
  212. if(btList && btList.style.display!="none"){
  213. btList.querySelectorAll('.dialog-footer>.g-button')[1].click();
  214. }
  215. }, 500);
  216. }
  217. }, 500);
  218. }
  219. }, 500);
  220. GM_setValue('url', '');
  221. }
  222. }else if(location.href.indexOf("115.com/?tab=offline&mode=wangpan") != -1){
  223. window.clearInterval(t);
  224. curlink = GM_getValue('url');
  225. if(curlink){
  226. var rsc = setInterval(function() {
  227. if (document.readyState == 'complete') {
  228. clearInterval(rsc);
  229. setTimeout(function() {
  230. Core['OFFL5Plug'].OpenLink();
  231. setTimeout(function() {
  232. $('#js_offline_new_add').val(curlink);
  233. }, 300);
  234. }, 1000);
  235. }
  236. }, 400);
  237. GM_setValue('url', '');
  238. }
  239. }else if((i === 0 && $(enableUrl).length > 0) || i > 20){
  240. window.clearInterval(t);
  241. getAllEnableUrl();
  242. }else{
  243. i++;
  244. }
  245. }, 500);