一键离线下载

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

当前为 2016-11-02 提交的版本,查看 最新版本

  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.24
  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 sites={
  32. 0:{
  33. name:"baidu",
  34. url:"http://pan.baidu.com/disk/home",
  35. bgColor:"e1e1e1"
  36. },
  37. 1:{
  38. name:"yyw",
  39. url:"http://115.com/?tab=offline&mode=wangpan",
  40. bgColor:"5e5eff"
  41. },
  42. 2:{
  43. name:"furk",
  44. url:"https://www.furk.net/users/files/add",
  45. bgColor:"3BEBFF",
  46. hide:false
  47. },
  48. 3:{
  49. name:"seedr",
  50. url:"https://www.seedr.cc/files",
  51. bgColor:"F44336",
  52. hide:false
  53. },
  54. };
  55. 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"]';
  56. var disableUrl=[".torrentkitty.","bt.box.n0808.com"];
  57. var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  58. var i18n={};
  59. if(unsafeWindow && unsafeWindow.jQuery)$ = unsafeWindow.jQuery;
  60. switch (lang){
  61. case "zh-CN":
  62. i18n={
  63. yyw:"115网盘",
  64. baidu:"百度网盘",
  65. furk:"Furk网盘",
  66. seedr:"Seedr网盘"
  67. };
  68. break;
  69. default:
  70. i18n={
  71. yyw:"115",
  72. baidu:"BaiduPan",
  73. furk:"Furk",
  74. seedr:"Seedr"
  75. };
  76. break;
  77. }
  78.  
  79. function include(things,obj) {
  80. for (var i = things.length - 1; i >= 0; i--) {
  81. if ($(things[i]).attr('href')===$(obj).attr('href')){
  82. return true;
  83. }
  84. }
  85. }
  86.  
  87. function setCss(){
  88. $('head').append(`
  89. <style>
  90. a.whx-a{
  91. display:inline-block;
  92. margin-left:5px;
  93. background-size:20px;
  94. border-radius:50%;
  95. vertical-align:middle;
  96. transition:margin-top 0.5s ease;
  97. outline:none!important;
  98. padding:0px!important;
  99. height:25px!important;
  100. width:25px!important;
  101. background-position:center!important;
  102. background-repeat:no-repeat!important;
  103. background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYM5vMOA/ENGegK2olI6G1b97Z0sXENA+jAAAAKFJREFUKM+FklkSxCAIRHFfss3K/Y86iQSDVqzpH7FfgQpCVfAmGx+gl9JI0qrxrcNLzooEbKUG4EKWdkCiDRV0N0RTrZ5wvdgTTgp4SzCAHxAPZkAM5GOJWuuT7FE5OVPOBFLTYb3Oc2YB5uJ8+G6pgkTGt74ntcCJHiwFLHw10Tdc93jlGXGvSRtsHNpuPs+/o1ODfxAtSL0f7HPC+L/9AF60G3QxO1UaAAAAAElFTkSuQmCC")!important;
  104. }
  105. </style>
  106. `);
  107. }
  108.  
  109. function getAllEnableUrl() {
  110. var rawnodes = $(enableUrl).get();
  111. var nodes = [];
  112. var i,x;
  113. var curNode;
  114. var parentDiv=$("<div style='display:none;position:fixed;z-index:99999;overflow:visible;'></div>");
  115. var offUrl;
  116. var offNodes=[];
  117. function hideIcons(){
  118. parentDiv.css("display","none");
  119. for(var node of offNodes){
  120. node.css("margin-top","0px");
  121. }
  122. }
  123. for(x = 0; x < 4; x++){
  124. let offNode=$("<a></a>");
  125. offNode.addClass('whx-a').css("position","absolute").css("margin-top","0px").css("margin-left","0px");
  126. offNode.attr("target","_blank").click(function (event) {GM_setValue("url",getRightMagnetUrl(offUrl));});
  127. let siteConfig=sites[x];
  128. offNode.css("background-color","#"+siteConfig.bgColor).attr("title",i18n[siteConfig.name] ).attr("href", siteConfig.url);
  129. /*switch(x){
  130. case 0:
  131. offNode.css("background-color","#e1e1e1").attr("title",i18n.baidu ).attr("href", "http://pan.baidu.com/disk/home");
  132. break;
  133. case 1:
  134. offNode.css("background-color","#F44336").attr("title",i18n.seedr ).attr("href", "https://www.seedr.cc/files");
  135. break;
  136. case 2:
  137. offNode.css("background-color","#3BEBFF").attr("title",i18n.furk ).attr("href", "https://www.furk.net/users/files/add");
  138. break;
  139. case 3:
  140. offNode.css("background-color","#5e5eff").attr("title",i18n.yyw ).attr("href", "http://115.com/?tab=offline&mode=wangpan");
  141. break;
  142. }*/
  143. offNodes.push(offNode);
  144. if(siteConfig.hide)continue;
  145. parentDiv.prepend(offNode);
  146. }
  147. parentDiv.mouseover(function(e){
  148. e.stopPropagation();
  149. });
  150. document.addEventListener("mouseover", function(e){
  151. hideIcons();
  152. });
  153.  
  154. if(rawnodes.length > 0){
  155. for (i = 0; i < rawnodes.length; i++) {
  156. var disable = false;
  157. curNode = rawnodes[i];
  158. for(var j = 0; j < disableUrl.length; j++){
  159. var temp = disableUrl[j];
  160. if($(curNode)[0].href.indexOf(temp)!=-1){
  161. disable = true;
  162. break;
  163. }
  164. }
  165. if(disable)continue;
  166. if(!include(nodes,curNode)){
  167. nodes.push(curNode);
  168. }
  169. }
  170. }
  171.  
  172. if(nodes.length > 0){
  173. $("body").append(parentDiv);
  174. var codeList = [];
  175. var listLen = 0;
  176. listLen = nodes.length;
  177. setCss();
  178. if (listLen !== 0) {
  179. for (i = 0; i < listLen; i++) {
  180. curNode = nodes[i];
  181. let clone=$("<a></a>").attr("style",curNode.getAttribute("style")).attr("href",curNode.getAttribute("href")).addClass('whx-a').css("background-color","#e1e1e1");
  182. clone.mouseover(function(e){
  183. offUrl=clone.attr("href");
  184. parentDiv.css("display","block");
  185. var basePos=clone.offset();
  186. parentDiv.offset({top:basePos.top,left:basePos.left});
  187. for(var x=0;x<4;x++){
  188. offNodes[x].css("margin-top",-x*25+"px");
  189. }
  190. e.stopPropagation();
  191. });
  192. $(curNode).after(clone);
  193. }
  194. }
  195. }
  196. }
  197.  
  198. function getRightMagnetUrl(url){
  199. var newUrl = url;
  200. if(/^magnet/.test(url)){
  201. newUrl=newUrl.split("&")[0].substring(20);
  202. if(newUrl.length==32){
  203. newUrl="magnet:?xt=urn:btih:" + base32ToHex(newUrl);
  204. }else{
  205. newUrl=url;
  206. }
  207. }
  208. return newUrl;
  209. }
  210.  
  211. 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'};
  212. 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'};
  213. function base32ToHex(str){
  214. if(str.length % 8 !== 0){
  215. return null;
  216. }
  217. str = str.toLowerCase();
  218. var bin = "", returnStr = "", i;
  219. for(i = 0;i < str.length;i++){
  220. bin += b32[str.substring(i,i+1)];
  221. }
  222. for(i = 0;i < bin.length;i+=4){
  223. returnStr += b16[bin.substring(i,i+4)];
  224. }
  225. return returnStr;
  226. }
  227.  
  228. var i=0;
  229. var t=window.setInterval(function() {
  230. var curlink;
  231. if (location.href.indexOf("furk.net/users/files/add") != -1){
  232. window.clearInterval(t);
  233. curlink = GM_getValue('url');
  234. if(curlink){
  235. setTimeout(function() {
  236. $('#url').val(curlink);
  237. GM_setValue('url', '');
  238. $(":submit[value='Add download']").click();
  239. }, 500);
  240. }
  241. }else if(location.href.indexOf("seedr.cc/files") != -1){
  242. if($('#upload-button').css("display") != "none"){
  243. window.clearInterval(t);
  244. curlink = GM_getValue('url');
  245. if(curlink){
  246. setTimeout(function() {
  247. $(':text[name="torrent"]').val(curlink);
  248. GM_setValue('url', '');
  249. $('#upload-button').click();
  250. }, 500);
  251. }
  252. }
  253. }else if(location.href.indexOf("pan.baidu.com/disk/home") != -1){
  254. window.clearInterval(t);
  255. curlink = GM_getValue('url');
  256. if(curlink){
  257. document.querySelector('.g-button[data-button-id=b13]').click();
  258. var bsi = setInterval(function() {
  259. var newTaskBtn = document.querySelector('#_disk_id_2');
  260. if(newTaskBtn){
  261. clearInterval(bsi);
  262. newTaskBtn.click();
  263. var bsl = setInterval(function() {
  264. var offLink=document.querySelector('#share-offline-link');
  265. if(offLink){
  266. clearInterval(bsl);
  267. offLink.value = curlink;
  268. document.querySelectorAll('#newoffline-dialog>.dialog-footer>.g-button')[1].click();
  269. if(/^magnet|torrent$/.test(curlink))
  270. var bsb = setInterval(function(){
  271. var btList=document.querySelector('#offlinebtlist-dialog');
  272. if(btList && btList.style.display!="none"){
  273. clearInterval(bsb);
  274. btList.querySelectorAll('.dialog-footer>.g-button')[1].click();
  275. }
  276. }, 200);
  277. }
  278. }, 500);
  279. }
  280. }, 500);
  281. GM_setValue('url', '');
  282. }
  283. }else if(location.href.indexOf("115.com/?tab=offline&mode=wangpan") != -1){
  284. window.clearInterval(t);
  285. curlink = GM_getValue('url');
  286. if(curlink){
  287. var rsc = setInterval(function() {
  288. if (document.readyState == 'complete') {
  289. clearInterval(rsc);
  290. setTimeout(function() {
  291. Core['OFFL5Plug'].OpenLink();
  292. setTimeout(function() {
  293. $('#js_offline_new_add').val(curlink);
  294. }, 300);
  295. }, 1000);
  296. }
  297. }, 400);
  298. GM_setValue('url', '');
  299. }
  300. }else if((i === 0 && $(enableUrl).size() > 0) || i > 20){
  301. window.clearInterval(t);
  302. getAllEnableUrl();
  303. }else{
  304. i++;
  305. }
  306. }, 500);