Skip to content

Commit 4760271

Browse files
committed
新增 [点击直接下载文件] 功能
1 parent 237d3a3 commit 4760271

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

Lanzou-Enhanced.user.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 蓝奏云网盘增强
3-
// @version 1.3.4
3+
// @version 1.3.5
44
// @author X.I.U
5-
// @description 刷新不回根目录、后退返回上一级、右键文件显示菜单、自动显示更多文件、自定义分享链接域名、自动打开/复制分享链接、带密码的分享链接自动输密码、拖入文件自动显示上传框、输入密码后回车确认、调整描述(话说)编辑框初始大小
5+
// @description 刷新不回根目录、后退返回上一级、右键文件显示菜单、点击直接下载文件、自动显示更多文件、自定义分享链接域名、自动打开/复制分享链接、带密码的分享链接自动输密码、拖入文件自动显示上传框、输入密码后回车确认、调整描述(话说)编辑框初始大小
66
// @match *://*.lanzous.com/*
77
// @match *://*.lanzoux.com/*
88
// @match *://*.lanzoui.com/*
@@ -40,6 +40,7 @@
4040
['menu_copy_fileSha', '自动复制分享链接', '自动复制分享链接', true],
4141
['menu_refreshCorrection', '刷新不返回根目录', '刷新不返回根目录', true],
4242
['menu_rightClickMenu', '右键文件显示菜单', '右键文件显示菜单', true],
43+
['menu_directDownload', '点击直接下载文件', '点击直接下载文件', true],
4344
['menu_folderDescdesMenu', '调整描述(话说)编辑框大小', '调整描述(话说)编辑框大小', true]
4445
], menu_ID = [], lastFolderID;
4546
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
@@ -113,8 +114,10 @@
113114
enterToPass(); // 输入密码后回车确认
114115
}
115116
fileMoreS(); // 自动显示更多文件
117+
directDownload(); // 点击直接下载文件(分享链接列表页)
116118
}
117119
}, 300);
120+
directDownload_(); // 点击直接下载文件(分享链接列表页)
118121
}
119122

120123

@@ -252,6 +255,36 @@
252255
}
253256

254257

258+
// 点击直接下载文件(分享链接列表页)
259+
function directDownload() {
260+
if (!menu_value('menu_directDownload')) return
261+
if (document.getElementById('infos')) {
262+
document.getElementById('infos').addEventListener('click', function(e) {
263+
if (e.target.tagName === 'A') {
264+
e.preventDefault(); // 阻止默认打开链接事件
265+
GM_openInTab(e.target.href + '#download', {active: false, insert: true, setParent: true}); // 后台打开
266+
}
267+
});
268+
}
269+
}
270+
// 点击下载按钮
271+
function directDownload_() {
272+
if (!menu_value('menu_directDownload')) return
273+
if (location.hash != '#download') return
274+
let iframe = document.querySelector('iframe.ifr2');
275+
if (iframe) { // 只有找到 iframe 框架时才会继续运行脚本
276+
iframe = iframe.contentWindow;
277+
let timer = setInterval(function(){
278+
if (iframe.document.querySelector('#go a[href]')) {
279+
GM_openInTab(iframe.document.querySelector('#go a[href]').href, {active: false, insert: true, setParent: false}); // 后台打开
280+
window.top.close(); // 关闭该后台标签页
281+
clearInterval(timer);
282+
}
283+
}, 1);
284+
}
285+
}
286+
287+
255288
// 滚动条事件
256289
function windowScroll(fn1) {
257290
var beforeScrollTop = document.documentElement.scrollTop,
@@ -317,6 +350,8 @@
317350
if (menu_value('menu_open_fileSha')) {f_sha.style.display = 'none';GM_openInTab(f_sha1.textContent, {active: true,insert: true,setParent: true});}
318351
// 复制分享链接(并已复制的提示信息)
319352
if (menu_value('menu_copy_fileSha')) {f_sha.style.display = 'none';GM_setClipboard(f_sha1.textContent, 'text');GM_notification({text: '已复制分享链接~', timeout: 2000});}
353+
// 直接下载文件
354+
if (menu_value('menu_directDownload')) {f_sha.style.display = 'none';GM_openInTab(f_sha1.textContent + '#download', {active: false,insert: true,setParent: true});}
320355
}
321356
}
322357
}
@@ -338,7 +373,7 @@
338373
// 隐藏分享链接窗口(这样自动打开/复制分享链接时,不会一闪而过)
339374
function hideSha(){
340375
if (menu_value('menu_open_fileSha') || menu_value('menu_copy_fileSha')) { // [自动复制分享链接] 或 [自动打开分享链接] 任意一个功能开启时才继续
341-
mainframe.document.head.appendChild(document.createElement('style')).textContent = '#f_sha {display: none !important;}';
376+
mainframe.document.lastElementChild.appendChild(document.createElement('style')).textContent = '#f_sha {display: none !important;}';
342377
}
343378
}
344379

0 commit comments

Comments
 (0)