🏠 Home 

蓝奏云网盘增强

文件排序、刷新不回根目录、快捷返回上一级(右键网页空白处)、后退返回上一级、右键文件显示菜单、点击直接下载文件、点击空白进入目录、自动显示更多文件、一键复制所有分享链接、自定义分享链接域名、自动打开/复制分享链接、带密码的分享链接自动输密码、拖入文件自动显示上传框、输入密码后回车确认、优化编辑框初始大小


ติดตั้งสคริปต์นี้?
สคริปต์ที่แนะนำของผู้เขียน

คุณอาจชื่นชอบ AutoPager


ติดตั้งสคริปต์นี้
  1. // ==UserScript==
  2. // @name 蓝奏云网盘增强
  3. // @version 1.5.6
  4. // @author X.I.U
  5. // @description 文件排序、刷新不回根目录、快捷返回上一级(右键网页空白处)、后退返回上一级、右键文件显示菜单、点击直接下载文件、点击空白进入目录、自动显示更多文件、一键复制所有分享链接、自定义分享链接域名、自动打开/复制分享链接、带密码的分享链接自动输密码、拖入文件自动显示上传框、输入密码后回车确认、优化编辑框初始大小
  6. // @match *://lanzou.com/u
  7. // @match *://www.lanzou.com/u
  8. // @match *://www.lanzou.com/account.php*
  9. // @match *://up.woozooo.com/u
  10. // @match *://up.woozooo.com/mydisk.php*
  11. // @match *://pc.woozooo.com/u
  12. // @match *://pc.woozooo.com/mydisk.php*
  13. // @match *://pan.lanzou.com/*
  14. // @match *://*.lanzoub.com/*
  15. // @match *://*.lanzoue.com/*
  16. // @match *://*.lanzouf.com/*
  17. // @match *://*.lanzouh.com/*
  18. // @match *://*.lanzoui.com/*
  19. // @match *://*.lanzouj.com/*
  20. // @match *://*.lanzoul.com/*
  21. // @match *://*.lanzoum.com/*
  22. // @match *://*.lanzouo.com/*
  23. // @match *://*.lanzoup.com/*
  24. // @match *://*.lanzouq.com/*
  25. // @match *://*.lanzout.com/*
  26. // @match *://*.lanzouu.com/*
  27. // @match *://*.lanzouv.com/*
  28. // @match *://*.lanzouw.com/*
  29. // @match *://*.lanzoux.com/*
  30. // @match *://*.lanzouy.com/*
  31. // @match *://*.lanzob.com/*
  32. // @match *://*.lanzoe.com/*
  33. // @match *://*.lanzof.com/*
  34. // @match *://*.lanzoh.com/*
  35. // @match *://*.lanzoi.com/*
  36. // @match *://*.lanzoj.com/*
  37. // @match *://*.lanzol.com/*
  38. // @match *://*.lanzom.com/*
  39. // @match *://*.lanzoo.com/*
  40. // @match *://*.lanzop.com/*
  41. // @match *://*.lanzoq.com/*
  42. // @match *://*.lanzot.com/*
  43. // @match *://*.lanzov.com/*
  44. // @match *://*.lanzow.com/*
  45. // @match *://*.lanzox.com/*
  46. // @match *://*.lanzoy.com/*
  47. // @match *://*.lanzb.com/*
  48. // @match *://*.lanze.com/*
  49. // @match *://*.lanzf.com/*
  50. // @match *://*.lanzh.com/*
  51. // @match *://*.lanzi.com/*
  52. // @match *://*.lanzj.com/*
  53. // @match *://*.lanzl.com/*
  54. // @match *://*.lanzm.com/*
  55. // @match *://*.lanzo.com/*
  56. // @match *://*.lanzp.com/*
  57. // @match *://*.lanzq.com/*
  58. // @match *://*.lanzt.com/*
  59. // @match *://*.lanzv.com/*
  60. // @match *://*.lanzw.com/*
  61. // @match *://*.lanzx.com/*
  62. // @match *://*.lanzy.com/*
  63. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABZ0lEQVR4nJ2TvW4UQRCEv+q9H8wGwFlIOEQQIRmnCIcnEidkSAQYEpwQIPEoZPgliB04IiW15JRXAMkne3e6COaMZe7HiEqmpzVV01PTLR9g1kIAGNdYQgrIAmliPfkSRghFQEk46yGB8S0GN3IF9fKAWYHJJjzbx0/30P1H/yBggwKfF9h5gfa/wObDeV6LAkYQDWTWq5shml3A9hR9+AqjFrLMnVkigECzHhqgEf51Affuotef8ahF2UNc0QZ/s9UZnr/Cu+/Q8DZ8O8TDDbT1pDof1ylXu2iqSdP38OYQ2VhCj3dh9rM+LhY/rQooII3bMUw/1veVrhIU0E5WehxWQILPEjRC7QQDbga1XKk6vgIDuoRxi/bews5LvHGnFqU/DXDZjMuRnx44T49t2860nc756rSzL/P8cpAnRzUqnV36hQOlO7ezrBRQ2pYLEFigtfUuMRHAiptGcrWAfnyvk/afEr8Bt+re7W42OSoAAAAASUVORK5CYII=
  64. // @grant GM_xmlhttpRequest
  65. // @grant GM_registerMenuCommand
  66. // @grant GM_unregisterMenuCommand
  67. // @grant GM_openInTab
  68. // @grant GM_getValue
  69. // @grant GM_setValue
  70. // @grant GM_notification
  71. // @grant GM_setClipboard
  72. // @grant unsafeWindow
  73. // @sandbox JavaScript
  74. // @noframes
  75. // @license GPL-3.0 License
  76. // @run-at document-end
  77. // @namespace https://github.com/XIU2/UserScript
  78. // @supportURL https://github.com/XIU2/UserScript
  79. // @homepageURL https://github.com/XIU2/UserScript
  80. // ==/UserScript==
  81. (function() {
  82. 'use strict';
  83. var menu_ALL = [
  84. ['menu_customFileSha', '自定义分享链接域名', '自定义分享链接域名', ''],
  85. ['menu_open_fileSha', '自动打开分享链接', '自动打开分享链接', true],
  86. ['menu_copy_fileSha', '自动复制分享链接', '自动复制分享链接', true],
  87. ['menu_refreshCorrection', '刷新不返回根目录', '刷新不返回根目录', true],
  88. ['menu_rightClickMenu', '右键文件显示菜单', '右键文件显示菜单', true],
  89. ['menu_directDownload', '点击直接下载文件 (分享链接列表页)', '点击直接下载文件', true],
  90. ['menu_folderDescdesMenu', '优化编辑框初始大小', '优化编辑框初始大小', true],
  91. ['menu_fileSort', '文件排序', '文件排序', true]
  92. ], menu_ID = [], lastFolderID;
  93. for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
  94. if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
  95. }
  96. registerMenuCommand();
  97. // 注册脚本菜单
  98. function registerMenuCommand() {
  99. if (menu_ID.length > menu_ALL.length){ // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单
  100. for (let i=0;i<menu_ID.length;i++){
  101. GM_unregisterMenuCommand(menu_ID[i]);
  102. }
  103. }
  104. for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
  105. menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
  106. if (menu_ALL[i][0] == 'menu_refreshCorrection') {
  107. menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❌'} ${menu_ALL[i][1]}`, function(){if(menu_value('menu_refreshCorrection')){UNrefreshCorrection();}else{refreshCorrection();};menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`)});
  108. } else if (menu_ALL[i][0] === 'menu_customFileSha') {
  109. menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){customFileSha()});
  110. } else {
  111. menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❌'} ${menu_ALL[i][1]}`, function(){menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`)});
  112. }
  113. }
  114. menu_ID[menu_ID.length] = GM_registerMenuCommand('💬 反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419224/feedback', {active: true,insert: true,setParent: true});});
  115. }
  116. // 菜单开关
  117. function menu_switch(menu_status, Name, Tips) {
  118. if (menu_status == 'true') {
  119. GM_setValue(`${Name}`, false);
  120. if (Name == 'menu_refreshCorrection') {
  121. GM_notification({text: `已关闭 [${Tips}] 功能`, timeout: 3500});
  122. } else {
  123. GM_notification({text: `已关闭 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  124. }
  125. } else {
  126. GM_setValue(`${Name}`, true);
  127. if (Name == 'menu_refreshCorrection') {
  128. GM_notification({text: `已开启 [${Tips}] 功能`, timeout: 3500});
  129. } else {
  130. GM_notification({text: `已开启 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  131. }
  132. }
  133. registerMenuCommand(); // 重新注册脚本菜单
  134. };
  135. // 返回菜单值
  136. function menu_value(menuName) {
  137. for (let menu of menu_ALL) {
  138. if (menu[0] == menuName) {
  139. return menu[3]
  140. }
  141. }
  142. }
  143. if (window.top.location.pathname === '/u' || window.top.location.pathname.indexOf('account.php') > -1 || window.top.location.pathname.indexOf('mydisk.php') > -1) { // 后台页
  144. if (window.top.location.href != 'https://pc.woozooo.com/mydisk.php') window.top.location.href = 'https://pc.woozooo.com/mydisk.php';
  145. RememberLoginStatus() // 通过延长 cookie 到期时间来一直记住登录状态
  146. var mainframe;
  147. iframe();
  148. } else if (window.top.location.pathname.indexOf('%') > -1) { // > 带密码的分享链接页面
  149. shareLinkWithPassword(); // 带密码的分享链接自动输密码
  150. } else {
  151. setTimeout(function() { // 延迟 300 毫秒(避免网页还没加载完)
  152. if (document.querySelector('#pwdload,#passwddiv')) { // > 分享链接输入密码页
  153. enterPassword(); // 自动输入密码(仅支持访问 带密码的分享链接 时)
  154. enterToPass(); // 输入密码后回车确认(针对手动输入密码)
  155. }
  156. if (document.getElementById('infos')) { // > 分享链接文件列表页
  157. fileMoreS(); // 自动显示更多文件
  158. directDownload(); // 点击直接下载文件(分享链接列表页)
  159. }
  160. }, 300);
  161. directDownload_(); // 点击直接下载文件(分享链接列表页)
  162. }
  163. // 获取 iframe 框架
  164. function iframe() {
  165. mainframe = document.getElementById('mainframe');
  166. if (mainframe) { // 只有找到 iframe 框架时才会继续运行脚本
  167. mainframe = mainframe.contentWindow;
  168. if (menu_value('menu_refreshCorrection')) refreshCorrection(); // 刷新不返回根目录(F5)
  169. setTimeout(folderDescdes, 500); // 优化编辑框初始大小
  170. setTimeout(hideSha, 500); // 隐藏分享链接窗口(这样自动打开/复制分享链接时,不会一闪而过)
  171. fobiddenBack(); // 禁止浏览器返回(并绑定新的返回事件)
  172. EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
  173. setTimeout(clickOpenDirectory, 500); // 点击空白进入目录
  174. setTimeout(backToTop, 2000); // 快捷返回上级(右键点击 网页右侧/下方 空白处)
  175. dragEnter(); // 拖入文件自动显示上传框
  176. setTimeout(viewTop,1000); // 监听并修改右键菜单 [外链分享地址] 为 [复制并打开分享链接] / [复制分享链接] / [打开分享链接] 之一
  177. setTimeout(copyAllfileSha, 500); // 一键复制所有分享链接
  178. setTimeout(filesSort, 300); // 文件排序
  179. }
  180. }
  181. // 带密码的分享链接自动输密码
  182. function shareLinkWithPassword() {
  183. if (location.pathname.indexOf('%E5%AF%86%E7%A0%81') > -1) {
  184. let shareLink = location.pathname.split('%')
  185. if (shareLink.length > 0) {
  186. shareLink = location.origin + shareLink[0]
  187. let password = location.pathname.replace('%E5%AF%86%E7%A0%81',':').replace(/%([A-Z]|[0-9]){2}/ig, '').split(':')
  188. if (password.length > 0) {
  189. location.replace(shareLink + '?pwd=' + password[password.length - 1])
  190. }
  191. }
  192. }
  193. }
  194. // 自动输入密码(仅支持访问 带密码的分享链接 时,比如上面 [带密码的分享链接自动输密码] 功能重定向后的链接)
  195. function enterPassword() {
  196. if (location.search.indexOf('?pwd=') > -1 || location.search.indexOf('?passwd=') > -1 || location.search.indexOf('?password=') > -1) {
  197. let password = location.search.split('=')
  198. if (password.length > 0) {
  199. document.getElementById('pwd').value = password[password.length - 1]
  200. if (document.getElementById('sub')) {
  201. document.getElementById('sub').click();
  202. } else {
  203. document.querySelector('.passwddiv-btn[onclick]').click();
  204. }
  205. }
  206. }
  207. }
  208. // 刷新不返回根目录(F5)
  209. function refreshCorrection() {
  210. document.onkeydown = mainframe.onkeydown = function (e) {
  211. e = window.event || e;
  212. if (e.key === 'F5') {
  213. let folderID = /-?\d+/.exec(mainframe.document.getElementById('filemore').children[0].onclick)
  214. if(folderID.length > 0){
  215. mainframe.folder(folderID[0]);
  216. e.returnValue = false;
  217. e.cancelBubble = true;
  218. return false;
  219. }
  220. }
  221. }
  222. }
  223. // 恢复刷新机制
  224. function UNrefreshCorrection() {
  225. document.onkeydown = mainframe.onkeydown = function (e) {
  226. e = window.event || e;
  227. if (e.key === 'F5') {
  228. return true;
  229. }
  230. }
  231. }
  232. // 点击空白进入目录
  233. function clickOpenDirectory() {
  234. mainframe.document.getElementById('sub_folder_list').onclick = function(e){
  235. //console.log(e.target);
  236. if (e.target.className && e.target.className == 'f_tb') {
  237. e.target.querySelector('span.follink').click()
  238. }
  239. }
  240. }
  241. // 右键文件显示菜单
  242. function rightClickMenu() {
  243. if (!menu_value('menu_rightClickMenu')) return
  244. rightClickMenu_('sub_folder_list', 'fols', 'folse') // 文件夹
  245. rightClickMenu_('filelist', 'fs', 'fse') // 文件
  246. }
  247. // 右键文件显示菜单,参数:文件/文件夹列表 ID、菜单 ID、菜单 ID前缀
  248. function rightClickMenu_(list_id_name, menu_id_name_prefix, list_id_name_prefix) {
  249. let list_ = mainframe.document.getElementById(list_id_name);
  250. if (!list_) return // 文件/文件夹列表
  251. list_.oncontextmenu = function(e){
  252. e.preventDefault(); // 屏蔽浏览器自身右键菜单
  253. let left = e.pageX - 30; // 右键菜单弹出位置
  254. let list_ID = e.target.id;
  255. if (e.target.nodeName === 'FONT') {
  256. list_ID = e.target.parentNode.parentNode.id
  257. } else if(e.target.id === '') {
  258. list_ID = e.target.parentNode.id
  259. }
  260. list_ID = /\d+/.exec(list_ID)
  261. if(list_ID.length > 0){
  262. mainframe.document.getElementById(menu_id_name_prefix + list_ID[0]).style.cssText='position: absolute !important; left: ' + left + 'px;' // 修改右键菜单弹出位置(X)
  263. mainframe.document.getElementById(list_id_name_prefix + list_ID[0]).focus();
  264. mainframe.document.getElementById(list_id_name_prefix + list_ID[0]).click();
  265. }
  266. }
  267. }
  268. // 自动显示更多文件(后台页)
  269. function fileMore() {
  270. let filemore = mainframe.document.getElementById('filemore'); // 寻找 [显示更多文件] 按钮
  271. if (filemore && filemore.style.display === 'block') { // 判断按钮是否存在且可见
  272. if (filemore.children[0]) { // 判断按钮元素下第一个元素是否存在
  273. filemore.children[0].click(); // 点击 [显示更多文件] 按钮
  274. }
  275. }
  276. }
  277. // 自动显示更多文件(分享链接列表页)
  278. function fileMoreS() {
  279. windowScroll(function (direction, e) {
  280. if (direction === 'down') { // 下滑才准备加载更多
  281. let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  282. let scrollDelta = 500;
  283. if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
  284. let filemore = document.getElementById('filemore'); // 寻找 [显示更多文件] 按钮
  285. if (filemore && filemore.style.display != 'none') { // 如果正在加载,就不再点击
  286. if (filemore.textContent.indexOf('更多') > -1){ // 避免已经在加载了,重复点击
  287. filemore.click(); // 点击 [显示更多文件] 按钮
  288. }
  289. }
  290. }
  291. }
  292. });
  293. }
  294. // 点击直接下载文件(分享链接列表页)
  295. function directDownload() {
  296. if (!menu_value('menu_directDownload')) return
  297. if (document.getElementById('infos')) {
  298. document.getElementById('infos').addEventListener('click', function(e) {
  299. if (e.target.tagName === 'A') { // 针对普通样式的分享链接列表页
  300. e.preventDefault(); // 阻止默认打开链接事件
  301. GM_openInTab(e.target.href + '#download', {active: false, insert: true, setParent: true}); // 后台打开
  302. } else { // 针对会员专属样式的分享链接列表页
  303. const link = e.target.closest('a'); // 点击 <a> 元素的子元素时,寻找最近的 <a> 父元素
  304. if ((link && this.contains(link))) {
  305. e.preventDefault(); // 阻止默认打开链接事件
  306. GM_openInTab(link.href + '#download', {active: false, insert: true, setParent: true}); // 后台打开
  307. }
  308. }
  309. });
  310. }
  311. }
  312. // 点击下载按钮
  313. function directDownload_() {
  314. if (!menu_value('menu_directDownload')) return
  315. if (location.hash != '#download') return
  316. let iframe = document.querySelector('iframe.ifr2, iframe.n_downlink');
  317. if (iframe) { // 只有找到 iframe 框架时才会继续运行脚本
  318. iframe = iframe.contentWindow;
  319. let timer = setInterval(function(){
  320. if (iframe.document.querySelector('.load>[href]')) {
  321. //iframe.document.querySelector('.load>a[href]').target = '_top'
  322. //iframe.document.querySelector('.load>a[href]').click();
  323. GM_openInTab(iframe.document.querySelector('.load>a[href]').href, {active: false, insert: true, setParent: false}); // 后台打开
  324. clearInterval(timer);
  325. // 关闭该后台标签页
  326. if (GM_info.scriptHandler === 'Violentmonkey') { // Violentmonkey 需要延迟一会儿
  327. setTimeout(function(){window.top.close();}, 500)
  328. } else {
  329. window.top.close();
  330. }
  331. }
  332. }, 10);
  333. }
  334. }
  335. // 滚动条事件
  336. function windowScroll(fn1) {
  337. var beforeScrollTop = document.documentElement.scrollTop,
  338. fn = fn1 || function () {};
  339. setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
  340. window.addEventListener('scroll', function (e) {
  341. var afterScrollTop = document.documentElement.scrollTop,
  342. delta = afterScrollTop - beforeScrollTop;
  343. if (delta == 0) return false;
  344. fn(delta > 0 ? 'down' : 'up', e);
  345. beforeScrollTop = afterScrollTop;
  346. }, false);
  347. }, 1000)
  348. }
  349. // 优化编辑框初始大小
  350. function folderDescdes() {
  351. if (!menu_value('menu_folderDescdesMenu')) return
  352. mainframe.document.lastChild.appendChild(mainframe.document.createElement('style')).textContent = `#folder_descdes, #fol_credes, #file_desc {margin: 15px 0px; width: 550px; height: 125px;} input#f_ename_new {min-width: 700px; font-size: 14px;} #f_ename {z-index: 999;left: 15px;}`
  353. }
  354. // 拖入文件自动显示上传框
  355. function dragEnter() {
  356. mainframe.addEventListener('dragenter', function (e) {
  357. e.preventDefault();
  358. e.stopPropagation();
  359. let f_upb = mainframe.document.querySelector('.f_upb')
  360. if(f_upb.style.top != '-36px') {
  361. f_upb.style.top = '-36px';
  362. mainframe.f_upc();
  363. }
  364. }, false);
  365. mainframe.addEventListener('drop', function (e) {
  366. e.preventDefault();
  367. //e.stopPropagation();
  368. //console.log(e.dataTransfer.files)
  369. });
  370. }
  371. // 一键复制所有分享链接
  372. function copyAllfileSha() {
  373. var f_data = '', tmep_data = [];
  374. let f_tp = mainframe.document.getElementById('f_tp');
  375. //console.log(f_tp, mainframe.document.location.href)
  376. f_tp.insertAdjacentHTML('afterend', `<a id="f_copyAll" class="f_sela" style="float: right; width: auto; font-size: 12px !important; font: inherit; padding: 2px 10px; margin-top: -25px;" title="获取所有分享链接需要一些时间(取决于有多少文件)。&#10;因为分享链接没有显示在网页上,需要通过网页接口获取,因此为了避免太频繁被限制,所以设置了 300ms 间隔时间!">一键复制所有分享链接</a>`);
  377. mainframe.document.getElementById('f_copyAll').onclick = function() {
  378. f_data = ''; tmep_data = [];
  379. mainframe.document.querySelectorAll('.f_tb').forEach(function (_this) {
  380. //console.log(_this, _this.id.indexOf('fol') > -1)
  381. if (_this.id.indexOf('fol') > -1) {
  382. //console.log(`task=18&folder_id=${_this.id.replace('fol','')}`)
  383. tmep_data.push([`${_this.querySelector('span[id^="folname"]').textContent}`, `task=18&folder_id=${_this.id.replace('fol','')}`])
  384. } else {
  385. //console.log(`task=22&file_id=${_this.id.replace('f','')}`)
  386. tmep_data.push([`${_this.querySelector('span[id^="filename"]').textContent}`, `task=22&file_id=${_this.id.replace('f','')}`])
  387. }
  388. })
  389. //console.log(tmep_data)
  390. if (tmep_data.length > 0) {
  391. getUrl(0);
  392. GM_notification({text: '获取所有分享链接需要一些时间(取决于有多少文件),在此期间请不要关闭网页!', timeout: 5000});
  393. }
  394. };
  395. function getUrl(i) {
  396. //console.log(i)
  397. GM_xmlhttpRequest({
  398. url: 'https://pc.woozooo.com/doupload.php',
  399. method: 'POST',
  400. data: tmep_data[i][1],
  401. responseType: 'json',
  402. overrideMimeType: 'application/json; charset=utf-8',
  403. headers: {
  404. 'Referer': mainframe.document.location.href,
  405. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  406. },
  407. timeout: 5000,
  408. onload: function (response) {
  409. try {
  410. //console.log('返回内容:',response.response)
  411. if (response.response && response.response.zt === 1) {
  412. //console.log(response.response)
  413. if (response.response.info.f_id) {
  414. //console.log('文件 1',f_data)
  415. f_data += `${tmep_data[i][0]} `
  416. if (menu_value('menu_customFileSha')) {
  417. f_data += `https://${menu_value('menu_customFileSha')}/${response.response.info.f_id} `
  418. } else {
  419. f_data += `${response.response.info.is_newd}/${response.response.info.f_id} `
  420. }
  421. if (response.response.info.onof == '1') f_data += `密码:${response.response.info.pwd}`
  422. f_data += `\n`
  423. //console.log('文件 2',f_data)
  424. } else {
  425. //console.log('目录 1',f_data)
  426. f_data += `${response.response.info.name} `
  427. if (menu_value('menu_customFileSha')) {
  428. f_data += `${response.response.info.new_url.replace(/\/\/.+\//i, '//' + menu_value('menu_customFileSha') + '/')} `
  429. } else {
  430. f_data += `${response.response.info.new_url} `
  431. }
  432. if (response.response.info.onof == '1') f_data += `密码:${response.response.info.pwd}`
  433. f_data += `\n`
  434. //console.log('目录 2',f_data)
  435. }
  436. if (++i < tmep_data.length) {
  437. setTimeout(function(){getUrl(i);}, 300);
  438. } else {
  439. console.log(f_data)
  440. GM_setClipboard(f_data, 'text');
  441. GM_notification({text: '✅ 已复制所有文件/目录的分享链接到剪切板~', timeout: 2000});
  442. }
  443. } else {
  444. GM_notification({text: '❌ 更新失败,请联系作者解决...', timeout: 5000});
  445. }
  446. } catch (e) {
  447. console.log(e);
  448. }
  449. }
  450. })
  451. }
  452. }
  453. // 分享链接相关(点击文件时)
  454. function fileSha() {
  455. var f_sha = mainframe.document.getElementById('f_sha'); // 寻找分享链接(下载链接)信息框
  456. if (f_sha && f_sha.style.display === 'block') { // 判断信息框是否存在且可见
  457. let f_sha1 = mainframe.document.getElementById('f_sha1'); // 获取分享链接(下载链接)
  458. if (f_sha1 && f_sha1.textContent != '') { // 确保分享链接(下载链接)不是空
  459. // 自定义分享链接域名
  460. if (menu_value('menu_customFileSha')) {f_sha1.innerText = f_sha1.innerText.replace(/\/\/.+\//i, '//' + menu_value('menu_customFileSha') + '/');}
  461. // 打开分享链接
  462. if (menu_value('menu_open_fileSha')) {f_sha.style.display = 'none';GM_openInTab(f_sha1.textContent, {active: true,insert: true,setParent: true});}
  463. // 复制分享链接(并已复制的提示信息)
  464. if (menu_value('menu_copy_fileSha')) {f_sha.style.display = 'none';GM_setClipboard(f_sha1.textContent, 'text');GM_notification({text: '已复制分享链接~', timeout: 2000});}
  465. // 直接下载文件
  466. //if (menu_value('menu_directDownload')) {f_sha.style.display = 'none';GM_openInTab(f_sha1.textContent + '#download', {active: false,insert: true,setParent: true});}
  467. }
  468. }
  469. }
  470. // 自定义分享链接域名
  471. function customFileSha() {
  472. let newDomain = prompt('请输入 [自定义分享链接域名],点击确定后立即生效\n蓝奏云分享链接末尾的 ID 是唯一的,而前面的域名用谁的都一样\n示例:pan.lanzoui.com 或 wwe.lanzoui.com 或 xiu.lanzoui.com', GM_getValue('menu_customFileSha'));
  473. if (newDomain === '') {
  474. GM_setValue('menu_customFileSha', '');
  475. registerMenuCommand(); // 重新注册脚本菜单
  476. } else if (newDomain != null) {
  477. GM_setValue('menu_customFileSha', newDomain);
  478. registerMenuCommand(); // 重新注册脚本菜单
  479. }
  480. }
  481. // 隐藏分享链接窗口(这样自动打开/复制分享链接时,不会一闪而过)
  482. function hideSha(){
  483. if (menu_value('menu_open_fileSha') || menu_value('menu_copy_fileSha')) { // [自动复制分享链接] 或 [自动打开分享链接] 任意一个功能开启时才继续
  484. mainframe.document.lastElementChild.appendChild(document.createElement('style')).textContent = '#f_sha {display: none !important;}';
  485. }
  486. }
  487. // 禁止浏览器返回(并绑定新的返回事件)
  488. function fobiddenBack() {
  489. history.pushState(null, null, document.URL);
  490. window.addEventListener('popstate',backEvent)
  491. }
  492. // 允许浏览器返回
  493. function enableBack() {
  494. history.go(-1);
  495. window.removeEventListener('popstate',backEvent)
  496. }
  497. // 浏览器后退事件函数
  498. function backEvent() {
  499. if (lastFolderID) {
  500. mainframe.folder(lastFolderID);
  501. }
  502. history.pushState(null, null, document.URL);
  503. }
  504. // 获取上个文件夹 ID(用于浏览器后退事件)
  505. function getLastFolderID() {
  506. lastFolderID = null
  507. let f_tpspan = mainframe.document.querySelectorAll('span.f_tpspan');
  508. if (f_tpspan.length > 1) {
  509. lastFolderID = /-?\d+/.exec(f_tpspan[f_tpspan.length - 2].getAttribute('onclick'))[0];
  510. }
  511. }
  512. // 输入密码后回车确认
  513. function enterToPass() {
  514. document.getElementById('pwd').onkeydown = function(e){
  515. if (e.key === 'Enter') {
  516. document.getElementById('sub').click();
  517. }
  518. };
  519. }
  520. // 快捷返回上级(右键点击 网页右侧/下方 空白处)
  521. function backToTop() {
  522. mainframe.document.getElementById('container').oncontextmenu = mainframe.document.body.oncontextmenu = function(e){
  523. if (e.target == this) {
  524. e.preventDefault();
  525. backEvent();
  526. }
  527. }
  528. }
  529. // 监听 XMLHttpRequest 事件并执行
  530. function EventXMLHttpRequest() {
  531. var _send = mainframe.XMLHttpRequest.prototype.send
  532. function sendReplacement(data) {
  533. setTimeout(fileMore, 200); // 自动显示更多文件
  534. setTimeout(fileSha, 200); // 自动打开分享链接(点击文件时)
  535. setTimeout(rightClickMenu, 500); // 右键文件显示菜单
  536. setTimeout(getLastFolderID, 200); // 获取上个文件夹 ID(用于浏览器后退事件)
  537. return _send.apply(this, arguments);
  538. }
  539. mainframe.XMLHttpRequest.prototype.send = sendReplacement;
  540. }
  541. // 监听并修改右键菜单 [外链分享地址] 为 [复制并打开分享链接] / [复制分享链接] / [打开分享链接] 之一
  542. function viewTop() {
  543. const callback = (mutationsList, observer) => {
  544. for (const mutation of mutationsList) {
  545. for (const target of mutation.addedNodes) {
  546. if (target.nodeType != 1) return
  547. if (target.className === 'f_view') {
  548. //console.log(target)
  549. let f_viewtop = target.querySelector('.f_viewtop');
  550. if (f_viewtop && f_viewtop.textContent === '外链分享地址') {
  551. if (menu_value('menu_open_fileSha') && menu_value('menu_copy_fileSha')) {
  552. f_viewtop.textContent = '复制并打开分享链接';
  553. } else if (menu_value('menu_open_fileSha')) {
  554. f_viewtop.textContent = '打开分享链接';
  555. } else if (menu_value('menu_copy_fileSha')) {
  556. f_viewtop.textContent = '复制分享链接';
  557. }
  558. }
  559. }
  560. }
  561. }
  562. };
  563. const observer = new MutationObserver(callback);
  564. observer.observe(mainframe.document, { childList: true, subtree: true });
  565. }
  566. // 通过延长 cookie 到期时间来一直记住登录状态
  567. function RememberLoginStatus() {
  568. // 获取 Cookie
  569. function getCookie(name) {
  570. if (!name) return ''
  571. let arr = document.cookie.split(';');
  572. name += '=';
  573. for (let i=0; i<arr.length; i++) {let now = arr[i].trim();if (now.indexOf(name) == 0) return now.substring(name.length, now.length);}
  574. return '';
  575. }
  576. const ylogin = getCookie('ylogin'), phpdisk_info = getCookie('phpdisk_info')
  577. if (ylogin !== '' && phpdisk_info !== '') { // 如果已登录(有相应 cookie),那么就延长至浏览器支持的到期时间上限(不同浏览器对到期时间的限制不一样,一般是 1-5 年)
  578. document.cookie='ylogin=' + ylogin + '; domain=.woozooo.com; expires=Thu, 18 Dec 2099 12:00:00 GMT; path=/'
  579. document.cookie='phpdisk_info=' + phpdisk_info + '; domain=pc.woozooo.com; expires=Thu, 18 Dec 2099 12:00:00 GMT; path=/'
  580. }
  581. }
  582. // 文件排序
  583. function filesSort() {
  584. const frame = mainframe;
  585. const frameDoc = frame.document;
  586. const currentStatus = {
  587. by: 'name',
  588. order: 'asc',
  589. }
  590. let allButtons = undefined;
  591. // 文件名排序
  592. function sortByName(name1, name2) {
  593. function sort(a, b) {
  594. const strA = a.toLocaleLowerCase().split('');
  595. const strB = b.toLocaleLowerCase().split('');
  596. for (let i = 0; i < strA.length; i++) {
  597. if (strA[i] === strB[i]) {
  598. continue;
  599. }
  600. if (strB[i] === undefined) return 1;
  601. if (notChinese(strA[i]) && notChinese(strB[i])) {
  602. return strA[i] < strB[i] ? -1 : 1;
  603. } else if (notChinese(strA[i])) {
  604. return -1;
  605. } else if (notChinese(strB[i])) {
  606. return 1;
  607. } else {
  608. return strA[i].localeCompare(strB[i]);
  609. }
  610. }
  611. if (strA.length === strB.length) {
  612. return 0;
  613. } else if (strA.length < strB.length) {
  614. return -1;
  615. }
  616. return 1;
  617. }
  618. function notChinese(char) {
  619. const charCode = char.charCodeAt(0)
  620. return charCode >= 0 && charCode <= 128
  621. }
  622. return sort(name1, name2);
  623. }
  624. // 创建排序按鈕
  625. function createAllButtons() {
  626. const tabTitle = frameDoc.querySelector('#container > div.n1 > div.f_th');
  627. const name = tabTitle.querySelector('div.f_name');
  628. const size = tabTitle.querySelector('div.f_size');
  629. const time = tabTitle.querySelector('div.f_time');
  630. const down = tabTitle.querySelector('div.f_down'); // 下载量
  631. return {
  632. name: {
  633. el: createButton(name, 'name', '按 文件名称 排序'),
  634. order: 'asc',
  635. },
  636. size: {
  637. el: createButton(size, 'size', '按 文件大小 排序'),
  638. order: 'asc',
  639. },
  640. time: {
  641. el: createButton(time, 'time', '按 上传时间 排序'),
  642. order: 'asc',
  643. },
  644. down: {
  645. el: createButton(down, 'down', '按 下载次数 排序'),
  646. order: 'asc',
  647. }
  648. };
  649. }
  650. function createButton(element, by, title) {
  651. // element.insertAdjacentHTML('beforeend', '<a class="col_sort_btn" href="javascript: void;" style="font-size: 16px; float: right;">⇧</a>');
  652. let button = frameDoc.createElement('a');
  653. button.className = 'col_sort_btn';
  654. button.href = 'javascript: void(0);';
  655. button.style.fontSize = '16px';
  656. button.style.float = 'right';
  657. if (by == 'name') {button.style.float = 'left';}
  658. button.title = title;
  659. button.textContent = '⇧';
  660. button.onclick = () => clickSortButton(by, button);
  661. element.appendChild(button);
  662. return button;
  663. }
  664. function getFiles() {
  665. const list = frameDoc.querySelector('#filelist');
  666. const files = list.childNodes;
  667. const filesInfo = [];
  668. const now = new Date();
  669. for (const file of files) {
  670. const name = file.querySelector('.f_name > span.aspanlink > .f_name_title').textContent;
  671. const size = parseByteSize(file.querySelector('.f_size').textContent);
  672. const time = file.querySelector('.f_time').textContent;
  673. const down = parseInt(file.querySelector('.f_down').textContent);
  674. filesInfo.push({
  675. info: {
  676. name: name,
  677. size: size,
  678. time: parseTime(now, time),
  679. down: down
  680. },
  681. node: file
  682. })
  683. }
  684. return filesInfo;
  685. }
  686. function getFolders() {
  687. const list = frameDoc.querySelector('#sub_folder_list');
  688. const folders = list.childNodes;
  689. const foldersInfo = [];
  690. for (const folder of folders) {
  691. const name = folder.querySelector('.f_tb > .f_name2 > span.follink > span').textContent;
  692. foldersInfo.push({
  693. info: {
  694. name: name,
  695. },
  696. node: folder
  697. })
  698. }
  699. return foldersInfo;
  700. }
  701. // 转换文件大小
  702. function parseByteSize(text) {
  703. const unit = ['B', 'K', 'M', 'G', 'T'];
  704. let size = 0;
  705. for (let i = 0; i < unit.length; i++) {
  706. if (text.indexOf(unit[i]) > -1) {
  707. size = parseFloat(text.replace(unit[i], '')) * Math.pow(####, i);
  708. break;
  709. }
  710. }
  711. return size;
  712. }
  713. // 转换时间格式
  714. function parseTime(now, text) {
  715. function parseDay(time) {
  716. const days = [
  717. {
  718. name: '前天',
  719. offset: -2,
  720. },
  721. {
  722. name: '昨天',
  723. offset: -1,
  724. }
  725. ];
  726. const date = new Date(now.getTime());
  727. let index = -1;
  728. for (let i = 0; i < days.length; i++) {
  729. if (time.indexOf(days[i].name) > -1) {
  730. index = i;
  731. break;
  732. }
  733. }
  734. if (index === -1) return new Date(now.getTime());
  735. const hourAndMinute = text.replace(days[index].name, '').split(':');
  736. const hour = parseInt(hourAndMinute[0]);
  737. const minute = parseInt(hourAndMinute[1]);
  738. date.setDate(date.getDate() + days[index].offset);
  739. date.setHours(hour);
  740. date.setMinutes(minute);
  741. // 蓝奏云显示比较奇怪,超过24小时,未满48小时,都是昨天,并不以每天0点作为分界
  742. if (hour * 60 + minute > now.getHours() * 60 + now.getMinutes()) {
  743. date.setDate(date.getDate() - 1);
  744. }
  745. return date;
  746. }
  747. if (text.indexOf('秒前') > -1) {
  748. return now.getTime() - parseInt(text.replace('秒前', '')) * 1000;
  749. } else if (text.indexOf('分钟前') > -1) {
  750. return now.getTime() - parseInt(text.replace('分钟前', '')) * 60 * 1000;
  751. } else if (text.indexOf('小时前') > -1) {
  752. return now.getTime() - parseInt(text.replace('小时前', '')) * 60 * 60 * 1000;
  753. } else if (text.indexOf('昨天') > -1 || text.indexOf('前天') > -1) {
  754. return parseDay(text).getTime();
  755. } else if (text.indexOf('天前') > -1) {
  756. return now.getTime() - parseInt(text.replace('天前', '')) * 24 * 60 * 60 * 1000;
  757. } else if (text.indexOf('月前') > -1) { // 我不知道有没有以下几种情况,暂时先写上
  758. return now.getTime() - parseInt(text.replace('月前', '')) * 30 * 24 * 60 * 60 * 1000;
  759. } else if (text.indexOf('年前') > -1) {
  760. return now.getTime() - parseInt(text.replace('年前', '')) * 365 * 24 * 60 * 60 * 1000;
  761. }
  762. return Date.parse(text);
  763. }
  764. // 排序
  765. function sortItems(files, by, order) {
  766. let compareFunc;
  767. if (by === 'name') {
  768. compareFunc = (a, b) => {
  769. return (order === 'asc' ? 1 : -1) * sortByName(a.info.name, b.info.name);
  770. }
  771. } else {
  772. compareFunc = (a, b) => {
  773. const r###lt = a.info[by] > b.info[by] ? 1 : -1;
  774. return (order === 'asc' ? 1 : -1) * r###lt;
  775. }
  776. }
  777. files.sort(compareFunc);
  778. }
  779. function sortFileList() {
  780. const files = getFiles();
  781. if (files.length > 0) {
  782. sortItems(files, currentStatus.by, currentStatus.order);
  783. // console.log(files)
  784. const fileList = frameDoc.querySelector('#filelist');
  785. for (let i = 0; i < files.length; i++) {
  786. fileList.appendChild(files[i].node);
  787. }
  788. }
  789. }
  790. function sortFolderList() {
  791. const folders = getFolders();
  792. // console.log(folders);
  793. if (folders.length > 0) {
  794. // 文件夹只能按名称排序
  795. if (currentStatus.by === 'name') {
  796. sortItems(folders, 'name', currentStatus.order);
  797. } else {
  798. sortItems(folders, 'name', 'asc'); // 其他情况,皆按名称升序
  799. }
  800. const folderList = frameDoc.querySelector('#sub_folder_list');
  801. for (let i = 0; i < folders.length; i++) {
  802. folderList.appendChild(folders[i].node);
  803. }
  804. }
  805. }
  806. function fileListCallback(records) {
  807. if (!menu_value('menu_fileSort')) return;
  808. for (const event of records) {
  809. // 自己修改的时候不排序
  810. if (event.removedNodes.length > 0) return;
  811. }
  812. sortFileList();
  813. }
  814. function folderListCallback(records) {
  815. if (!menu_value('menu_fileSort')) return;
  816. for (const event of records) {
  817. // 自己修改的时候不排序
  818. if (event.removedNodes.length > 0) return;
  819. }
  820. sortFolderList();
  821. }
  822. function clickSortButton(by, button) {
  823. if (currentStatus.by === by) {
  824. // 当前选项,点击时,反转排序
  825. currentStatus.order = button.textContent === '⬆' ? 'desc' : 'asc';
  826. } else {
  827. // 非当前选项,点击时,以图标所示的顺序排序
  828. currentStatus.order = button.textContent === '⇧' ? 'asc' : 'desc';
  829. // 修改非当前选项按钮的图标
  830. for (const key in allButtons) {
  831. if (key === by) continue;
  832. if (Object.hasOwnProperty.call(allButtons, key)) {
  833. const btnItem = allButtons[key];
  834. if (btnItem.el.textContent === '⬆') {
  835. btnItem.el.textContent = '⇧';
  836. } else if (btnItem.el.textContent === '⬇') {
  837. btnItem.el.textContent = '⇩';
  838. }
  839. }
  840. }
  841. }
  842. button.textContent = currentStatus.order === 'asc' ? '⬆' : '⬇';
  843. currentStatus.by = by;
  844. sortFileList();
  845. sortFolderList();
  846. }
  847. // create buttons
  848. setTimeout(() => {
  849. if (allButtons === undefined && menu_value('menu_fileSort')) {
  850. allButtons = createAllButtons();
  851. // console.log(allButtons);
  852. allButtons[currentStatus.by].el.textContent = currentStatus.order === 'asc' ? '⬆' : '⬇';
  853. }
  854. }, 500);
  855. // sort files
  856. const fileList = frameDoc.querySelector('#filelist');
  857. const fileObserver = new MutationObserver(fileListCallback);
  858. fileObserver.observe(fileList, { childList: true, attributes: false });
  859. // sort folders
  860. const folderList = frameDoc.querySelector('#sub_folder_list');;
  861. const folderObserver = new MutationObserver(folderListCallback);
  862. folderObserver.observe(folderList, { childList: true, attributes: false });
  863. }
  864. })();