forked from sleepybear1113/taobaoVisitingVenues
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
426 lines (363 loc) · 11.5 KB
/
Copy pathscript.js
File metadata and controls
426 lines (363 loc) · 11.5 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
toastLog("开始");
let deviceWidth = device.width;
let deviceHeight = device.height;
let isCheckIn = false;
function clickItemInCenter(item, time) {
if (time == null) time = 50;
if (item == null) return;
let x = item.bounds().centerX();
let y = item.bounds().centerY();
press(x, y, time);
}
/**
* 点击领喵币的按钮
* @param delay 点击之后延迟多久进行下一个函数
* @returns {number}
*/
function openBeginningBtnItem(delay) {
let items = textStartsWith("gif;base64").depth(19).find();
console.log("寻找--领喵币");
if (items.length > 0) {
let item = items[items.length - 1];
console.log("点击--领喵币");
clickItemInCenter(item);
sleep(delay);
return 1;
}
if (items.length === 0) {
let go = text("领喵币").findOne(1000);
if (go != null) {
console.log("点击--领喵币");
clickItemInCenter(go);
sleep(delay);
return 1;
}
}
return -1;
}
/**
* 判断是否打开领取中心
* @returns {number}
*/
function isOpenBeginning() {
let signIn = textContains("签到").findOnce();
if (signIn != null) {
console.log("成功--打开领取中心");
return 1;
}
return -1;
}
/**
* 确保打开领取中心
* @param waitDelay
* @returns {number}
*/
function ensureOpenBeginning(waitDelay) {
if (isOpenBeginning() === -1) {
openBeginningBtnItem(waitDelay);
}
if (isOpenBeginning() === 1) return 1;
console.error("失败--打开领取中心");
toast("失败--打开领取中心");
return -1;
}
function checkIn(flag) {
console.log("判断店铺签到");
if (flag === true) {
let getMoney = desc("签到领喵币").findOne(500);
if (getMoney != null) {
clickItemInCenter(getMoney);
console.log("点击签到");
sleep(2000);
let happyToGet = desc("开心收下").findOnce();
clickItemInCenter(happyToGet);
console.log("店铺签到获得喵币");
sleep(500);
}
}
}
/**
* 向上滑动
*/
function swipeUp(n) {
console.log("滑动屏幕");
let x = parseInt(deviceWidth / 2);
let duration = 500;
let y = [parseInt(deviceHeight * 0.75), parseInt(deviceHeight * 0.25)];
for (let i = 0; i < n; i++) {
swipe(x, y[0], x, y[1], duration);
}
}
/**
* 逛店有没有满
* @returns {number}
*/
function isFull() {
for (let i = 0; i < 10; i++) {
if (descContains("已达上限").findOnce() || textContains("已达上限").findOnce()) {
console.log("今日已达上限");
return 1;
}
sleep(200);
}
return 0
}
/**
* 执行浏览结束的判断操作
* @returns {number}
*/
function browseFinish() {
for (let i = 0; i < 10; i++) {
let normalFinishDesc = descContains("已获得").findOnce();
let normalFinishText = textContains("已获得").findOnce();
let swipeFinishDesc = descContains("任务完成").findOnce();
let swipeFinishText = textContains("任务完成").findOnce();
if (normalFinishDesc != null || swipeFinishDesc != null || normalFinishText != null || swipeFinishText != null) {
console.log("浏览结束");
return 0;
}
sleep(250);
}
console.log("浏览未知");
return -1;
}
/**
* 判断进入浏览的时候是否需要滑动
* @returns {number}
*/
function judgeWay() {
let timeOut = 1000 * 7;
let delay = 250;
let loops = parseInt(timeOut / delay);
for (let i = 0; i < loops; i++) {
let swipeAppearDesc = descContains("滑动浏览得").findOnce();
let swipeAppearText = textContains("滑动浏览得").findOnce();
if (swipeAppearDesc != null || swipeAppearText != null) {
console.log("已获取到滑动浏览模式");
return 0;
}
let directBrowseDesc = desc("浏览").findOnce();
let directBrowseText = text("浏览").findOnce();
if (directBrowseDesc != null || directBrowseText != null) {
if (descContains("00喵币").findOnce() != null || textContains("00喵币").findOnce() != null) {
console.log("已获取到正常浏览模式");
return 1;
}
}
sleep(delay);
}
console.log("超时");
return -1;
}
/**
* 关闭领取中心再打开
* @returns {number}
*/
function reopenAgain() {
console.log("reopen");
let tbs = id("taskBottomSheet").findOnce();
if (tbs == null) return -1;
let close = tbs.child(1);
if (close != null) {
console.log("关闭");
clickItemInCenter(close);
sleep(1000);
return ensureOpenBeginning(2000);
}
return -1;
}
/**
* 点击-去浏览 按钮
* @returns {number}
*/
function clickGoBrowse(n) {
// 寻找-去浏览-的按钮
let browse = text("去浏览").findOne(1000);
if (browse != null) {
let guessYouLike = textContains("猜你喜欢").findOnce(); //寻找-猜你喜欢-的按钮
//如果出现了-猜你喜欢,那就点击下一个-去浏览-的按钮
if (guessYouLike != null) {
console.log("出现猜你喜欢");
// 这里判断控件的 top 坐标是否一样(其实我也不知道直接判断控件是否一样行不行)
let pp = browse.parent().bounds().top;
let ppp = guessYouLike.parent().parent().bounds().top;
if (ppp === pp) {
console.log("跳过--猜你喜欢");
let allBrowse = text("去浏览").find();
// 如果仅剩下一个-去浏览-的按钮,并且外圈循环重复不到 2 次,那就进行返回 0 进行 reopen()
if (allBrowse.length <= 1 && n <= 1) {
return 0;
}
// 循环找到一个 top 坐标不是和-猜你喜欢-一样的
for (let i = 0; i < allBrowse.length; i++) {
let item = allBrowse[i];
if (item.bounds().top !== browse.bounds().top) {
browse = item;
}
}
}
}
console.log("点击--去浏览");
clickItemInCenter(browse);
return 1;
}
return -1;
}
/**
* 跳过倒计时广告
*/
function clickSkip() {
let skip = descMatches("^[0-6]\\d{0}s$").findOnce();
if (skip != null) {
console.log("滑动跳过");
swipeUp(1);
}else console.log("无广告");
}
/**
* 循环执行浏览操作
*/
function runGoBrowse() {
let isSuccess = 1;
// 进行循环浏览
for (let i = 0; i < 50; i++) {
isSuccess = ensureOpenBeginning(2000); // 打开领取中心
if (isSuccess !== 1) break; //打开失败就 -1
// 每 5 次重新开关领取中心进行刷新
if (i % 5 === 0) {
reopenAgain();
}
// 点击去浏览,如果没找到 去浏览 的按钮,那就关闭领取中心再打开,三次
for (let j = 0; j < 3; j++) {
isSuccess = clickGoBrowse(j);
if (isSuccess !== 1) {
reopenAgain();
} else break;
}
if (isSuccess === -1) break; //如果 3 次之后还是不行,那就 -1
toastLog(i); // 第几次循环
sleep(2000);
clickSkip(); // 判断广告跳过,向上滑动
let jw = judgeWay(); //去浏览之后,判断是不是滑动浏览。这里最多延时 7s
// 进行滑动。如果是滑动的话,就是店铺,判断是否有店铺签到的操作。
if (jw === 0) {
checkIn(isCheckIn);
swipeUp(2);
} else if (jw === -1) { //如果没有滑动浏览,那就可能不需要,或者浏览到上限了
if (isFull() === 1) { // 这里的最多延时 2s
console.log("已达上限");
backToBefore();
reopenAgain();
continue;
}
}
// 这里通过不同的情况区分不同的延时
if (jw === -1) {
console.log("10s");
sleep(1000 * 10);
} else {
console.log("14s");
sleep(1000 * 14);
}
let isF = browseFinish(); //右下角是否出现浏览完成类似的字样。最多延时 2.5s
if (isF === 0) {
console.log("浏览结束,返回");
} else if (isF === -1) {
console.log("浏览未正常结束,返回");
}
backToBefore();
}
}
/**
* 可能存在需要两次返回的情况
*/
function backToBefore() {
back();
sleep(2000);
let isGoingTo = text("正在前往会场").findOnce();
if (isGoingTo != null) {
back();
sleep(2000);
} else {
isGoingTo = desc("正在前往会场").findOnce();
if (isGoingTo != null) {
back();
sleep(2000);
}
}
}
function removeFile(fileName) {
if (files.exists(fileName)) {
files.remove(fileName);
}
}
function clearNewScript() {
threads.start(function () {
removeFile("/sdcard/脚本/淘宝喵币/script.js");
removeFile("/sdcard/脚本/淘宝喵币/version.txt");
toastLog("清除完成");
});
}
function runRun() {
sleep(500);
let statue = runGoBrowse();
toastLog("去浏览--浏览结束");
alert("结束");
}
function moveFloating(n) {
let i = -1;
dialogs.confirm("由于需要,请将悬浮窗移动至靠左。", "点击确认表示已完成,直接运行脚本。\n点击取消则手动前去调整。\n", function (clear) {
if (clear) {
console.log("直接运行");
i = 1;
} else {
toastLog("请将悬浮窗移动至靠左");
i = 0;
}
});
while (i === -1) {
slepp(100);
}
if (i === 1) {
runRun(n);
}
}
function oldVersionWarning(v) {
let items = ["依旧尝试继续", "清除本地下载的新脚本,使用默认脚本", "新APP"];
let choice = -10;
dialogs.select("当前新版本可能不适用于此旧APP,请更新到新APP。", items, function (index) {
choice = index;
});
while (choice === -10) {
sleep(100);
}
if (choice === -1) {
toastLog("未选择!");
} else if (choice === 0) {
if (v <= 6) {
console.log(v);
moveFloating();
}
runRun();
} else if (choice === 1) {
clearNewScript();
} else if (choice === 3) {
alert("暂没有开放下载新 APP 的功能,请自行下载");
}
}
function versionChoice(v) {
let vv = parseInt(v);
let minSuitVersion = 10;
console.log("适合运行的最低版本" + minSuitVersion);
if (vv < minSuitVersion) {
oldVersionWarning(vv);
} else {
runRun();
}
}
function runChoose(n) {
if (n === 1) isCheckIn = true;
let currentVersion = app.versionCode;
console.log("当前版本:" + currentVersion);
versionChoice(currentVersion);
}
module.exports = runChoose;