-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoTool_DownloadASMR.user.js
161 lines (128 loc) · 5.18 KB
/
AutoTool_DownloadASMR.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// ==UserScript==
// @name AutoTool
// @namespace https://github.com/XiaoLinXiaoZhu/AutoTool
// @version 0.1
// @description XLXZ'a AutoTool
// @author XLXZ
// @match https://www.asmrgay.com/*
// @match https://cczhhz.asmr.icu/*
// @grant none
// @require
// @license MIT
// ==/UserScript==
var shutdown;
var emptyTimes;
//主程序
window.onload=function(){
shutdown =0;
emptyTimes = 0;
};
function getEndingNumber(str) {
// 正则表达式匹配结尾的1到3位数字
var match = str.match(/\d{1,3}$/);
// 如果找到匹配项,则返回数字部分
return match ? parseInt(match[0], 10) : null;
}
function tryNextUrl(){
var currentUrl = window.location.href;
console.log("=====Now Url is : " + currentUrl);
var newUrl = currentUrl.slice(0, -4);
var match = getEndingNumber(newUrl)
console.log("=====Now Match Url is : " + newUrl);
console.log("=====Now Match is : " + match);
if (match) {
// 提取出数字部分,并转换为整数
var numberPart = parseInt(match, 10);
if(numberPart>9){
newUrl = newUrl.slice(0, -2);
}
else newUrl = newUrl.slice(0, -1);
numberPart ++;
newUrl = newUrl + numberPart + '.rar';
console.log("=====Next Url is :" + newUrl);
window.location.href = newUrl;
}
}
function tryPartUrl(){
var currentUrl = window.location.href;
var newUrl = currentUrl.slice(0, -3);
newUrl += 'part1' + '.exe';
window.open(newUrl, '_top');
}
// 设置延时3秒后执行
setTimeout(function() {
// 获取class包含"hope-button"的所有元素
//alert("match url");
function checkButton() {
var currentUrl = window.location.href; //获取当前url并分析结尾
var lastThreeChars = currentUrl.slice(-3);
console.log("analying url,end with :"+lastThreeChars);
if(lastThreeChars != "zip" && lastThreeChars != "exe" && lastThreeChars != "rar"){
console.log(lastThreeChars + "This is a normal page,stop running");
clearInterval(intervalId); // 停止定时器
}
console.log('getting');
var test = document.querySelector("#root > div.hope-c-PJLV.hope-c-PJLV-iicyfOA-css > div > div > div > div:nth-child(3) > div > a");
if(!test){
test = document.querySelector("#root > div.hope-c-PJLV.hope-c-PJLV-iicyfOA-css > div > div > div > div:nth-child(3) > div > a");
}
if(!test && lastThreeChars == "zip"){
if(emptyTimes > 3){ //如果没有get到且最后为zip,那么可能是加载失误或者文件分part
tryPartUrl();
}
else{
emptyTimes++;
}
}
if (test && lastThreeChars == "zip") {
console.log(test); //如果get到了且最后为zip,那么这个就是文件的末尾
var js = test.href;
window.location.href = js;
console.log(js);
alert("已开始下载")
shutdown = 1;
clearInterval(intervalId); // 防止继续无谓的检查,一旦条件满足就停止定时器
}
if(lastThreeChars == "exe" || lastThreeChars == "rar"){
console.log("===== part mod now!");
if(!test){
console.log("===== didn't get the button,try times:"+emptyTimes);
if(emptyTimes > 3){ //如果没有get到,那么可能是加载失误或者文件到了结尾
shutdown = 1;
}
else{
emptyTimes++;
}
}
else{
js = test.href;
window.open(js, '_blank');
//window.location.href = js;
//console.log(js);
console.log("尝试打开下一页面");
tryNextUrl();
}
}
}
// 设置每2000毫秒(即2秒)执行一次checkBoolValue函数
var intervalId = setInterval(checkButton, 2000);
}, 5000); // 延迟3秒(3000毫秒)
setTimeout(function() {
function checkBoolValue() {
var currentUrl = window.location.href;//获取当前url并分析结尾
var lastThreeChars = currentUrl.slice(-3);
if(lastThreeChars != "zip" && lastThreeChars != "exe" && lastThreeChars != "rar"){
console.log(lastThreeChars + "This is a normal page,stop detect ShutDown");
clearInterval(intervalId); // 停止定时器
}
if (shutdown == 1) {
alert("关闭页面……")
window.open("about:blank", "_top").close();
clearInterval(intervalId); // 防止继续无谓的检查,一旦条件满足就停止定时器
} else {
console.log("shutdown == 0");
}
}
// 设置每2000毫秒(即2秒)执行一次checkBoolValue函数
var intervalId = setInterval(checkBoolValue, 2000);
}, 20000); // 延迟20秒(3000毫秒)