Skip to content

Commit ef320d8

Browse files
committed
新增 [后退返回上一级] 功能
1 parent c12dbfb commit ef320d8

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

Lanzou-Enhanced.user.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 蓝奏云网盘增强
3-
// @version 1.1.7
3+
// @version 1.2.0
44
// @author X.I.U
5-
// @description 刷新不返回根目录、右键文件显示菜单、自动显示更多文件、自动打开分享链接、自动复制分享链接、调整描述(话说)编辑框初始大小、拖入文件自动显示上传框
5+
// @description 刷新不回根目录、后退返回上一级、右键文件显示菜单、自动显示更多文件、自动打开分享链接、自动复制分享链接、调整描述(话说)编辑框初始大小、拖入文件自动显示上传框
66
// @match *://*.lanzous.com/*
77
// @match *://*.lanzoux.com/*
88
// @match *://*.lanzoui.com/*
@@ -33,7 +33,7 @@
3333
menu_refreshCorrection = GM_getValue('xiu2_menu_refreshCorrection'),
3434
menu_rightClickMenu = GM_getValue('xiu2_menu_rightClickMenu'),
3535
menu_folderDescdesMenu = GM_getValue('xiu2_menu_folderDescdesMenu');
36-
var menu_open_fileSha_ID, menu_copy_fileSha_ID, menu_refreshCorrection_ID, menu_rightClickMenu_ID, menu_folderDescdesMenu_ID, menu_feedBack_ID;
36+
var menu_open_fileSha_ID, menu_copy_fileSha_ID, menu_refreshCorrection_ID, menu_rightClickMenu_ID, menu_folderDescdesMenu_ID, menu_feedBack_ID, lastFolderID;
3737
if (menu_open_fileSha == null){menu_open_fileSha = true; GM_setValue('xiu2_menu_open_fileSha', menu_open_fileSha)};
3838
if (menu_copy_fileSha == null){menu_copy_fileSha = true; GM_setValue('xiu2_menu_copy_fileSha', menu_copy_fileSha)};
3939
if (menu_refreshCorrection == null){menu_refreshCorrection = true; GM_setValue('xiu2_menu_refreshCorrection', menu_refreshCorrection)};
@@ -107,15 +107,16 @@
107107
// 获取 iframe 框架
108108
function iframe() {
109109
mainframe = document.getElementById("mainframe");
110-
if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
110+
if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
111111
mainframe = mainframe.contentWindow;
112112
if(menu_refreshCorrection){
113-
refreshCorrection(); // 刷新不返回根目录(F5)
113+
refreshCorrection(); // 刷新不返回根目录(F5)
114114
}
115115
setTimeout(folderDescdes, 200); // 调整话说编辑框初始大小
116-
EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
116+
fobiddenBack(); // 禁止浏览器返回(并绑定新的返回事件)
117+
EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
117118

118-
dragEnter(); // 拖入文件自动显示上传框
119+
dragEnter(); // 拖入文件自动显示上传框
119120
}
120121
}
121122

@@ -289,6 +290,39 @@
289290
}
290291

291292

293+
// 禁止浏览器返回(并绑定新的返回事件)
294+
function fobiddenBack() {
295+
history.pushState(null, null, document.URL);
296+
window.addEventListener('popstate',backEvent)
297+
}
298+
299+
300+
// 允许浏览器返回
301+
function enableBack() {
302+
history.go(-1);
303+
window.removeEventListener('popstate',backEvent)
304+
}
305+
306+
307+
// 浏览器后退事件函数
308+
function backEvent() {
309+
if(lastFolderID) {
310+
mainframe.folder(lastFolderID);
311+
}
312+
history.pushState(null, null, document.URL);
313+
}
314+
315+
316+
// 获取上个文件夹 ID(用于浏览器后退事件)
317+
function getLastFolderID() {
318+
lastFolderID = null
319+
let f_tpspan = mainframe.document.querySelectorAll("span.f_tpspan");
320+
if(f_tpspan.length > 1) {
321+
lastFolderID = /-?\d+/.exec(f_tpspan[f_tpspan.length - 2].getAttribute("onclick"))[0];
322+
}
323+
}
324+
325+
292326
// 定时执行(旧方法,每隔 100ms 执行一次,比较笨且浪费一丢丢性能,但优点是不会漏掉且反应更快)
293327
//setInterval(fileMore,100);
294328

@@ -300,6 +334,7 @@
300334
setTimeout(fileMore, 200); // 自动显示更多文件
301335
setTimeout(fileSha, 200); // 自动打开分享链接(点击文件时)
302336
setTimeout(rightClickMenu, 500); // 右键文件显示菜单
337+
setTimeout(getLastFolderID, 200); // 获取上个文件夹 ID(用于浏览器后退事件)
303338
return _send.apply(this, arguments);
304339
}
305340
mainframe.XMLHttpRequest.prototype.send = sendReplacement;

0 commit comments

Comments
 (0)