Skip to content

Commit 74d0d97

Browse files
committed
优化 代码(执行方式)
1 parent e5d6efa commit 74d0d97

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

Lanzou-Enhanced.user.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 蓝奏云网盘增强
3-
// @version 1.0.0
3+
// @version 1.0.1
44
// @author X.I.U
55
// @description 自动显示更多文件(文件夹末尾按钮)
66
// @match https://www.lanzou.com/account.php
@@ -25,16 +25,44 @@
2525
// 注册脚本菜单
2626
GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
2727

28+
29+
// 获取 iframe 框架
30+
var mainframe,
31+
patt_mydisk=/mydisk\.php\?/;
32+
if(patt_mydisk.test(window.top.location.href)){
33+
mainframe = window; // 如果当前位于最后一个套娃 iframe 本身,则不再需要寻找 iframe 框架,暂时没什么用,但是以后如果要增加其他功能可能用得上
34+
EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
35+
}else{
36+
mainframe = document.getElementById("mainframe");
37+
if(mainframe){ // 只有找到 iframe 框架时才会继续运行脚本
38+
mainframe = mainframe.contentWindow;
39+
EventXMLHttpRequest(); // 监听 XMLHttpRequest 事件并执行 [自动显示更多文件]
40+
}
41+
}
42+
43+
2844
// 自动显示更多文件
2945
function fileMore() {
30-
var mainframe = document.getElementById("mainframe").contentWindow;
3146
var filemore = mainframe.document.getElementById("filemore");
3247
if(filemore && filemore.style.display != "none"){
3348
if(filemore.children[0]){
3449
filemore.children[0].click();
3550
}
3651
}
3752
}
38-
// 定时执行(为了确保不漏掉,只能用这个笨方法了。。。)
39-
setInterval(fileMore,100)
53+
54+
55+
// 定时执行(旧方法,每隔 100ms 执行一次,比较笨且浪费一丢丢性能,但优点是不会漏掉且反应更快)
56+
//setInterval(fileMore,100);
57+
58+
59+
// 监听 XMLHttpRequest 事件并执行(新方法,只有在产生事件时才会执行 [自动显示更多文件],平时不会执行,更优雅~)
60+
function EventXMLHttpRequest() {
61+
var _send = mainframe.XMLHttpRequest.prototype.send
62+
function sendReplacement(data) {
63+
setTimeout(fileMore, 200); // 延迟执行,避免网页还没加载完
64+
return _send.apply(this, arguments);
65+
}
66+
mainframe.XMLHttpRequest.prototype.send = sendReplacement;
67+
}
4068
})();

0 commit comments

Comments
 (0)