一键离线下载

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

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

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