Greasy Fork is available in English.

获取夸克网盘文件列表

获取并显示文件列表

질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name 获取夸克网盘文件列表
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description 获取并显示文件列表
  6. // @author 21zys
  7. // @match *://pan.quark.cn/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 等待页面完全加载后执行
  16. window.addEventListener('load', function() {
  17. // 查找目标位置
  18. const targetDiv = document.querySelector('div.SectionHeaderController--section-header-right--QIJ-wNk');
  19.  
  20. if (targetDiv) {
  21. // 创建按钮
  22. const button = document.createElement('button');
  23. button.type = 'button';
  24. button.className = 'ant-btn btn-file btn-create-folder';
  25. button.style = 'margin-right: 12px;'
  26. button.innerText = '获取文件列表';
  27.  
  28. // 按钮点击事件
  29. button.addEventListener('click', function() {
  30. // 获取文件列表
  31. let page = 1;
  32. let pdir_fid = '';
  33. const url = window.location.href;
  34.  
  35. // 用 '/' 分割并取最后一个字符串
  36. const lastSegment = url.split('/').pop();
  37.  
  38. // 用 '-' 分割并取第一个字符串
  39. pdir_fid = lastSegment.split('-')[0];
  40.  
  41. // 获取当前域名的cookie
  42. const cookie = document.cookie;
  43.  
  44.  
  45. let results = [];
  46.  
  47.  
  48. function fetchPage(page) {
  49. const xhr = new XMLHttpRequest();
  50. const url = `https://drive-pc.quark.cn/1/clouddrive/file/sort?pr=ucpro&fr=pc&uc_param_str=&pdir_fid=${pdir_fid}&_page=${page}&_size=500&_fetch_total=1&_fetch_sub_dirs=0&_sort=file_type:asc,file_name:asc`;
  51.  
  52. xhr.open('GET', url, false);
  53.  
  54. // 设置withCredentials为true,允许跨域请求发送cookie
  55. xhr.withCredentials = true;
  56.  
  57. // 设置cookie请求头
  58. xhr.setRequestHeader('Cookie', cookie);
  59.  
  60. xhr.onreadystatechange = function () {
  61. if (xhr.readyState === 4 && xhr.status === 200) {
  62. const response = JSON.parse(xhr.responseText);
  63. const data = response.data;
  64.  
  65. // 如果data或list为空,则停止请求
  66. if (!data || !data.list || data.list.length === 0) {
  67. return;
  68. }
  69.  
  70. // 将每个对象的 file_name 追加到 results 数组中
  71. data.list.forEach(item => {
  72. results.push(item.file_name);
  73. });
  74.  
  75. // 请求下一页
  76. fetchPage(page + 1);
  77. } else if (xhr.readyState === 4) {
  78. console.error('请求出错:', xhr.status);
  79. }
  80. };
  81.  
  82. xhr.send();
  83. }
  84.  
  85. fetchPage(page);
  86.  
  87. // 创建一个文本域用于显示结果
  88. const textarea = document.createElement('textarea');
  89. textarea.value = results.join('\n');
  90. textarea.style.width = '100%';
  91. textarea.style.height = '300px';
  92.  
  93. // 弹出一个对话框,包含文本域
  94. const dialog = document.createElement('div');
  95. dialog.style.position = 'fixed';
  96. dialog.style.top = '50%';
  97. dialog.style.left = '50%';
  98. dialog.style.transform = 'translate(-50%, -50%)';
  99. dialog.style.zIndex = '9999';
  100. dialog.style.backgroundColor = 'white';
  101. dialog.style.border = '1px solid #ccc';
  102. dialog.style.padding = '20px';
  103. dialog.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
  104.  
  105. // 关闭按钮
  106. const closeButton = document.createElement('button');
  107. closeButton.innerText = '关闭';
  108. closeButton.style.marginTop = '10px';
  109.  
  110. closeButton.addEventListener('click', function() {
  111. document.body.removeChild(dialog);
  112. });
  113.  
  114. dialog.appendChild(textarea);
  115. dialog.appendChild(closeButton);
  116.  
  117. document.body.appendChild(dialog);
  118. });
  119.  
  120. // 将按钮添加到目标位置
  121. targetDiv.insertBefore(button, targetDiv.firstChild);
  122. }
  123. });
  124. })();