天翼云盘跳过客户端下载文件

跳过客户端,直接下载文件

  1. // ==UserScript==
  2. // @name 天翼云盘跳过客户端下载文件
  3. // @icon http://cloud.189.cn/logo.ico
  4. // @version 0.2
  5. // @namespace http://astwy.com
  6. // @description 跳过客户端,直接下载文件
  7. // @author 艾斯托维亚
  8. // @include *//cloud.189.cn/*
  9. // @require https://cdn.staticfile.org/jquery/3.5.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. "use strict";
  14. window.onload = hfxz;
  15. })();
  16.  
  17. function hfxz()
  18. {
  19. console.log(1);
  20. var url = window.location.href;
  21. var match = url.match(/cloud\.189\.cn\/t\/([0-9a-z]+)/i);
  22. var shortCode= match ? match[1] : null;
  23. if (url.indexOf("cloud.189.cn/main") > 0 || url.indexOf("cloud.189.cn/photo") > 0) {
  24. if ($("#J_Create").length)
  25. {
  26. $("#J_Create").after('<a class="btn btn-show-link" style="background: #2b89ea; color: #fff; cursor: pointer">显示链接</a>');
  27. }
  28. else if ($(".JC_Refresh").length) {
  29. $(".JC_Refresh").after('<a class="btn btn-show-link" style="background: #2b89ea; color: #fff; cursor: pointer">显示链接</a>');
  30. }
  31. else {}
  32. }
  33. else if(url.indexOf("cloud.189.cn/t") > 0){
  34. if("undefined" != typeof _shareId){
  35. if ($("#J_SaveAs").length)
  36. {
  37. $("#J_SaveAs").after('<a class="btn btn-show-link" style="background: #2b89ea; color: #fff; cursor: pointer">显示链接</a>');
  38. $(".btn-show-link").on("click", showDownload);
  39. }
  40. else if ($(".JC_Refresh").length) {
  41. $(".JC_Refresh").after('<a class="btn btn-show-link" style="background: #2b89ea; color: #fff; cursor: pointer">显示链接</a>');
  42. }
  43. else {}
  44. }
  45. else{
  46. for(var t=document.getElementsByTagName("a"),e=0;e<t.length;e++){"btn btn-download download-link disable"===t[e].getAttribute("class")&&t[e].setAttribute("class","btn btn-download download-link")}
  47. console.log("恢复单文件下载按钮");
  48. }
  49. }
  50. else{}
  51. };
  52. function getSelectedFileList () {
  53. var mainView = null, fileList = [];
  54. if (unsafeWindow.fileId) {
  55. fileList = [
  56. {
  57. attributes: unsafeWindow
  58. }
  59. ];
  60. }
  61. else if (unsafeWindow._shareId) {
  62. mainView = unsafeWindow.appRouter.mainView;
  63. if (mainView instanceof Object && mainView.fileList) {
  64. fileList = mainView.fileList;
  65. if (fileList.selected().length) {
  66. fileList = fileList.selected();
  67. }
  68. }
  69. //obj.processFileList(fileList, unsafeWindow._shareId);
  70. }
  71. else if (unsafeWindow.mainView) {
  72. mainView = unsafeWindow.mainView;
  73. if (mainView.fileListTabObj && mainView.fileListTabObj[mainView.options.fileId]) {
  74. fileList = mainView.fileListTabObj[mainView.options.fileId].fileList.selected();
  75. }
  76. else if (mainView.getSelectedModels) {
  77. fileList = mainView.getSelectedModels();
  78. }
  79. }
  80.  
  81. var selectedFileList = [];
  82. fileList.forEach(function (item) {
  83. if (item.attributes.fileId > 0) {
  84. selectedFileList.push(item);
  85. }
  86. });
  87. return selectedFileList;
  88. };
  89.  
  90. function getMetadata(){
  91. var url = window.location.href;
  92. var match = url.match(/cloud\.189\.cn\/t\/([0-9a-z]+)/i);
  93. var shortCode= match ? match[1] : null;
  94. var result;
  95. $.ajax({
  96. url: "https://cloud.189.cn/v2/listShareDirByShareIdAndFileId.action?shortCode=" + shortCode + "&accessCode="+getCookie("shareId_"+_shareId)+"&verifyCode="+_verifyCode+"&orderBy=1&order=ASC&pageNum=1&pageSize=60",
  97. type: "get",
  98. dateType: "json",
  99. async:false,
  100. success: function (data) {
  101. result=data;
  102. //console.log(_shareId);
  103. },
  104. error: function () {
  105. }
  106. });
  107. return result;
  108. }
  109.  
  110. function buildFolderDownUrl(fileId){
  111. var sessionKey=getCookie("validCodeTimestamp");
  112. var result="https://cloud.189.cn/downloadMultiFiles.action?sessionKey="+sessionKey+"&fileIdS="+fileId+"&downloadType=3&shareId="+_shareId;
  113. return result;
  114. }
  115.  
  116. function getFileDownUrl(fileId,subFileId){
  117. var result="";
  118. var s_url = window.location.href;
  119. var match = s_url.match(/cloud\.189\.cn\/t\/([0-9a-z]+)/i);
  120. var shortCode= match ? match[1] : null;
  121. $.ajax({
  122. url: "https://cloud.189.cn/v2/getFileDownloadUrl.action?shortCode="+shortCode+"&fileId="+subFileId+"&accessCode="+getCookie("shareId_"+_shareId)+"&subFileId="+fileId+"&noCache=0.1",
  123. type: "get",
  124. dateType: "text",
  125. async:false,
  126. success: function (data) {
  127. //console.log(data);
  128. result= data;
  129. },
  130. error: function (data) {
  131. console.log(666);
  132. }
  133. });
  134. return result;
  135. }
  136.  
  137. function showDownload () {
  138. var sels=getSelectedFileList ();
  139. showDownloadPage();
  140. var html = '<div style="padding: 20px; height: 410px; overflow-y: auto;">';
  141. var rowStyle = "margin:10px 0px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;";
  142.  
  143. var tmp=getMetadata();
  144. if (tmp.path) {
  145. html += '<p>压缩包</p>';
  146. html += '<p style="' + rowStyle + '"><a title="' + tmp.path[0].fileName + '-打包下载.zip" href="' + buildFolderDownUrl(tmp.path[0].fileId) + '&fileName=打包下载.zip" style="color: blue;">' + tmp.path[0].fileName + '-打包下载.zip</a></p>';
  147. html += '<p>&nbsp;</p>';
  148. }
  149.  
  150. sels.forEach(function (item, index) {
  151. var file=item.attributes;
  152. if(file.isFolder){
  153. var f_downloadUrl = buildFolderDownUrl(file.fileId)+'&fileName=打包下载.zip';
  154. html += '<p>' + (++index) + ':' + (file.fileName ? file.fileName : file.fileId) + '打包下载</p>';
  155. html += '<p style="' + rowStyle + '"><a title="' + f_downloadUrl + '" href="' + f_downloadUrl + '" style="color: blue;">' + f_downloadUrl + '</a></p>';
  156. }
  157. else{
  158. var s_downloadUrl = "https:"+getFileDownUrl(file.fileId,file.parentId)+'&fileName='+file.fileName;
  159. html += '<p>' + (++index) + ':' + (file.fileName ? file.fileName : file.fileId) +' '+file.fileSize+ '</p>';
  160. html += '<p style="' + rowStyle + '"><a title="' + s_downloadUrl + '" href="' + s_downloadUrl + '" style="color: blue;">' + s_downloadUrl + '</a></p>';
  161. }
  162. });
  163.  
  164. html += '<div>';
  165. $("#J_FileModal .modal-body").html(html);
  166. $("#J_FileModal").show();
  167. }
  168.  
  169. function showDownloadPage() {
  170. var template = '<div id="J_FileModal" class="treeBox-modal modal in" style="display:block"><div class="modal-dialog"><div class="modal-header"><a class="close">×</a><h3>文件下载</h3></div><h3>点击蓝色的链接或右键另存为即可下载,文件夹打包下载必须点击跳转进行下载</h3><div class="modal-body"></div></div></div>';
  171. if ($("#J_FileModal").length == 0) {
  172. $("body").append(template);
  173. $("#J_FileModal .close").on("click", function () {
  174. $("#J_FileModal").hide();
  175. });
  176. }
  177. }
  178.  
  179. function jsdx(num){
  180. }
  181.  
  182. function getCookie(name){
  183. var strcookie = document.cookie;//获取cookie字符串
  184. var arrcookie = strcookie.split("; ");//分割
  185. //遍历匹配
  186. for ( var i = 0; i < arrcookie.length; i++) {
  187. var arr = arrcookie[i].split("=");
  188. if (arr[0] == name){
  189. return arr[1];
  190. }
  191. }
  192. return "";
  193. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址