夸克云盘

解除浏览器大文件下载,自定义提取码

  1. // ==UserScript==
  2. // @name 夸克云盘
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description 解除浏览器大文件下载,自定义提取码
  6. // @author by小怪
  7.  
  8. // @match https://pan.quark.cn/s/*
  9. // @match https://pan.quark.cn/list*
  10. // @connect drive.quark.cn
  11. // @connect pan.quark.cn
  12. // @icon https://pan.quark.cn/favicon.ico
  13. // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
  14. // @run-at document-body
  15. // @grant unsafeWindow
  16. // @grant GM_xmlhttpRequest
  17. // @grant window.onurlchange
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22. unsafeWindow = unsafeWindow || window;
  23. var $ = $ || window.$;
  24. var quark = {
  25. file:[]
  26. };
  27.  
  28. class XMLHttp {
  29. request_m = function (param) {};
  30. response_m = function (param) {};
  31. request_s = function (param) {};
  32. response_s = function (param) {};
  33. }
  34. let http = new XMLHttp();
  35.  
  36. //分享页面
  37. quark.sharePage=function(){
  38. // XMLHttpRequest 拦截
  39. http.request_s = function (param) {
  40. //console.log(param, "---request");
  41. // if (res.config.url.includes("file/sort")) {
  42. // console.log(JSON.parse(res.response));
  43.  
  44. //}
  45. };
  46. http.response_s = function (res) {
  47. //console.log(res, "---response");
  48. //文件详情
  49. if (res.config.url!=null&&res.config.url.includes("share/sharepage/detail")) {
  50. console.log(JSON.parse(res.response));
  51. // quark.download('94a968da04694fb6aa25fb0e214a7767',function(result){
  52. // console.log('下载---',result);
  53.  
  54. // });
  55. // quark.play('94a968da04694fb6aa25fb0e214a7767',function(result){
  56. // console.log('获取视频---',result);
  57.  
  58. // });
  59. }
  60.  
  61. }
  62. // 初始化 XMLHttpRequest
  63. quark.initXMLHttpRequest_s();
  64.  
  65.  
  66.  
  67. }
  68.  
  69. //主页面
  70. quark.mainPage=function(){
  71. //监听
  72. // XMLHttpRequest 拦截
  73. http.request_m = function (param) {
  74. console.log(param, "---request");
  75. // if (res.config.url.includes("file/sort")) {
  76. // console.log(JSON.parse(res.response));
  77.  
  78. //}
  79. };
  80. http.response_m = function (res) {
  81. console.log(res, "---response");
  82. //获取列表
  83. if (res.config.url!=null&&res.config.url.includes("file/sort")) {
  84. console.log(JSON.parse(res.response));
  85. quark.mainList(JSON.parse(res.response));
  86. }
  87. //判断分享码是否一样
  88. if (res.config.url!=null&&res.config.url.includes("/share/password?pr=ucpro&fr=pc")) {
  89. var share_pwd = localStorage.getItem("share_pwd");
  90. if (share_pwd!=null&&JSON.parse(res.response).data.passcode == share_pwd) {
  91. quark.showTipSuccess("自定义分享密码 成功");
  92. }
  93. else {
  94. localStorage.removeItem("share_pwd");
  95. quark.showTipError("自定义分享密码 失败,请修改分享密码后重试");
  96. }
  97. }
  98.  
  99.  
  100.  
  101. }
  102. // 初始化 XMLHttpRequest
  103. quark.initXMLHttpRequest_m();
  104.  
  105. }
  106. //获取列表
  107. quark.mainList=function(result){
  108. //获取每个下载地址
  109. let arr=[];
  110. for(let i=0; i<result.data.list.length;i++){
  111. if(!result.data.list[i].format_type==""){
  112. arr.push(result.data.list[i].fid);
  113. }
  114. }
  115. quark.file=arr;
  116.  
  117. if(document.getElementById("file-list")){
  118.  
  119. //存在
  120. }else{
  121. //不存在
  122. //展示按钮
  123. var html = '<button type="button" class="ant-btn btn-file ant-btn-primary btn-create-folder" id="file-list"><img class="btn-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAAD4/042AAABAklEQVRoBe1XQQ6EIAzUPfiH3Rf7Dh+nz2DbhINLphrpIkiGhKgjxXaGJuMwcJABMkAGumMghDDJnGWucer99JhCY/Jy+RnzkwpQ5tOxlihgLLGpZo72HWUg3IO9PMEtxLKA2ipQASrgZIBHyEmgO5wKuCl0btCvAmJn9pY4NWaHzxaph0H4pZrCPCseA/G296OmFTfdoeSo9vdtsXkzvomR/aBv9tsDUu2CKq6EXc9FjlB2E/+xRU6b2OwBD9NaAIrnHxlgpesmBvW2B1GB2ppQASrgZIBHyEmgO5wKGBRuAEcYWHYNKqXAAtJAGFjWAJRY8VNL3EDKTIEMkAEykMnAFyXm+VFrbT4RAAAAAElFTkSuQmCC"><span>文件下载列表</span></button>';
  124. $(".btn-main").append(html);
  125. }
  126.  
  127. //监听按钮打开
  128. $(document).on("click", "#file-list", function () {
  129. //alert(1);
  130. let html_model_list='<div><div class="ant-modal-root" id="model-list"><div class="ant-modal-mask"></div><div tabindex="-1" class="ant-modal-wrap ant-modal-centered" role="dialog" aria-labelledby="rcDialogTitle1"><div role="document" class="ant-modal move-to-modal" style="width: 720px; transform-origin: 724px 405px;"><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden; outline: none;"></div><div class="ant-modal-content"><button type="button" aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x" id="close-list"><i aria-label="图标: close"class="anticon anticon-close ant-modal-close-icon"><svg viewBox="64 64 896 896"focusable="false" class="" data-icon="close" width="1em" height="1em"fill="currentColor" aria-hidden="true"><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button><div class="ant-modal-header"><div class="ant-modal-title" id="rcDialogTitle1">下载列表</div></div><div class="ant-modal-body"><div class="move-to-container"><ul class="ant-tree ant-tree-directory" role="tree" unselectable="on">';
  131. quark.download(quark.file,function(result){
  132. for(let i=0; i<result.length;i++){
  133. html_model_list+='<li class="ant-tree-treenode-switcher-open ant-tree-treenode-selected" role="treeitem">'+(i+1)+','+result[i].file_name+'<br /> <a href="'+result[i].download_url+'">'+result[i].download_url+'</a> </li>';
  134. }
  135.  
  136. html_model_list+='</ul></div></div><div class="ant-modal-footer"><div class="move-to-footer "><div class="buttons-wrap"> <button type="button"class="ant-btn btn-file btn-file-primary ant-btn-primary" id="close-list"><span>关闭</span></button></div></div></div></div><div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden; outline: none;"></div></div></div></div></div>';
  137. $(document.body).append(html_model_list);
  138. });
  139.  
  140. });
  141.  
  142. //关闭列表
  143. $(document).on("click", "#close-list", function () {
  144. $("#model-list").remove();
  145. });
  146.  
  147.  
  148.  
  149.  
  150. };
  151.  
  152. //下载
  153. quark.download = function (fids,callback) {
  154. GM_xmlhttpRequest({
  155. method: "POST",
  156. url: "https://drive.quark.cn/1/clouddrive/file/download?pr=ucpro&fr=pc",
  157. headers: {
  158. "Content-Type": "application/json;charset=utf-8"
  159. },
  160. data: JSON.stringify({"fids": fids}),
  161. onload: function (res) {
  162. let resData = JSON.parse(res.responseText).data;
  163. if (resData === undefined || resData.length === 0) {
  164. //失败
  165. quark.showTipError("获取列表失败!");
  166. callback("");
  167. } else {
  168. //成功
  169. quark.showTipSuccess("获取列表成功!");
  170. }
  171.  
  172. callback(resData);
  173. //cosnole.log(o.download_url);
  174.  
  175. }
  176. });
  177. };
  178.  
  179. //视频地址
  180. quark.play = function (fids,callback) {
  181. GM_xmlhttpRequest({
  182. method: "POST",
  183. url: "https://drive.quark.cn/1/clouddrive/file/v2/play?pr=ucpro&fr=pc",
  184. headers: {
  185. "Content-Type": "application/json;charset=utf-8"
  186. },
  187. data: JSON.stringify({"fid":fids,"resolutions":"normal,low,high,super,2k,4k","supports":"fmp4"}),
  188. onload: function (res) {
  189. let resData = JSON.parse(res.responseText).data;
  190. if (resData === undefined || resData.length === 0) {
  191. //失败
  192. quark.showTipError("获取视频失败!");
  193. callback("");
  194. } else {
  195. //成功
  196. quark.showTipSuccess("获取视频成功!");
  197. }
  198.  
  199. callback(resData);
  200. //cosnole.log(o.download_url);
  201.  
  202. }
  203. });
  204. };
  205.  
  206.  
  207.  
  208. //获取Storage
  209. quark.getItem = function(n) {
  210. n = window.localStorage.getItem(n)|| sessionStorage.getItem(n);;
  211.  
  212. if (!n) {
  213. return null;
  214. }
  215. try {
  216. return JSON.parse(n);
  217. } catch (e) {
  218. return n;
  219. }
  220. };
  221.  
  222.  
  223. //自定义提取码
  224. //url_type=1 是没有提取码 2是提取码
  225. //
  226. quark.customSharePwd=function(){
  227. //监听
  228. $(document).on("DOMNodeInserted", ".ant-modal-root", function() {
  229. var text = $(this).find(".ant-modal-title").text();
  230. if (text == "分享文件") {
  231. if ($(".input-share-pwd").length == 0) {
  232. var sharePwd = localStorage.getItem("share_pwd");
  233. var html = '<div class="oper-row"><span class="oper-name" style="width: auto;">自定义提取码</span><span class="oper-area">';
  234. //html += '<input type="text" class="ant-input input-share-pwd" value="' + (sharePwd ? sharePwd : "") + '" placeholder="" style="margin-left: 12px;width: 100px;height: 25px;line-height: normal;border: 1px solid #D4D7DE;text-align: center;"></div>'
  235. html+='<input placeholder="选择需要自定义" class="ant-input code-input input-share-pwd" type="text" value="' + (sharePwd ? sharePwd : "") + '" name="passcode"></span></div>';
  236. $(".create-share-body").append(html);
  237. sendSharePwd();
  238. }
  239. }
  240.  
  241. });
  242.  
  243. //判断获取的值
  244. function sendSharePwd () {
  245. (function(send) {
  246. XMLHttpRequest.prototype.send = function() {
  247. if (arguments.length && typeof arguments[0] == "string" && arguments[0].includes("fid_list")) {
  248. var share_pwd = localStorage.getItem("share_pwd");
  249. if (share_pwd) {
  250. var body = JSON.parse(arguments[0]);
  251. body.passcode = share_pwd;
  252. arguments[0] = JSON.stringify(body);
  253. }
  254. }
  255. send.apply(this, arguments);
  256. };
  257. })(XMLHttpRequest.prototype.send);
  258. }
  259.  
  260.  
  261. //获取修改的值
  262. $(document).on("change", ".input-share-pwd", function () {
  263. var value = this.value;
  264. localStorage.setItem("share_pwd", value);
  265. });
  266.  
  267.  
  268.  
  269.  
  270. };
  271.  
  272. //提示成功
  273. quark.showTipSuccess = function (msg, timeout) {
  274. quark.hideTip();
  275. var $element = $(".ant-message");
  276. if ($element.length) {
  277. $element.html('<span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-success"><i aria-label="icon: check-circle" class="anticon anticon-check-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg></i><span>'+msg+'</span></div></div></div></span>');
  278. }
  279. else {
  280. $(document.body).append('<div><div class="ant-message"><span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-success"><i aria-label="icon: check-circle" class="anticon anticon-check-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg></i><span>' + msg + '</span></div></div></div></span></div></div>');
  281. }
  282.  
  283. setTimeout(function () {
  284. quark.hideTip();
  285. }, timeout || 3000);
  286. };
  287. //提示失败
  288. quark.showTipError = function (msg, timeout) {
  289. quark.hideTip();
  290. var $element = $(".ant-message");
  291. if ($element.length) {
  292. $element.html('<span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-error"><i aria-label="icon: close-circle" class="anticon anticon-close-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 0 1-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"></path></svg></i><span>'+msg+'</span></div></div></div></span>');
  293. }
  294. else {
  295. $(document.body).append('<div><div class="ant-message"><span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-error"><i aria-label="icon: close-circle" class="anticon anticon-close-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 0 1-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"></path></svg></i><span>'+msg+'</span></div></div></div></span></div></div>');
  296. }
  297.  
  298. setTimeout(function () {
  299. quark.hideTip()
  300. }, timeout || 3000);
  301. };
  302.  
  303. //隐藏
  304. quark.hideTip = function() {
  305. $(".ant-message").html('<span></span>');
  306. };
  307.  
  308. // 初始化 拦截XMLHttpRequest 主页面
  309. quark.initXMLHttpRequest_m= function() {
  310. let open = XMLHttpRequest.prototype.open;
  311. XMLHttpRequest.prototype.open = function(...args){
  312. let send = this.send;
  313. let _this = this
  314. let post_data = []
  315. this.send = function (...data) {
  316. post_data = data;
  317. return send.apply(_this, data)
  318. }
  319. // 请求前拦截
  320. http.request_m(args)
  321.  
  322. this.addEventListener('readystatechange', function () {
  323. if (this.readyState === 4) {
  324. let config = {
  325. url: args[1],
  326. status: this.status,
  327. method: args[0],
  328. data: post_data
  329. }
  330. // 请求后拦截
  331. http.response_m({config, response: this.response})
  332. }
  333. }, false)
  334. return open.apply(this, args);
  335. }
  336.  
  337. };
  338. //分享页面
  339. quark.initXMLHttpRequest_s= function() {
  340. let open = XMLHttpRequest.prototype.open;
  341. XMLHttpRequest.prototype.open = function(...args){
  342. let send = this.send;
  343. let _this = this
  344. let post_data = []
  345. this.send = function (...data) {
  346. post_data = data;
  347. return send.apply(_this, data)
  348. }
  349. // 请求前拦截
  350. http.request_s(args)
  351.  
  352. this.addEventListener('readystatechange', function () {
  353. if (this.readyState === 4) {
  354. let config = {
  355. url: args[1],
  356. status: this.status,
  357. method: args[0],
  358. data: post_data
  359. }
  360. // 请求后拦截
  361. http.response_s({config, response: this.response})
  362. }
  363. }, false)
  364. return open.apply(this, args);
  365. }
  366.  
  367. }
  368.  
  369. //初始化
  370. quark.install= function () {
  371. var url = location.href;
  372. if (url.indexOf(".quark.cn/s/") > 0) {
  373. //分享页面初始化
  374. quark.sharePage();
  375. quark.showTipSuccess("夸克云盘插件初始化成功!");
  376. }
  377. else if (url.indexOf(".quark.cn/list") > 0) {
  378. // debugger
  379. //主页面初始化
  380. quark.customSharePwd();
  381. quark.showTipSuccess("夸克云盘插件初始化成功!");
  382. quark.mainPage();
  383. }
  384.  
  385. }();
  386. // Your code here...
  387. })();