蓝奏云网盘增强

自动显示更多文件(文件夹末尾按钮)、自动打开分享链接(点击文件时)

目前為 2020-12-31 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 蓝奏云网盘增强
  3. // @version 1.0.4
  4. // @author X.I.U
  5. // @description 自动显示更多文件(文件夹末尾按钮)、自动打开分享链接(点击文件时)
  6. // @match *://www.lanzou.com/account.php
  7. // @match *://www.lanzou.com/u
  8. // @match *://up.woozooo.com/u
  9. // @match *://up.woozooo.com/mydisk.php*
  10. // @match *://pc.woozooo.com/u
  11. // @match *://pc.woozooo.com/mydisk.php*
  12. // @icon https://www.lanzou.com/favicon.ico
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM_registerMenuCommand
  15. // @grant GM_unregisterMenuCommand
  16. // @grant GM_openInTab
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_notification
  20. // @noframes
  21. // @license GPL-3.0 License
  22. // @run-at document-end
  23. // @namespace https://github.com/XIU2/UserScript
  24. // ==/UserScript==
  25.  
  26. (function() {
  27. if(window.top.location.href != "https://pc.woozooo.com/mydisk.php"){
  28. window.top.location.href = "https://pc.woozooo.com/mydisk.php"
  29. }
  30.  
  31. var menu_open_fileSha = GM_getValue('xiu2_menu_open_fileSha');
  32. var menu_open_fileSha_ID, menu_feedBack_ID;
  33. if (menu_open_fileSha == null){menu_open_fileSha = true; GM_setValue('xiu2_menu_open_fileSha', menu_open_fileSha)};
  34. registerMenuCommand();
  35.  
  36. // 注册脚本菜单
  37. function registerMenuCommand() {
  38. var menu_open_fileSha_;
  39. if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
  40. GM_unregisterMenuCommand(menu_open_fileSha_ID);
  41. GM_unregisterMenuCommand(menu_feedBack_ID);
  42. menu_open_fileSha = GM_getValue('xiu2_menu_open_fileSha');
  43. }
  44.  
  45. if (menu_open_fileSha){menu_open_fileSha_ = "√";}else{menu_open_fileSha_ = "×";}
  46.  
  47. menu_open_fileSha_ID = GM_registerMenuCommand(`[ ${menu_open_fileSha_} ] 自动打开分享链接(点击文件时)`, function(){menu_switch(menu_open_fileSha,'xiu2_menu_open_fileSha','自动打开分享链接(点击文件时)')});
  48. menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
  49. }
  50.  
  51.  
  52. // 菜单开关
  53. function menu_switch(menu_status, Name, Tips) {
  54. if (menu_status){
  55. GM_setValue(`${Name}`, false);
  56. GM_notification(`已关闭 [${Tips}] 功能\n(刷新网页后生效)`);
  57. }else{
  58. GM_setValue(`${Name}`, true);
  59. GM_notification(`已开启 [${Tips}] 功能\n(刷新网页后生效)`);
  60. }
  61. registerMenuCommand(); // 重新注册脚本菜单
  62. };
  63.  
  64.  
  65. // 获取 iframe 框架
  66. var mainframe
  67. mainframe = document.getElementById("mainframe");
  68. if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
  69. mainframe = mainframe.contentWindow;
  70. EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
  71. }
  72.  
  73.  
  74. // 自动显示更多文件
  75. function fileMore() {
  76. let filemore = mainframe.document.getElementById("filemore"); // 寻找 [显示更多文件] 按钮
  77. if(filemore && filemore.style.display == "block"){ // 判断按钮是否存在且可见
  78. if(filemore.children[0]){ // 判断按钮元素下第一个元素是否存在
  79. filemore.children[0].click(); // 点击 [显示更多文件] 按钮
  80. }
  81. }
  82. }
  83.  
  84.  
  85. // 自动打开分享链接(点击文件时)
  86. function fileSha() {
  87. if(menu_open_fileSha){ // 脚本菜单开启时才继续
  88. var f_sha = mainframe.document.getElementById("f_sha"); // 寻找分享链接(下载链接)信息框
  89. if(f_sha && f_sha.style.display == "block"){ // 判断信息框是否存在且可见
  90. let code = mainframe.document.getElementById("code").getAttribute("title"); // 获取分享链接(下载链接)
  91. if(code != ""){ // 确保分享链接(下载链接)不是空
  92. f_sha.style.display = "none"; // 隐藏分享链接(下载链接)信息框
  93. window.GM_openInTab(code, {active: true,insert: true,setParent: true}) // 打开分享链接(下载链接)
  94. }
  95. }
  96. }
  97. }
  98.  
  99.  
  100. // 定时执行(旧方法,每隔 100ms 执行一次,比较笨且浪费一丢丢性能,但优点是不会漏掉且反应更快)
  101. //setInterval(fileMore,100);
  102.  
  103.  
  104. // 监听 XMLHttpRequest 事件并执行(新方法,只有在产生事件时才会执行 [自动显示更多文件],平时不会执行,更优雅~)
  105. function EventXMLHttpRequest() {
  106. var _send = mainframe.XMLHttpRequest.prototype.send
  107. function sendReplacement(data) {
  108. setTimeout(fileMore, 200); // 自动显示更多文件
  109. setTimeout(fileSha, 200); // 自动打开分享链接(点击文件时)
  110. return _send.apply(this, arguments);
  111. }
  112. mainframe.XMLHttpRequest.prototype.send = sendReplacement;
  113. }
  114.  
  115.  
  116. /*(function (open) {
  117. mainframe.XMLHttpRequest.prototype.open = function () {
  118. this.addEventListener("readystatechange", function () {
  119. if(this.responseURL != "") {
  120. console.log(this.responseURL);
  121. }
  122. }, false);
  123. open.apply(this, arguments);
  124. };
  125. })(mainframe.XMLHttpRequest.prototype.open);*/
  126. })();