11// ==UserScript==
22// @name 蓝奏云网盘增强
3- // @version 1.3.1
3+ // @version 1.3.2
44// @author X.I.U
55// @description 刷新不回根目录、后退返回上一级、右键文件显示菜单、自动显示更多文件、自动打开分享链接、自动复制分享链接、带密码的分享链接自动输密码、拖入文件自动显示上传框、输入密码后回车确认、调整描述(话说)编辑框初始大小
66// @match *://*.lanzous.com/*
2222// @grant GM_getValue
2323// @grant GM_setValue
2424// @grant GM_notification
25+ // @grant GM_setClipboard
2526// @grant unsafeWindow
2627// @noframes
2728// @license GPL-3.0 License
3132// @homepageURL https://github.com/XIU2/UserScript
3233// ==/UserScript==
3334
34- 'use strict' ;
3535( function ( ) {
36+ 'use strict' ;
3637 var menu_ALL = [
3738 [ 'menu_open_fileSha' , '自动打开分享链接' , '自动打开分享链接' , true ] ,
3839 [ 'menu_copy_fileSha' , '自动复制分享链接' , '自动复制分享链接' , true ] ,
117118 // 获取 iframe 框架
118119 function iframe ( ) {
119120 mainframe = document . getElementById ( 'mainframe' ) ;
120- if ( mainframe ) { // 只有找到 iframe 框架时才会继续运行脚本
121+ if ( mainframe ) { // 只有找到 iframe 框架时才会继续运行脚本
121122 mainframe = mainframe . contentWindow ;
122123 if ( menu_value ( 'menu_refreshCorrection' ) ) {
123124 refreshCorrection ( ) ; // 刷新不返回根目录(F5)
202203 let list_ = mainframe . document . getElementById ( list_id_name ) ;
203204 if ( list_ ) { // 文件/文件夹列表
204205 list_ . oncontextmenu = function ( e ) {
205- e . preventDefault ( ) ; // 屏蔽浏览器自身右键菜单
206- let left = e . pageX - 30 ; // 右键菜单弹出位置
206+ e . preventDefault ( ) ; // 屏蔽浏览器自身右键菜单
207+ let left = e . pageX - 30 ; // 右键菜单弹出位置
207208 let list_ID = e . target . id ;
208209 if ( e . target . nodeName === 'FONT' ) {
209210 list_ID = e . target . parentNode . parentNode . id
224225 // 自动显示更多文件(后台页)
225226 function fileMore ( ) {
226227 let filemore = mainframe . document . getElementById ( 'filemore' ) ; // 寻找 [显示更多文件] 按钮
227- if ( filemore && filemore . style . display === 'block' ) { // 判断按钮是否存在且可见
228- if ( filemore . children [ 0 ] ) { // 判断按钮元素下第一个元素是否存在
228+ if ( filemore && filemore . style . display === 'block' ) { // 判断按钮是否存在且可见
229+ if ( filemore . children [ 0 ] ) { // 判断按钮元素下第一个元素是否存在
229230 filemore . children [ 0 ] . click ( ) ; // 点击 [显示更多文件] 按钮
230231 }
231232 }
241242 if ( document . documentElement . scrollHeight <= document . documentElement . clientHeight + scrollTop + scrollDelta ) {
242243 let filemore = document . getElementById ( 'filemore' ) ; // 寻找 [显示更多文件] 按钮
243244 if ( filemore && filemore . style . display != 'none' ) { // 如果正在加载,就不再点击
244- if ( filemore . textContent . indexOf ( '更多' ) > - 1 ) { // 避免已经在加载了,重复点击
245+ if ( filemore . textContent . indexOf ( '更多' ) > - 1 ) { // 避免已经在加载了,重复点击
245246 filemore . click ( ) ; // 点击 [显示更多文件] 按钮
246247 }
247248 }
319320 }
320321
321322
322- // 自动打开分享链接(点击文件时)
323+ // 自动打开分享链接(点击文件时/右键菜单 - [打开分享连接] )
323324 function fileSha_Open ( ) {
324- if ( menu_value ( 'menu_open_fileSha' ) ) { // 脚本菜单开启时才继续
325- let code = mainframe . document . getElementById ( 'code' ) . title ; // 获取分享链接(下载链接)
326- if ( code != '' ) { // 确保分享链接(下载链接)不是空
327- window . GM_openInTab ( code , { active : true , insert : true , setParent : true } ) // 打开分享链接(下载链接)
325+ if ( menu_value ( 'menu_open_fileSha' ) ) { // 脚本菜单开启时才继续
326+ let code = mainframe . document . getElementById ( 'code' ) ; // 获取分享链接(下载链接)
327+ if ( code && code . title != '' ) { // 确保分享链接(下载链接)不是空
328+ window . GM_openInTab ( code . title , { active : true , insert : true , setParent : true } ) // 打开分享链接(下载链接)
328329 }
329330 }
330331 }
331332
332333
333- // 自动复制分享链接(点击文件时)
334+ // 自动复制分享链接(点击文件时/右键菜单 - [复制分享连接] )
334335 function fileSha_Copy ( ) {
335- if ( menu_value ( 'menu_copy_fileSha' ) ) { // 脚本菜单开启时才继续
336- let f_sha1 = mainframe . document . getElementById ( 'f_sha1' ) . textContent ; // 获取分享链接(下载链接)
337- if ( f_sha1 != '' ) { // 确保分享链接(下载链接)不是空
338- copyToClipboard ( f_sha1 ) ; // 复制到剪切板
336+ if ( menu_value ( 'menu_copy_fileSha' ) ) { // 脚本菜单开启时才继续
337+ let f_sha1 = mainframe . document . getElementById ( 'f_sha1' ) ; // 获取分享链接(下载链接)
338+ if ( f_sha1 && f_sha1 . textContent != '' ) { // 确保分享链接(下载链接)不是空
339+ GM_setClipboard ( f_sha1 . textContent , 'text' ) ; // 复制到剪切板
340+ GM_notification ( { text : '已复制分享链接~' , timeout : 2000 } ) ; // 已复制提示
339341 }
340342 }
341343 }
342344
343345
344- // 复制到剪切板
345- function copyToClipboard ( s ) {
346- if ( window . clipboardData ) {
347- window . clipboardData . setData ( 'text' , s ) ;
348- } else {
349- ( function ( s ) {
350- document . oncopy = function ( e ) {
351- e . clipboardData . setData ( 'text' , s ) ;
352- e . preventDefault ( ) ;
353- document . oncopy = null ;
354- }
355- } ) ( s ) ;
356- document . execCommand ( 'Copy' ) ;
357- }
358- }
359-
360-
361346 // 隐藏分享链接窗口(这样自动打开/复制分享链接时,不会一闪而过)
362347 function hideSha ( ) {
363348 if ( menu_value ( 'menu_open_fileSha' ) || menu_value ( 'menu_copy_fileSha' ) ) { // [自动复制分享链接] 或 [自动打开分享链接] 任意一个功能开启时才继续
392377 // 获取上个文件夹 ID(用于浏览器后退事件)
393378 function getLastFolderID ( ) {
394379 lastFolderID = null
395- let f_tpspan = mainframe . document . querySelectorAll ( " span.f_tpspan" ) ;
380+ let f_tpspan = mainframe . document . querySelectorAll ( ' span.f_tpspan' ) ;
396381 if ( f_tpspan . length > 1 ) {
397- lastFolderID = / - ? \d + / . exec ( f_tpspan [ f_tpspan . length - 2 ] . getAttribute ( " onclick" ) ) [ 0 ] ;
382+ lastFolderID = / - ? \d + / . exec ( f_tpspan [ f_tpspan . length - 2 ] . getAttribute ( ' onclick' ) ) [ 0 ] ;
398383 }
399384 }
400385
409394 }
410395
411396
412- // 监听 XMLHttpRequest 事件并执行(新方法,只有在产生事件时才会执行 [自动显示更多文件],平时不会执行,更优雅~)
397+ // 监听 XMLHttpRequest 事件并执行
413398 function EventXMLHttpRequest ( ) {
414399 var _send = mainframe . XMLHttpRequest . prototype . send
415400 function sendReplacement ( data ) {
447432 const observer = new MutationObserver ( callback ) ;
448433 observer . observe ( mainframe . document , { childList : true , subtree : true } ) ;
449434 }
450-
451-
452- /*(function (open) {
453- mainframe.XMLHttpRequest.prototype.open = function () {
454- this.addEventListener("readystatechange", function () {
455- if(this.responseURL != "") {
456- console.log(this.responseURL);
457- }
458- }, false);
459- open.apply(this, arguments);
460- };
461- })(mainframe.XMLHttpRequest.prototype.open);*/
462435} ) ( ) ;
0 commit comments