蓝奏云网盘增强

刷新不返回根目录、自动显示更多文件、自动打开分享链接、自动复制分享链接

目前為 2021-01-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 蓝奏云网盘增强
  3. // @version 1.0.7
  4. // @author X.I.U
  5. // @description 刷新不返回根目录、自动显示更多文件、自动打开分享链接、自动复制分享链接
  6. // @match *://*.lanzous.com/*
  7. // @match *://*.lanzoux.com/*
  8. // @match *://*.lanzoui.com/*
  9. // @match *://www.lanzou.com/account.php
  10. // @match *://www.lanzou.com/u
  11. // @match *://up.woozooo.com/u
  12. // @match *://up.woozooo.com/mydisk.php*
  13. // @match *://pc.woozooo.com/u
  14. // @match *://pc.woozooo.com/mydisk.php*
  15. // @icon https://www.lanzou.com/favicon.ico
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_registerMenuCommand
  18. // @grant GM_unregisterMenuCommand
  19. // @grant GM_openInTab
  20. // @grant GM_getValue
  21. // @grant GM_setValue
  22. // @grant GM_notification
  23. // @noframes
  24. // @license GPL-3.0 License
  25. // @run-at document-end
  26. // @namespace https://github.com/XIU2/UserScript
  27. // ==/UserScript==
  28. (function() {
  29. var menu_open_fileSha = GM_getValue('xiu2_menu_open_fileSha');
  30. var menu_copy_fileSha = GM_getValue('xiu2_menu_copy_fileSha');
  31. var menu_refreshCorrection = GM_getValue('xiu2_menu_refreshCorrection');
  32. var menu_open_fileSha_ID, menu_copy_fileSha_ID, menu_refreshCorrection_ID, menu_feedBack_ID;
  33. if (menu_open_fileSha == null){menu_open_fileSha = true; GM_setValue('xiu2_menu_open_fileSha', menu_open_fileSha)};
  34. if (menu_copy_fileSha == null){menu_copy_fileSha = true; GM_setValue('xiu2_menu_copy_fileSha', menu_copy_fileSha)};
  35. if (menu_refreshCorrection == null){menu_refreshCorrection = true; GM_setValue('xiu2_menu_refreshCorrection', menu_refreshCorrection)};
  36. registerMenuCommand();
  37.  
  38. // 注册脚本菜单
  39. function registerMenuCommand() {
  40. var menu_open_fileSha_, menu_copy_fileSha_, menu_refreshCorrection_;
  41. if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
  42. GM_unregisterMenuCommand(menu_open_fileSha_ID);
  43. GM_unregisterMenuCommand(menu_copy_fileSha_ID);
  44. GM_unregisterMenuCommand(menu_copy_fileSha_ID);
  45. GM_unregisterMenuCommand(menu_refreshCorrection_ID);
  46. menu_open_fileSha = GM_getValue('xiu2_menu_open_fileSha');
  47. menu_copy_fileSha = GM_getValue('xiu2_menu_copy_fileSha');
  48. menu_refreshCorrection = GM_getValue('xiu2_menu_refreshCorrection');
  49. }
  50.  
  51. if (menu_open_fileSha){menu_open_fileSha_ = "√";}else{menu_open_fileSha_ = "×";}
  52. if (menu_copy_fileSha){menu_copy_fileSha_ = "√";}else{menu_copy_fileSha_ = "×";}
  53. if (menu_refreshCorrection){menu_refreshCorrection_ = "√";}else{menu_refreshCorrection_ = "×";}
  54.  
  55. menu_open_fileSha_ID = GM_registerMenuCommand(`[ ${menu_open_fileSha_} ] 自动打开分享链接`, function(){menu_switch(menu_open_fileSha,'xiu2_menu_open_fileSha','自动打开分享链接', true)});
  56. menu_copy_fileSha_ID = GM_registerMenuCommand(`[ ${menu_copy_fileSha_} ] 自动复制分享链接`, function(){menu_switch(menu_copy_fileSha,'xiu2_menu_copy_fileSha','自动复制分享链接', true)});
  57. menu_refreshCorrection_ID = GM_registerMenuCommand(`[ ${menu_refreshCorrection_} ] 刷新不返回根目录`, function(){if(menu_refreshCorrection){UNrefreshCorrection();}else{refreshCorrection();};menu_switch(menu_refreshCorrection,'xiu2_menu_refreshCorrection','刷新不返回根目录', false)});
  58. menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
  59. }
  60.  
  61.  
  62. // 菜单开关
  63. function menu_switch(menu_status, Name, Tips, RefreshTips) {
  64. if(RefreshTips){
  65. RefreshTips = "\n(刷新网页后生效)"
  66. }else{
  67. RefreshTips = ""
  68. }
  69. if (menu_status){
  70. GM_setValue(`${Name}`, false);
  71. GM_notification(`已关闭 [${Tips}] 功能${RefreshTips}`);
  72. }else{
  73. GM_setValue(`${Name}`, true);
  74. GM_notification(`已开启 [${Tips}] 功能${RefreshTips}`);
  75. }
  76. registerMenuCommand(); // 重新注册脚本菜单
  77. };
  78.  
  79.  
  80. if(document.getElementById("infos")){ // 分享链接文件列表页
  81. setTimeout(fileMoreS, 300); // 自动显示更多文件
  82. }else if(document.querySelector("iframe.ifr2")){ // 分享链接文件下载页(暂时没有这方面的功能,先空着)
  83. //console.log()
  84. }else if(document.getElementById("mainframe") || window.top.location.href.indexOf("mydisk.php?") > -1){ // 后台页
  85. if(window.top.location.href != "https://pc.woozooo.com/mydisk.php"){
  86. window.top.location.href = "https://pc.woozooo.com/mydisk.php"
  87. }
  88. var mainframe;
  89. iframe();
  90. }
  91.  
  92.  
  93. // 获取 iframe 框架
  94. function iframe() {
  95. mainframe = document.getElementById("mainframe");
  96. if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
  97. mainframe = mainframe.contentWindow;
  98. if(menu_refreshCorrection){
  99. refreshCorrection(); // 刷新不返回根目录(F5)
  100. }
  101. EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
  102. }
  103. }
  104.  
  105.  
  106. // 刷新不返回根目录(F5)
  107. function refreshCorrection() {
  108. document.onkeydown = mainframe.onkeydown = function (e) {
  109. e = window.event || e;
  110. let keycode = e.keyCode;
  111. if (keycode == 116) {
  112. e.keyCode = 0;
  113. let folderID = /-?\d+/.exec(mainframe.document.getElementById("filemore").children[0].getAttribute("onclick"))
  114. if(folderID.length > 0){
  115. mainframe.folder(folderID[0]);
  116. e.returnValue = false;
  117. e.cancelBubble = true;
  118. return false;
  119. }
  120. }
  121. }
  122. }
  123.  
  124.  
  125. // 恢复刷新机制
  126. function UNrefreshCorrection() {
  127. document.onkeydown = mainframe.onkeydown = function (e) {
  128. e = window.event || e;
  129. let keycode = e.keyCode;
  130. if (keycode == 116) {
  131. return true;
  132. }
  133. }
  134. }
  135.  
  136.  
  137. // 自动显示更多文件
  138. function fileMore() {
  139. let filemore = mainframe.document.getElementById("filemore"); // 寻找 [显示更多文件] 按钮
  140. if(filemore && filemore.style.display == "block"){ // 判断按钮是否存在且可见
  141. if(filemore.children[0]){ // 判断按钮元素下第一个元素是否存在
  142. filemore.children[0].click(); // 点击 [显示更多文件] 按钮
  143. }
  144. }
  145. }
  146.  
  147.  
  148. // 自动显示更多文件
  149. function fileMoreS() {
  150. let filemore = document.getElementById("filemore"); // 寻找 [显示更多文件] 按钮
  151. if(filemore && filemore.style.display != "none"){ // 判断按钮是否存在且可见
  152. filemore.click(); // 点击 [显示更多文件] 按钮
  153. }
  154. }
  155.  
  156.  
  157. // 分享链接相关(点击文件时)
  158. function fileSha() {
  159. var f_sha = mainframe.document.getElementById("f_sha"); // 寻找分享链接(下载链接)信息框
  160. if(f_sha && f_sha.style.display == "block"){ // 判断信息框是否存在且可见
  161. fileSha_Open(); // 自动打开分享链接(点击文件时)
  162. fileSha_Copy(); // 自动复制分享链接(点击文件时)
  163. if(menu_open_fileSha || menu_copy_fileSha){
  164. f_sha.style.display = "none"; // 隐藏分享链接(下载链接)信息框
  165. }
  166. }
  167. }
  168.  
  169.  
  170. // 自动打开分享链接(点击文件时)
  171. function fileSha_Open() {
  172. if(menu_open_fileSha){ // 脚本菜单开启时才继续
  173. let code = mainframe.document.getElementById("code").getAttribute("title"); // 获取分享链接(下载链接)
  174. if(code != ""){ // 确保分享链接(下载链接)不是空
  175. window.GM_openInTab(code, {active: true,insert: true,setParent: true}) // 打开分享链接(下载链接)
  176. }
  177. }
  178. }
  179.  
  180.  
  181. // 自动复制分享链接(点击文件时)
  182. function fileSha_Copy() {
  183. if(menu_copy_fileSha){ // 脚本菜单开启时才继续
  184. let f_sha1 = mainframe.document.getElementById("f_sha1").innerText; // 获取分享链接(下载链接)
  185. if(f_sha1 != ""){ // 确保分享链接(下载链接)不是空
  186. copyToClipboard(f_sha1); // 复制到剪切板
  187. }
  188. }
  189. }
  190.  
  191.  
  192. // 复制到剪切板
  193. function copyToClipboard(s){
  194. if(window.clipboardData){
  195. window.clipboardData.setData('text',s);
  196. }else{
  197. (function(s){
  198. document.oncopy=function(e){
  199. e.clipboardData.setData('text',s);
  200. e.preventDefault();
  201. document.oncopy=null;
  202. }
  203. })(s);
  204. document.execCommand('Copy');
  205. }
  206. }
  207.  
  208.  
  209. // 定时执行(旧方法,每隔 100ms 执行一次,比较笨且浪费一丢丢性能,但优点是不会漏掉且反应更快)
  210. //setInterval(fileMore,100);
  211.  
  212.  
  213. // 监听 XMLHttpRequest 事件并执行(新方法,只有在产生事件时才会执行 [自动显示更多文件],平时不会执行,更优雅~)
  214. function EventXMLHttpRequest() {
  215. var _send = mainframe.XMLHttpRequest.prototype.send
  216. function sendReplacement(data) {
  217. setTimeout(fileMore, 200); // 自动显示更多文件
  218. setTimeout(fileSha, 200); // 自动打开分享链接(点击文件时)
  219. return _send.apply(this, arguments);
  220. }
  221. mainframe.XMLHttpRequest.prototype.send = sendReplacement;
  222. }
  223.  
  224.  
  225. /*(function (open) {
  226. mainframe.XMLHttpRequest.prototype.open = function () {
  227. this.addEventListener("readystatechange", function () {
  228. if(this.responseURL != "") {
  229. console.log(this.responseURL);
  230. }
  231. }, false);
  232. open.apply(this, arguments);
  233. };
  234. })(mainframe.XMLHttpRequest.prototype.open);*/
  235. })();