蓝奏云网盘增强

刷新不返回根目录、右键文件显示菜单、自动显示更多文件、自动打开分享链接、自动复制分享链接、调整描述(话说)编辑框初始大小

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

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