baidunet downloader

分享页面也可以下载哦,反正我就是不用度娘云管家!

  1. // ==UserScript==
  2. // @name baidunet downloader
  3. // @namespace www.52pojie.cn
  4. // @version 1.1
  5. // @description 分享页面也可以下载哦,反正我就是不用度娘云管家!
  6. // @include *n.baidu.com/share/link*
  7. // @include *n.baidu.com/s/*
  8. // @run-at document-start
  9. // @match *://pan.baidu.com/disk/home*
  10. // @match *://yun.baidu.com/disk/home*
  11. // @require http://code.jquery.com/jquery-latest.js
  12. // @run-at document-end
  13. // @grant unsafeWindow
  14. // @copyright 2012+, Jixun
  15. // ==/UserScript==
  16.  
  17.  
  18. try { var w=unsafeWindow; } catch (e) { var w=window; }
  19. w.navigator.__defineGetter__ ('platform', function () {return 'Cracked by Jixun ^^';});
  20.  
  21.  
  22. (function() {
  23. 'use strict';
  24. var $ = $ || window.$;
  25. var yunData,sign,timestamp,bdstoken,logid;
  26. var fileList=[],selectList=[],
  27. list_grid_status='list';
  28. var observer,currentPage,currentPath,currentCategory;
  29. var panAPIUrl = location.protocol + "//" + location.host + "/api/";
  30. var restAPIUrl1 = location.protocol + "//pcs.baidu.com/rest/2.0/pcs/";
  31. //var restAPIUrl2 = location.protocol + "//d.pcs.baidu.com/rest/2.0/pcs/";
  32. $(function(){
  33. initParams();
  34. registerEventListener();
  35. createObserver();
  36. addButton();
  37. createIframe();
  38. addDialog();
  39. console.log('Baidu Yun Helper load successful!');
  40. });
  41. function initParams(){
  42. yunData = unsafeWindow.yunData;
  43. sign = getSign();
  44. timestamp = getTimestamp();
  45. bdstoken = getBDStoken();
  46. logid = getLogid();
  47. currentPage = getCurrentPage();
  48. if(currentPage == 'list')
  49. currentPath = getPath();
  50. if(currentPage == 'category')
  51. currentCategory = getCategory();
  52. refreshListGridStatus();
  53. refreshFileList();
  54. refreshSelectList();
  55. }
  56. function refreshFileList(){
  57. if (currentPage == 'list') {
  58. fileList = getFileList();
  59. } else if (currentPage == 'category'){
  60. fileList = getCategoryFileList();
  61. }
  62. }
  63. function refreshSelectList(){
  64. selectList = [];
  65. }
  66. function refreshListGridStatus(){
  67. list_grid_status = getListGridStatus();
  68. }
  69. function getListGridStatus(){
  70. var status = 'list';
  71. var $status_div = $('div.list-grid-switch');
  72. if ($status_div.hasClass('list-switched-on')){
  73. status = 'list';
  74. } else if ($status_div.hasClass('grid-switched-on')) {
  75. status = 'grid';
  76. }
  77. return status;
  78. }
  79. function registerEventListener(){
  80. registerHashChange();
  81. registerListGridStatus();
  82. registerCheckbox();
  83. registerAllCheckbox();
  84. registerFileSelect();
  85. }
  86. function registerHashChange(){
  87. window.addEventListener('hashchange',function(e){
  88. refreshListGridStatus();
  89. if(getCurrentPage() == 'list') {
  90. if(currentPage == getCurrentPage()){
  91. if(currentPath == getPath()){
  92. return;
  93. } else {
  94. currentPath = getPath();
  95. refreshFileList();
  96. refreshSelectList();
  97. }
  98. } else {
  99. currentPage = getCurrentPage();
  100. currentPath = getPath();
  101. refreshFileList();
  102. refreshSelectList();
  103. }
  104. } else if (getCurrentPage() == 'category') {
  105. if(currentPage == getCurrentPage()){
  106. if(currentCategory == getCategory()){
  107. return;
  108. } else {
  109. currentPage = getCurrentPage();
  110. currentCategory = getCategory();
  111. refreshFileList();
  112. refreshSelectList();
  113. }
  114. } else {
  115. currentPage = getCurrentPage();
  116. currentCategory = getCategory();
  117. refreshFileList();
  118. refreshSelectList();
  119. }
  120. }
  121. });
  122. }
  123. function registerListGridStatus(){
  124. var $a_list = $('a[node-type=list-switch]');
  125. $a_list.click(function(){
  126. list_grid_status = 'list';
  127. });
  128. var $a_grid = $('a[node-type=grid-switch]');
  129. $a_grid.click(function(){
  130. list_grid_status = 'grid';
  131. });
  132. }
  133. function registerCheckbox(){
  134. var $checkbox = $('span.checkbox');
  135. $checkbox.each(function(index,element){
  136. $(element).bind('click',function(e){
  137. var $parent = $(this).parent();
  138. var filename;
  139. if(list_grid_status == 'list') {
  140. filename = $('div.file-name div.text a',$parent).attr('title');
  141. }else if(list_grid_status == 'grid'){
  142. filename = $('div.file-name a',$parent).attr('title');
  143. }
  144. if($parent.hasClass('item-active')){
  145. console.log('unselect file:'+filename);
  146. for(var i=0;i<selectList.length;i++){
  147. if(selectList[i].filename == filename){
  148. selectList.splice(i,1);
  149. }
  150. }
  151. }else{
  152. console.log('select file:'+filename);
  153. $.each(fileList,function(index,element){
  154. if(element.server_filename == filename){
  155. var obj = {
  156. filename:element.server_filename,
  157. path:element.path,
  158. fs_id:element.fs_id,
  159. isdir:element.isdir
  160. };
  161. selectList.push(obj);
  162. }
  163. });
  164. }
  165. });
  166. });
  167. }
  168. function unregisterCheckbox(){
  169. var $checkbox = $('span.checkbox');
  170. $checkbox.each(function(index,element){
  171. $(element).unbind('click');
  172. });
  173. }
  174. function registerAllCheckbox(){
  175. var $checkbox = $('div.col-item.check');
  176. $checkbox.each(function(index,element){
  177. $(element).bind('click',function(e){
  178. var $parent = $(this).parent();
  179. if($parent.hasClass('checked')){
  180. console.log('unselect all');
  181. selectList = [];
  182. } else {
  183. console.log('select all');
  184. selectList = [];
  185. $.each(fileList,function(index,element){
  186. var obj = {
  187. filename:element.server_filename,
  188. path:element.path,
  189. fs_id:element.fs_id,
  190. isdir:element.isdir
  191. };
  192. selectList.push(obj);
  193. });
  194. }
  195. });
  196. });
  197. }
  198. function unregisterAllCheckbox(){
  199. var $checkbox = $('div.col-item.check');
  200. $checkbox.each(function(index,element){
  201. $(element).unbind('click');
  202. });
  203. }
  204. function registerFileSelect(){
  205. var $dd = $('div.list-view dd');
  206. $dd.each(function(index,element){
  207. $(element).bind('click',function(e){
  208. var nodeName = e.target.nodeName.toLowerCase();
  209. if(nodeName != 'span' && nodeName != 'a' && nodeName != 'em') {
  210. selectList = [];
  211. var filename = $('div.file-name div.text a',$(this)).attr('title');
  212. console.log('select file:' + filename);
  213. $.each(fileList,function(index,element){
  214. if(element.server_filename == filename){
  215. var obj = {
  216. filename:element.server_filename,
  217. path:element.path,
  218. fs_id:element.fs_id,
  219. isdir:element.isdir
  220. };
  221. selectList.push(obj);
  222. }
  223. });
  224. }
  225. });
  226. });
  227. }
  228. function unregisterFileSelect(){
  229. var $dd = $('div.list-view dd');
  230. $dd.each(function(index,element){
  231. $(element).unbind('click');
  232. });
  233. }
  234. function createObserver(){
  235. var MutationObserver = window.MutationObserver;
  236. var options = {
  237. 'childList': true
  238. };
  239. observer = new MutationObserver(function(mutations){
  240. unregisterCheckbox();
  241. unregisterAllCheckbox();
  242. unregisterFileSelect();
  243. registerCheckbox();
  244. registerAllCheckbox();
  245. registerFileSelect();
  246. });
  247. var list_view = document.querySelector('.list-view');
  248. var grid_view = document.querySelector('.grid-view');
  249. observer.observe(list_view,options);
  250. observer.observe(grid_view,options);
  251. }
  252. //添加下载按钮
  253. function addButton(){
  254. var $dropdownbutton = $('<span class="g-dropdown-button"></span>');
  255. var $dropdownbutton_a = $('<a class="g-button" data-button-id="b200" data-button-index="200" href="javascript:void(0);"></a>');
  256. var $dropdownbutton_a_span = $('<span class="g-button-right"><em class="icon icon-download" title="百度网盘下载助手"></em><span class="text" style="width: auto;">点击下载</span></span>');
  257. var $dropdownbutton_span = $('<span class="menu" style="width:auto"></span>');
  258. var $panAPIDownloadButton = $('<a data-menu-id="b-menu201" class="g-button-menu" href="javascript:void(0);">直接下载</a>');
  259. var $restAPIDownloadButton1 = $('<a data-menu-id="b-menu202" class="g-button-menu" href="javascript:void(0);">API下载(百度云ID)</a>');
  260. var $restAPIDownloadButton2 = $('<a data-menu-id="b-menu203" class="g-button-menu" href="javascript:void(0);">API下载(ES ID)</a>');
  261. var $linkButton1 = $('<a data-menu-id="b-menu204" class="g-button-menu" href="javascript:void(0);">显示链接(直接下载)</a>');
  262. var $linkButton2 = $('<a data-menu-id="b-menu204" class="g-button-menu" href="javascript:void(0);">显示链接(百度云ID)</a>');
  263. var $linkButton3 = $('<a data-menu-id="b-menu204" class="g-button-menu" href="javascript:void(0);">显示链接(ES ID)</a>');
  264. $dropdownbutton_span.append($panAPIDownloadButton).append($restAPIDownloadButton1).append($restAPIDownloadButton2).append($linkButton1).append($linkButton2).append($linkButton3);
  265. $dropdownbutton_a.append($dropdownbutton_a_span);
  266. $dropdownbutton.append($dropdownbutton_a).append($dropdownbutton_span);
  267. $dropdownbutton.hover(function(){
  268. $dropdownbutton.toggleClass('button-open');
  269. });
  270. $panAPIDownloadButton.click(panAPIDownloadClick);
  271. $restAPIDownloadButton1.click(restAPIDownloadClick1);
  272. $restAPIDownloadButton2.click(restAPIDownloadClick2);
  273. $linkButton1.click(linkButtonClick1);
  274. $linkButton2.click(linkButtonClick2);
  275. $linkButton3.click(linkButtonClick3);
  276. $('div.default-dom div.bar div.list-tools').append($dropdownbutton);
  277. }
  278. function addDialog(){
  279. var screenWidth = document.body.clientWidth;
  280. var dialogLeft = screenWidth>568 ? (screenWidth-568)/2 : 0;
  281. var $dialog_div = $('<div class="dialog" id="baiduyunHelperDialog" style="width: 568px; top: 0px; bottom: auto; left: '+dialogLeft+'px; right: auto; display: hidden; visibility: visible; z-index: 52;"></div>');
  282. var $dialog_header = $('<div class="dialog-header"><h3><span class="dialog-header-title">下载链接</span></h3></div>');
  283. var $dialog_control = $('<div class="dialog-control"><span class="dialog-icon dialog-close">×</span></div>');
  284. var $dialog_body = $('<div class="dialog-body"></div>');
  285. var $content = $('<div style="padding:0 20px"><a id="downloadlink" href="javascript:void(0)"></a></div>');
  286. var $tip = $('<div id="dialog_tip" style="padding-left:20px;background-color:#faf2d3;border-top: 1px solid #c4dbfe;"><p></p></div>');
  287. var $shadow = $('<div id="dialog_shadow" style="position: fixed; left: 0px; top: 0px; z-index: 50; background: rgb(0, 0, 0) none repeat scroll 0% 0%; opacity: 0.5; width: 100%; height: 100%; display: none;"></div>');
  288. var mouseInitX,mouseInitY,dialogInitX,dialogInitY;
  289. $dialog_header.mousedown(function(event){
  290. mouseInitX = parseInt(event.pageX);
  291. mouseInitY = parseInt(event.pageY);
  292. dialogInitX = parseInt($dialog_div.css('left').replace('px',''));
  293. dialogInitY = parseInt($dialog_div.css('top').replace('px',''));
  294. $(this).mousemove(function(event){
  295. var tempX = dialogInitX + parseInt(event.pageX) - mouseInitX;
  296. var tempY = dialogInitY + parseInt(event.pageY) - mouseInitY;
  297. tempX = tempX<0 ? 0 : tempX>screenWidth-568 ? screenWidth-568 : tempX;
  298. tempY = tempY<0 ? 0 : tempY;
  299. $dialog_div.css('left',tempX+'px').css('top',tempY+'px');
  300. });
  301. });
  302. $dialog_header.mouseup(function(event){
  303. $(this).unbind('mousemove');
  304. });
  305. $dialog_control.click(dialogControl);
  306. $('body').append($dialog_div.append($dialog_header.append($dialog_control)).append($dialog_body.append($content).append($tip)));
  307. $('body').append($shadow);
  308. }
  309. function panAPIDownloadClick(){
  310. console.log('PAN API download button clicked.');
  311. if(selectList.length === 0) {
  312. alert("获取选中文件失败,请刷新重试!");
  313. return;
  314. }
  315.  
  316. var fidlist,downloadType;
  317. var downloadLink;
  318. fidlist = getFidList(selectList);
  319. if (selectList.length == 1) {
  320. if (selectList[0].isdir === 1)
  321. downloadType = 'batch';
  322. else if (selectList[0].isdir === 0)
  323. downloadType= 'dlink';
  324. } else if(selectList.length > 1){
  325. downloadType = 'batch';
  326. }
  327. downloadLink = getDownloadLinkWithPanAPI(fidlist,downloadType);
  328. execDownload(downloadLink);
  329. }
  330. function restAPIDownloadClick1(){
  331. console.log("REST API download 1 button clicked.");
  332. if(selectList.length === 0) {
  333. alert("获取选中文件失败,请刷新重试!");
  334. return;
  335. } else if (selectList.length > 1) {
  336. alert("该方法不支持多文件下载!");
  337. return;
  338. } else {
  339. if(selectList[0].isdir == 1){
  340. alert("该方法不支持目录下载!");
  341. return;
  342. }
  343. }
  344. var downloadLink = getDownloadLinkWithRESTAPI1(selectList[0].path);
  345. execDownload(downloadLink);
  346. }
  347. function restAPIDownloadClick2(){
  348. console.log("REST API download 1 button clicked.");
  349. if(selectList.length === 0) {
  350. alert("获取选中文件失败,请刷新重试!");
  351. return;
  352. } else if (selectList.length > 1) {
  353. alert("该方法不支持多文件下载!");
  354. return;
  355. } else {
  356. if(selectList[0].isdir == 1){
  357. alert("该方法不支持目录下载!");
  358. return;
  359. }
  360. }
  361. var downloadLink = getDownloadLinkWithRESTAPI2(selectList[0].path);
  362. execDownload(downloadLink);
  363. }
  364. function linkButtonClick1(){
  365. if(selectList.length === 0) {
  366. alert("获取选中文件失败,请刷新重试!");
  367. return;
  368. }
  369.  
  370. var fidlist,downloadType;
  371. var downloadLink;
  372.  
  373. fidlist = getFidList(selectList);
  374.  
  375. if (selectList.length == 1) {
  376. if (selectList[0].isdir === 1)
  377. downloadType = 'batch';
  378. else if (selectList[0].isdir === 0)
  379. downloadType= 'dlink';
  380. } else if(selectList.length > 1){
  381. downloadType = 'batch';
  382. }
  383. downloadLink = getDownloadLinkWithPanAPI(fidlist,downloadType);
  384. $('#downloadlink').attr('href',downloadLink).text(downloadLink);
  385. var $shadow = $('#dialog_shadow');
  386. var $dialog = $('#baiduyunHelperDialog');
  387. var $tip = $('div#dialog_tip p');
  388. $tip.text('显示模拟百度网盘获取的链接,可以使用右键迅雷下载,复制无用,需要传递cookie');
  389. $shadow.show();
  390. $dialog.show();
  391. }
  392. function linkButtonClick2(){
  393. if(selectList.length === 0) {
  394. alert("获取选中文件失败,请刷新重试!");
  395. return;
  396. } else if (selectList.length > 1) {
  397. alert("该方法不支持多文件下载!");
  398. return;
  399. } else {
  400. if(selectList[0].isdir == 1){
  401. alert("该方法不支持目录下载!");
  402. return;
  403. }
  404. }
  405. var downloadLink = getDownloadLinkWithRESTAPI1(selectList[0].path);
  406. $('#downloadlink').attr('href',downloadLink).text(downloadLink);
  407. var $shadow = $('#dialog_shadow');
  408. var $dialog = $('#baiduyunHelperDialog');
  409. var $tip = $('div#dialog_tip p');
  410. $tip.text('显示模拟APP获取的链接(使用百度云ID),可以使用右键迅雷下载,复制无用,需要传递cookie');
  411. $shadow.show();
  412. $dialog.show();
  413. }
  414. function linkButtonClick3(){
  415. if(selectList.length === 0) {
  416. alert("获取选中文件失败,请刷新重试!");
  417. return;
  418. } else if (selectList.length > 1) {
  419. alert("该方法不支持多文件下载!");
  420. return;
  421. } else {
  422. if(selectList[0].isdir == 1){
  423. alert("该方法不支持目录下载!");
  424. return;
  425. }
  426. }
  427. var downloadLink = getDownloadLinkWithRESTAPI2(selectList[0].path);
  428. $('#downloadlink').attr('href',downloadLink).text(downloadLink);
  429. var $shadow = $('#dialog_shadow');
  430. var $dialog = $('#baiduyunHelperDialog');
  431. var $tip = $('div#dialog_tip p');
  432. $tip.text('显示模拟APP获取的链接(使用ES ID),可以使用右键迅雷下载,复制无用,需要传递cookie');
  433. $shadow.show();
  434. $dialog.show();
  435. }
  436. function dialogControl(){
  437. $('#downloadlink').attr('href','javascript:void(0)').text('');
  438. $('div#dialog_tip p').text('');
  439. var $dialog = $('#baiduyunHelperDialog');
  440. var $shadow = $('#dialog_shadow');
  441. $dialog.hide();
  442. $shadow.hide();
  443. }
  444.  
  445. function getSign(){
  446. var signFnc;
  447. try{
  448. signFnc = new Function("return " + yunData.sign2)();
  449. } catch(e){
  450. throw new Error(e.message);
  451. }
  452. return base64Encode(signFnc(yunData.sign5,yunData.sign1));
  453. }
  454.  
  455. //获取当前目录
  456. function getPath(){
  457. var hash = location.hash;
  458. var regx = /(^|&|\/)path=([^&]*)(&|$)/i;
  459. var result = hash.match(regx);
  460. return decodeURIComponent(result[2]);
  461. }
  462. function getCategory(){
  463. var hash = location.hash;
  464. var regx = /(^|&|\/)type=([^&]*)(&|$)/i;
  465. var result = hash.match(regx);
  466. return decodeURIComponent(result[2]);
  467. }
  468. function getCurrentPage(){
  469. var hash = location.hash;
  470. return decodeURIComponent(hash.substring(hash.indexOf('#')+1,hash.indexOf('/')));
  471. }
  472.  
  473. //获取文件列表
  474. function getFileList(){
  475. var filelist = [];
  476. var listUrl = panAPIUrl + "list";
  477. var path = getPath();
  478. var params = {
  479. dir:path,
  480. bdstoken:bdstoken,
  481. logid:logid,
  482. order:'size',
  483. desc:0,
  484. clienttype:0,
  485. showempty:0,
  486. web:1,
  487. channel:'chunlei',
  488. appid:250528
  489. };
  490. $.ajax({
  491. url:listUrl,
  492. async:false,
  493. method:'GET',
  494. data:params,
  495. success:function(result){
  496. filelist = 0===result.errno ? result.list : [];
  497. }
  498. });
  499. return filelist;
  500. }
  501. function getCategoryFileList(){
  502. var filelist = [];
  503. var listUrl = panAPIUrl + "categorylist";
  504. var category = getCategory();
  505. var params = {
  506. category:category,
  507. bdstoken:bdstoken,
  508. logid:logid,
  509. order:'size',
  510. desc:0,
  511. clienttype:0,
  512. showempty:0,
  513. web:1,
  514. channel:'chunlei',
  515. appid:250528
  516. };
  517. $.ajax({
  518. url:listUrl,
  519. async:false,
  520. method:'GET',
  521. data:params,
  522. success:function(result){
  523. filelist = 0===result.errno ? result.info : [];
  524. }
  525. });
  526. return filelist;
  527. }
  528.  
  529. function getFidList(list){
  530. var fidlist = null;
  531. if (list.length === 0)
  532. return null;
  533. var fileidlist = [];
  534. $.each(list,function(index,element){
  535. fileidlist.push(element.fs_id);
  536. });
  537. fidlist = '[' + fileidlist + ']';
  538. return fidlist;
  539. }
  540.  
  541. function getTimestamp(){
  542. return yunData.timestamp;
  543. }
  544.  
  545. function getBDStoken(){
  546. return yunData.MYBDSTOKEN;
  547. }
  548.  
  549. function getLogid(){
  550. var name = "BAIDUID";
  551. function getCookie(e) {
  552. var o, t;
  553. var n = document,c=decodeURI;
  554. return n.cookie.length > 0 && (o = n.cookie.indexOf(e + "="),-1 != o) ? (o = o + e.length + 1,t = n.cookie.indexOf(";", o),-1 == t && (t = n.cookie.length),c(n.cookie.substring(o, t))) : "";
  555. }
  556. var u = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#¥%……&";
  557. var d = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
  558. var f = String.fromCharCode;
  559. function l(e){
  560. if (e.length < 2) {
  561. var n = e.charCodeAt(0);
  562. return 128 > n ? e : 2048 > n ? f(192 | n >>> 6) + f(128 | 63 & n) : f(224 | n >>> 12 & 15) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
  563. }
  564. var n = 65536 + 1024 * (e.charCodeAt(0) - 55296) + (e.charCodeAt(1) - 56320);
  565. return f(240 | n >>> 18 & 7) + f(128 | n >>> 12 & 63) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
  566. }
  567. function g(e){
  568. return (e + "" + Math.random()).replace(d, l);
  569. }
  570. function m(e){
  571. var n = [0, 2, 1][e.length % 3];
  572. var t = e.charCodeAt(0) << 16 | (e.length > 1 ? e.charCodeAt(1) : 0) << 8 | (e.length > 2 ? e.charCodeAt(2) : 0);
  573. var o = [u.charAt(t >>> 18), u.charAt(t >>> 12 & 63), n >= 2 ? "=" : u.charAt(t >>> 6 & 63), n >= 1 ? "=" : u.charAt(63 & t)];
  574. return o.join("");
  575. }
  576. function h(e){
  577. return e.replace(/[\s\S]{1,3}/g, m);
  578. }
  579. function p(){
  580. return h(g((new Date()).getTime()));
  581. }
  582. function w(e,n){
  583. return n ? p(String(e)).replace(/[+\/]/g, function(e) {
  584. return "+" == e ? "-" : "_";
  585. }).replace(/=/g, "") : p(String(e));
  586. }
  587. return w(getCookie(name));
  588. }
  589.  
  590. //获取下载地址。这个地址不是直接下载地址,访问这个地址会返回302,response header中的location才是真实下载地址
  591. //暂时没有找到提取方法
  592. function getDownloadLinkWithPanAPI(fidlist,type){
  593. var downloadUrl = panAPIUrl + "download";
  594. var link = null;
  595. var params= {
  596. sign:sign,
  597. timestamp:timestamp,
  598. fidlist:fidlist,
  599. type:type,
  600. channel:'chunlei',
  601. web:1,
  602. app_id:250528,
  603. bdstoken:bdstoken,
  604. logid:logid,
  605. clienttype:0
  606. };
  607. $.ajax({
  608. url:downloadUrl,
  609. async:false,
  610. method:'GET',
  611. data:params,
  612. success:function(result){
  613. if (type == 'dlink')
  614. link = result.dlink[0].dlink;
  615. else if (type == 'batch')
  616. link = result.dlink;
  617. }
  618. });
  619. return link;
  620. }
  621.  
  622. function getDownloadLinkWithRESTAPI1(path){
  623. var link = restAPIUrl1 + 'file?method=download&app_id=250528&path=' + path;
  624. return link;
  625. }
  626. function getDownloadLinkWithRESTAPI2(path){
  627. var link = restAPIUrl1 + 'file?method=download&app_id=266719&path=' + path;
  628. return link;
  629. }
  630. function execDownload(link){
  631. console.log('selectList:');
  632. console.log(selectList);
  633. console.log("download link:"+link);
  634. $('#helperdownloadiframe').attr('src',link);
  635. }
  636.  
  637. function createIframe(){
  638. var $div = $('<div class="helper-hide" style="padding:0;margin:0;display:block"></div>');
  639. var $iframe = $('<iframe src="javascript:void(0)" id="helperdownloadiframe" style="display:none"></iframe>');
  640. $div.append($iframe);
  641. $('body').append($div);
  642.  
  643. }
  644.  
  645. function base64Encode(t){
  646. var a, r, e, n, i, s, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  647. for (e = t.length,r = 0,a = ""; e > r; ) {
  648. if (n = 255 & t.charCodeAt(r++),r == e) {
  649. a += o.charAt(n >> 2);
  650. a += o.charAt((3 & n) << 4);
  651. a += "==";
  652. break;
  653. }
  654. if (i = t.charCodeAt(r++),r == e) {
  655. a += o.charAt(n >> 2);
  656. a += o.charAt((3 & n) << 4 | (240 & i) >> 4);
  657. a += o.charAt((15 & i) << 2);
  658. a += "=";
  659. break;
  660. }
  661. s = t.charCodeAt(r++);
  662. a += o.charAt(n >> 2);
  663. a += o.charAt((3 & n) << 4 | (240 & i) >> 4);
  664. a += o.charAt((15 & i) << 2 | (192 & s) >> 6);
  665. a += o.charAt(63 & s);
  666. }
  667. return a;
  668. }
  669. })();