一键离线下载

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

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

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