一键离线下载

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

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

  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.21
  10. // @author Hoothin
  11. // @mail rixixi@gmail.com
  12. // @include http*://*/*
  13. // @exclude http*://www.baidu.*
  14. // @exclude http*://www.google.*
  15. // @exclude http*://www.bing.*
  16. // @include http*://pan.baidu.com/*
  17. // @include http://115.com/*
  18. // @include https://www.furk.net/*
  19. // @include https://www.seedr.cc/*
  20. // @grant GM_setValue
  21. // @grant GM_getValue
  22. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
  23. // @supportURL http://www.hoothin.com
  24. // @license MIT License
  25. // @compatible chrome
  26. // @compatible firefox
  27. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=rixixi@sina.com&item_name=Greasy+Fork+donation
  28. // @contributionAmount 1
  29. // ==/UserScript==
  30.  
  31. 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"]';
  32. var disableUrl=[".torrentkitty.","bt.box.n0808.com"];
  33. var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  34. var i18n={};
  35. switch (lang){
  36. case "zh-CN":
  37. i18n={
  38. yyw:"115网盘",
  39. baidu:"百度网盘",
  40. furk:"Furk网盘",
  41. seedr:"Seedr网盘"
  42. };
  43. break;
  44. default:
  45. i18n={
  46. yyw:"115",
  47. baidu:"BaiduPan",
  48. furk:"Furk",
  49. seedr:"Seedr"
  50. };
  51. break;
  52. }
  53.  
  54. function include(things,obj) {
  55. for (var i = things.length - 1; i >= 0; i--) {
  56. if ($(things[i]).attr('href')===$(obj).attr('href')){
  57. return true;
  58. }
  59. }
  60. }
  61.  
  62. function setCss(){
  63. $('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>');
  64. }
  65.  
  66. function getAllEnableUrl() {
  67. var rawnodes = $(enableUrl).get();
  68. var nodes = [];
  69. var i,x;
  70. var curNode;
  71. var parentDiv=$("<div style='display:none;position:fixed;z-index:99999;overflow:visible;'></div>");
  72. var offUrl;
  73. var offNodes=[];
  74. for(x = 0; x < 4; x++){
  75. let offNode=$("<a></a>");
  76. offNode.addClass('whx-a').css("position","absolute").css("margin-top","0px").css("margin-left","0px");
  77. offNode.attr("target","_blank").click(function (event) {GM_setValue("url",getRightMagnetUrl(offUrl));});
  78. switch(x){
  79. case 0:
  80. offNode.css("background-color","#e1e1e1").attr("title",i18n.baidu ).attr("href", "http://pan.baidu.com/disk/home");
  81. break;
  82. case 1:
  83. offNode.css("background-color","#F44336").attr("title",i18n.seedr ).attr("href", "https://www.seedr.cc/files");
  84. break;
  85. case 2:
  86. offNode.css("background-color","#3BEBFF").attr("title",i18n.furk ).attr("href", "https://www.furk.net/users/files/add");
  87. break;
  88. case 3:
  89. offNode.css("background-color","#5e5eff").attr("title",i18n.yyw ).attr("href", "http://115.com/?tab=offline&mode=wangpan");
  90. break;
  91. }
  92. offNodes.push(offNode);
  93. parentDiv.prepend(offNode);
  94. }
  95. parentDiv.mouseleave(function(e){
  96. parentDiv.css("display","none");
  97. for(var node of offNodes){
  98. node.css("margin-top","0px");
  99. }
  100. });
  101.  
  102. if(rawnodes.length > 0){
  103. for (i = 0; i < rawnodes.length; i++) {
  104. var disable = false;
  105. curNode = rawnodes[i];
  106. for(var j = 0; j < disableUrl.length; j++){
  107. var temp = disableUrl[j];
  108. if($(curNode)[0].href.indexOf(temp)!=-1){
  109. disable = true;
  110. break;
  111. }
  112. }
  113. if(disable)continue;
  114. if(!include(nodes,curNode)){
  115. nodes.push(curNode);
  116. }
  117. }
  118. }
  119.  
  120. if(nodes.length > 0){
  121. $("body").append(parentDiv);
  122. var codeList = [];
  123. var listLen = 0;
  124. listLen = nodes.length;
  125. setCss();
  126. if (listLen !== 0) {
  127. for (i = 0; i < listLen; i++) {
  128. curNode = nodes[i];
  129. let clone=$("<a></a>").attr("style",curNode.getAttribute("style")).attr("href",curNode.getAttribute("href")).addClass('whx-a').css("background-color","#e1e1e1");
  130. clone.mouseover(function(e){
  131. offUrl=clone.attr("href");
  132. parentDiv.css("display","block");
  133. var basePos=clone.offset();
  134. parentDiv.offset({top:basePos.top,left:basePos.left});
  135. for(var x=0;x<4;x++){
  136. offNodes[x].css("margin-top",-x*25+"px");
  137. }
  138. });
  139. $(curNode).after(clone);
  140. }
  141. }
  142. }
  143. }
  144.  
  145. function getRightMagnetUrl(url){
  146. var newUrl = url;
  147. if(/^magnet/.test(url)){
  148. newUrl=newUrl.split("&")[0].substring(20);
  149. if(newUrl.length==32){
  150. newUrl="magnet:?xt=urn:btih:" + base32ToHex(newUrl);
  151. }else{
  152. newUrl=url;
  153. }
  154. }
  155. return newUrl;
  156. }
  157.  
  158. 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'};
  159. 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'};
  160. function base32ToHex(str){
  161. if(str.length % 8 !== 0){
  162. return null;
  163. }
  164. str = str.toLowerCase();
  165. var bin = "", returnStr = "", i;
  166. for(i = 0;i < str.length;i++){
  167. bin += b32[str.substring(i,i+1)];
  168. }
  169. for(i = 0;i < bin.length;i+=4){
  170. returnStr += b16[bin.substring(i,i+4)];
  171. }
  172. return returnStr;
  173. }
  174.  
  175. var i=0;
  176. var t=window.setInterval(function() {
  177. var curlink;
  178. if (location.href.indexOf("furk.net/users/files/add") != -1){
  179. window.clearInterval(t);
  180. curlink = GM_getValue('url');
  181. if(curlink){
  182. setTimeout(function() {
  183. $('#url').val(curlink);
  184. GM_setValue('url', '');
  185. $(":submit[value='Add download']").click();
  186. }, 500);
  187. }
  188. }else if(location.href.indexOf("seedr.cc/files") != -1){
  189. if($('#upload-button').css("display") != "none"){
  190. window.clearInterval(t);
  191. curlink = GM_getValue('url');
  192. if(curlink){
  193. setTimeout(function() {
  194. $(':text[name="torrent"]').val(curlink);
  195. GM_setValue('url', '');
  196. $('#upload-button').click();
  197. }, 500);
  198. }
  199. }
  200. }else if(location.href.indexOf("pan.baidu.com/disk/home") != -1){
  201. window.clearInterval(t);
  202. curlink = GM_getValue('url');
  203. if(curlink){
  204. document.querySelector('.g-button[data-button-id=b13]').click();
  205. var bsi = setInterval(function() {
  206. var newTaskBtn = document.querySelector('#_disk_id_2');
  207. if(newTaskBtn){
  208. clearInterval(bsi);
  209. newTaskBtn.click();
  210. var bsl = setInterval(function() {
  211. var offLink=document.querySelector('#share-offline-link');
  212. if(offLink){
  213. clearInterval(bsl);
  214. offLink.value = curlink;
  215. document.querySelectorAll('#newoffline-dialog>.dialog-footer>.g-button')[1].click();
  216. setTimeout(function(){
  217. var btList=document.querySelector('#offlinebtlist-dialog');
  218. if(btList && btList.style.display!="none"){
  219. btList.querySelectorAll('.dialog-footer>.g-button')[1].click();
  220. }
  221. }, 500);
  222. }
  223. }, 500);
  224. }
  225. }, 500);
  226. GM_setValue('url', '');
  227. }
  228. }else if(location.href.indexOf("115.com/?tab=offline&mode=wangpan") != -1){
  229. window.clearInterval(t);
  230. curlink = GM_getValue('url');
  231. if(curlink){
  232. var rsc = setInterval(function() {
  233. if (document.readyState == 'complete') {
  234. clearInterval(rsc);
  235. setTimeout(function() {
  236. Core['OFFL5Plug'].OpenLink();
  237. setTimeout(function() {
  238. $('#js_offline_new_add').val(curlink);
  239. }, 300);
  240. }, 1000);
  241. }
  242. }, 400);
  243. GM_setValue('url', '');
  244. }
  245. }else if((i === 0 && $(enableUrl).length > 0) || i > 20){
  246. window.clearInterval(t);
  247. getAllEnableUrl();
  248. }else{
  249. i++;
  250. }
  251. }, 500);