蓝奏云网盘增强

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

目前为 2021-01-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 蓝奏云网盘增强
  3. // @version 1.1.1
  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. menu_copy_fileSha = GM_getValue('xiu2_menu_copy_fileSha'),
  31. menu_refreshCorrection = GM_getValue('xiu2_menu_refreshCorrection'),
  32. menu_rightClickMenu = GM_getValue('xiu2_menu_rightClickMenu');
  33. var menu_open_fileSha_ID, menu_copy_fileSha_ID, menu_refreshCorrection_ID, menu_rightClickMenu_ID, menu_feedBack_ID;
  34. if (menu_open_fileSha == null){menu_open_fileSha = true; GM_setValue('xiu2_menu_open_fileSha', menu_open_fileSha)};
  35. if (menu_copy_fileSha == null){menu_copy_fileSha = true; GM_setValue('xiu2_menu_copy_fileSha', menu_copy_fileSha)};
  36. if (menu_refreshCorrection == null){menu_refreshCorrection = true; GM_setValue('xiu2_menu_refreshCorrection', menu_refreshCorrection)};
  37. if (menu_rightClickMenu == null){menu_rightClickMenu = true; GM_setValue('xiu2_menu_rightClickMenu', menu_rightClickMenu)};
  38. registerMenuCommand();
  39.  
  40. // 注册脚本菜单
  41. function registerMenuCommand() {
  42. var menu_open_fileSha_, menu_copy_fileSha_, menu_refreshCorrection_, menu_rightClickMenu_;
  43. if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
  44. GM_unregisterMenuCommand(menu_open_fileSha_ID);
  45. GM_unregisterMenuCommand(menu_copy_fileSha_ID);
  46. GM_unregisterMenuCommand(menu_refreshCorrection_ID);
  47. GM_unregisterMenuCommand(menu_rightClickMenu_ID);
  48. GM_unregisterMenuCommand(menu_feedBack_ID);
  49. menu_open_fileSha = GM_getValue('xiu2_menu_open_fileSha');
  50. menu_copy_fileSha = GM_getValue('xiu2_menu_copy_fileSha');
  51. menu_refreshCorrection = GM_getValue('xiu2_menu_refreshCorrection');
  52. menu_rightClickMenu = GM_getValue('xiu2_menu_rightClickMenu');
  53. }
  54.  
  55. if (menu_open_fileSha){menu_open_fileSha_ = "√";}else{menu_open_fileSha_ = "×";}
  56. if (menu_copy_fileSha){menu_copy_fileSha_ = "√";}else{menu_copy_fileSha_ = "×";}
  57. if (menu_refreshCorrection){menu_refreshCorrection_ = "√";}else{menu_refreshCorrection_ = "×";}
  58. if (menu_rightClickMenu){menu_rightClickMenu_ = "√";}else{menu_rightClickMenu_ = "×";}
  59.  
  60. menu_open_fileSha_ID = GM_registerMenuCommand(`[ ${menu_open_fileSha_} ] 自动打开分享链接`, function(){menu_switch(menu_open_fileSha,'xiu2_menu_open_fileSha','自动打开分享链接', true)});
  61. menu_copy_fileSha_ID = GM_registerMenuCommand(`[ ${menu_copy_fileSha_} ] 自动复制分享链接`, function(){menu_switch(menu_copy_fileSha,'xiu2_menu_copy_fileSha','自动复制分享链接', true)});
  62. menu_refreshCorrection_ID = GM_registerMenuCommand(`[ ${menu_refreshCorrection_} ] 刷新不返回根目录`, function(){if(menu_refreshCorrection){UNrefreshCorrection();}else{refreshCorrection();};menu_switch(menu_refreshCorrection,'xiu2_menu_refreshCorrection','刷新不返回根目录', false)});
  63. menu_rightClickMenu_ID = GM_registerMenuCommand(`[ ${menu_rightClickMenu_} ] 右键文件显示菜单`, function(){menu_switch(menu_rightClickMenu,'xiu2_menu_rightClickMenu','右键文件显示菜单', true)});
  64. menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
  65. }
  66.  
  67.  
  68. // 菜单开关
  69. function menu_switch(menu_status, Name, Tips, RefreshTips) {
  70. if(RefreshTips){
  71. RefreshTips = "\n(刷新网页后生效)"
  72. }else{
  73. RefreshTips = ""
  74. }
  75. if (menu_status){
  76. GM_setValue(`${Name}`, false);
  77. GM_notification(`已关闭 [${Tips}] 功能${RefreshTips}`);
  78. }else{
  79. GM_setValue(`${Name}`, true);
  80. GM_notification(`已开启 [${Tips}] 功能${RefreshTips}`);
  81. }
  82. registerMenuCommand(); // 重新注册脚本菜单
  83. };
  84.  
  85.  
  86. if(document.getElementById("infos")){ // 分享链接文件列表页
  87. setTimeout(fileMoreS, 300); // 自动显示更多文件
  88. }else if(document.querySelector("iframe.ifr2")){ // 分享链接文件下载页(暂时没有这方面的功能,先空着)
  89. //console.log()
  90. }else if(document.getElementById("mainframe") || window.top.location.href.indexOf("mydisk.php?") > -1){ // 后台页
  91. if(window.top.location.href != "https://pc.woozooo.com/mydisk.php"){
  92. window.top.location.href = "https://pc.woozooo.com/mydisk.php"
  93. }
  94. var mainframe;
  95. iframe();
  96. }
  97.  
  98.  
  99. // 获取 iframe 框架
  100. function iframe() {
  101. mainframe = document.getElementById("mainframe");
  102. if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
  103. mainframe = mainframe.contentWindow;
  104. if(menu_refreshCorrection){
  105. refreshCorrection(); // 刷新不返回根目录(F5)
  106. }
  107. EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
  108. }
  109. }
  110.  
  111.  
  112. // 刷新不返回根目录(F5)
  113. function refreshCorrection() {
  114. document.onkeydown = mainframe.onkeydown = function (e) {
  115. e = window.event || e;
  116. let keycode = e.keyCode;
  117. if (keycode == 116) {
  118. e.keyCode = 0;
  119. let folderID = /-?\d+/.exec(mainframe.document.getElementById("filemore").children[0].getAttribute("onclick"))
  120. if(folderID.length > 0){
  121. mainframe.folder(folderID[0]);
  122. e.returnValue = false;
  123. e.cancelBubble = true;
  124. return false;
  125. }
  126. }
  127. }
  128. }
  129.  
  130.  
  131. // 恢复刷新机制
  132. function UNrefreshCorrection() {
  133. document.onkeydown = mainframe.onkeydown = function (e) {
  134. e = window.event || e;
  135. let keycode = e.keyCode;
  136. if (keycode == 116) {
  137. return true;
  138. }
  139. }
  140. }
  141.  
  142.  
  143. // 右键文件显示菜单
  144. function rightClickMenu() {
  145. if(menu_rightClickMenu){ // 脚本菜单开启时才继续
  146. rightClickMenu_("sub_folder_list", "fols", "folse") // 文件夹
  147. rightClickMenu_("filelist", "fs", "fse") // 文件
  148. }
  149. }
  150.  
  151.  
  152. // 右键文件显示菜单,参数:文件/文件夹列表 ID、菜单 ID 前缀
  153. function rightClickMenu_(list_id_name, menu_id_name_prefix, list_id_name_prefix) {
  154. let list_ = mainframe.document.getElementById(list_id_name);
  155. if(list_){ // 文件/文件夹列表
  156. list_.oncontextmenu = function(e){
  157. e.preventDefault(); // 屏蔽浏览器自身右键菜单
  158. let left = e.pageX - 30; // 右键菜单弹出位置
  159. let list_ID = e.target.id;
  160. if(e.target.nodeName == "FONT"){
  161. list_ID = e.target.parentNode.parentNode.id
  162. }else if(e.target.id == ""){
  163. list_ID = e.target.parentNode.id
  164. }
  165. list_ID = /\d+/.exec(list_ID)
  166. if(list_ID.length > 0){
  167. mainframe.document.getElementById(menu_id_name_prefix + list_ID[0]).style.cssText="position: absolute !important; left: " + left + "px;" // 修改右键菜单弹出位置(X)
  168. mainframe.document.getElementById(list_id_name_prefix + list_ID[0]).focus();
  169. mainframe.document.getElementById(list_id_name_prefix + list_ID[0]).click();
  170. }
  171. }
  172. }
  173. }
  174.  
  175.  
  176. // 自动显示更多文件(后台页)
  177. function fileMore() {
  178. let filemore = mainframe.document.getElementById("filemore"); // 寻找 [显示更多文件] 按钮
  179. if(filemore && filemore.style.display == "block"){ // 判断按钮是否存在且可见
  180. if(filemore.children[0]){ // 判断按钮元素下第一个元素是否存在
  181. filemore.children[0].click(); // 点击 [显示更多文件] 按钮
  182. }
  183. }
  184. }
  185.  
  186.  
  187. // 自动显示更多文件(分享链接列表页)
  188. function fileMoreS() {
  189. let filemore = document.getElementById("filemore"); // 寻找 [显示更多文件] 按钮
  190. if(filemore && filemore.style.display != "none"){ // 判断按钮是否存在且可见
  191. filemore.click(); // 点击 [显示更多文件] 按钮
  192. }
  193. }
  194.  
  195.  
  196. // 分享链接相关(点击文件时)
  197. function fileSha() {
  198. var f_sha = mainframe.document.getElementById("f_sha"); // 寻找分享链接(下载链接)信息框
  199. if(f_sha && f_sha.style.display == "block"){ // 判断信息框是否存在且可见
  200. fileSha_Open(); // 自动打开分享链接(点击文件时)
  201. fileSha_Copy(); // 自动复制分享链接(点击文件时)
  202. if(menu_open_fileSha || menu_copy_fileSha){
  203. f_sha.style.display = "none"; // 隐藏分享链接(下载链接)信息框
  204. }
  205. }
  206. }
  207.  
  208.  
  209. // 自动打开分享链接(点击文件时)
  210. function fileSha_Open() {
  211. if(menu_open_fileSha){ // 脚本菜单开启时才继续
  212. let code = mainframe.document.getElementById("code").getAttribute("title"); // 获取分享链接(下载链接)
  213. if(code != ""){ // 确保分享链接(下载链接)不是空
  214. window.GM_openInTab(code, {active: true,insert: true,setParent: true}) // 打开分享链接(下载链接)
  215. }
  216. }
  217. }
  218.  
  219.  
  220. // 自动复制分享链接(点击文件时)
  221. function fileSha_Copy() {
  222. if(menu_copy_fileSha){ // 脚本菜单开启时才继续
  223. let f_sha1 = mainframe.document.getElementById("f_sha1").innerText; // 获取分享链接(下载链接)
  224. if(f_sha1 != ""){ // 确保分享链接(下载链接)不是空
  225. copyToClipboard(f_sha1); // 复制到剪切板
  226. }
  227. }
  228. }
  229.  
  230.  
  231. // 复制到剪切板
  232. function copyToClipboard(s){
  233. if(window.clipboardData){
  234. window.clipboardData.setData('text',s);
  235. }else{
  236. (function(s){
  237. document.oncopy=function(e){
  238. e.clipboardData.setData('text',s);
  239. e.preventDefault();
  240. document.oncopy=null;
  241. }
  242. })(s);
  243. document.execCommand('Copy');
  244. }
  245. }
  246.  
  247.  
  248. // 定时执行(旧方法,每隔 100ms 执行一次,比较笨且浪费一丢丢性能,但优点是不会漏掉且反应更快)
  249. //setInterval(fileMore,100);
  250.  
  251.  
  252. // 监听 XMLHttpRequest 事件并执行(新方法,只有在产生事件时才会执行 [自动显示更多文件],平时不会执行,更优雅~)
  253. function EventXMLHttpRequest() {
  254. var _send = mainframe.XMLHttpRequest.prototype.send
  255. function sendReplacement(data) {
  256. setTimeout(fileMore, 200); // 自动显示更多文件
  257. setTimeout(fileSha, 200); // 自动打开分享链接(点击文件时)
  258. setTimeout(rightClickMenu, 500); // 右键文件显示菜单
  259. return _send.apply(this, arguments);
  260. }
  261. mainframe.XMLHttpRequest.prototype.send = sendReplacement;
  262. }
  263.  
  264.  
  265. /*(function (open) {
  266. mainframe.XMLHttpRequest.prototype.open = function () {
  267. this.addEventListener("readystatechange", function () {
  268. if(this.responseURL != "") {
  269. console.log(this.responseURL);
  270. }
  271. }, false);
  272. open.apply(this, arguments);
  273. };
  274. })(mainframe.XMLHttpRequest.prototype.open);*/
  275. })();